mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
prefix match for autocomplete attribute search
This commit is contained in:
parent
75d8627f1c
commit
2e6395ad88
@ -27,6 +27,20 @@ class NoteCache {
|
|||||||
return this.attributeIndex[`${type}-${name}`] || [];
|
return this.attributeIndex[`${type}-${name}`] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return {Attribute[]} */
|
||||||
|
findAttributesWithPrefix(type, name) {
|
||||||
|
const resArr = [];
|
||||||
|
const key = `${type}-${name}`;
|
||||||
|
|
||||||
|
for (const idx in this.attributeIndex) {
|
||||||
|
if (idx.startsWith(key)) {
|
||||||
|
resArr.push(this.attributeIndex[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resArr.flat();
|
||||||
|
}
|
||||||
|
|
||||||
decryptProtectedNotes() {
|
decryptProtectedNotes() {
|
||||||
for (const note of Object.values(this.notes)) {
|
for (const note of Object.values(this.notes)) {
|
||||||
note.decrypt();
|
note.decrypt();
|
||||||
|
@ -4,13 +4,17 @@ const NoteSet = require('../note_set');
|
|||||||
const noteCache = require('../../note_cache/note_cache');
|
const noteCache = require('../../note_cache/note_cache');
|
||||||
|
|
||||||
class AttributeExistsExp {
|
class AttributeExistsExp {
|
||||||
constructor(attributeType, attributeName) {
|
constructor(attributeType, attributeName, prefixMatch) {
|
||||||
this.attributeType = attributeType;
|
this.attributeType = attributeType;
|
||||||
this.attributeName = attributeName;
|
this.attributeName = attributeName;
|
||||||
|
this.prefixMatch = prefixMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(noteSet) {
|
execute(noteSet) {
|
||||||
const attrs = noteCache.findAttributes(this.attributeType, this.attributeName);
|
const attrs = this.prefixMatch
|
||||||
|
? noteCache.findAttributesWithPrefix(this.attributeType, this.attributeName)
|
||||||
|
: noteCache.findAttributes(this.attributeType, this.attributeName);
|
||||||
|
|
||||||
const resultNoteSet = new NoteSet();
|
const resultNoteSet = new NoteSet();
|
||||||
|
|
||||||
for (const attr of attrs) {
|
for (const attr of attrs) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ParsingContext = require('./parsing_context');
|
|
||||||
const AndExp = require('./expressions/and');
|
const AndExp = require('./expressions/and');
|
||||||
const OrExp = require('./expressions/or');
|
const OrExp = require('./expressions/or');
|
||||||
const NotExp = require('./expressions/not');
|
const NotExp = require('./expressions/not');
|
||||||
@ -63,7 +62,8 @@ function getExpression(tokens, parsingContext) {
|
|||||||
const comparator = comparatorBuilder(operator, comparedValue);
|
const comparator = comparatorBuilder(operator, comparedValue);
|
||||||
|
|
||||||
if (!comparator) {
|
if (!comparator) {
|
||||||
throw new Error(`Can't find operator '${operator}'`);
|
parsingContext.addError(`Can't find operator '${operator}'`);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
expressions.push(new FieldComparisonExp(type, token.substr(1), comparator));
|
expressions.push(new FieldComparisonExp(type, token.substr(1), comparator));
|
||||||
@ -71,7 +71,7 @@ function getExpression(tokens, parsingContext) {
|
|||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
expressions.push(new AttributeExistsExp(type, token.substr(1)));
|
expressions.push(new AttributeExistsExp(type, token.substr(1), parsingContext.fuzzyAttributeSearch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (['and', 'or'].includes(token.toLowerCase())) {
|
else if (['and', 'or'].includes(token.toLowerCase())) {
|
||||||
@ -79,14 +79,14 @@ function getExpression(tokens, parsingContext) {
|
|||||||
op = token.toLowerCase();
|
op = token.toLowerCase();
|
||||||
}
|
}
|
||||||
else if (op !== token.toLowerCase()) {
|
else if (op !== token.toLowerCase()) {
|
||||||
throw new Error('Mixed usage of AND/OR - always use parenthesis to group AND/OR expressions.');
|
parsingContext.addError('Mixed usage of AND/OR - always use parenthesis to group AND/OR expressions.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isOperator(token)) {
|
else if (isOperator(token)) {
|
||||||
throw new Error(`Misplaced or incomplete expression "${token}"`);
|
parsingContext.addError(`Misplaced or incomplete expression "${token}"`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error(`Unrecognized expression "${token}"`);
|
parsingContext.addError(`Unrecognized expression "${token}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!op && expressions.length > 1) {
|
if (!op && expressions.length > 1) {
|
||||||
|
@ -5,6 +5,7 @@ const parens = require('./parens');
|
|||||||
const parser = require('./parser');
|
const parser = require('./parser');
|
||||||
const NoteSet = require("./note_set");
|
const NoteSet = require("./note_set");
|
||||||
const SearchResult = require("./search_result");
|
const SearchResult = require("./search_result");
|
||||||
|
const ParsingContext = require("./parsing_context");
|
||||||
const noteCache = require('../note_cache/note_cache');
|
const noteCache = require('../note_cache/note_cache');
|
||||||
const noteCacheService = require('../note_cache/note_cache_service');
|
const noteCacheService = require('../note_cache/note_cache_service');
|
||||||
const hoistedNoteService = require('../hoisted_note');
|
const hoistedNoteService = require('../hoisted_note');
|
||||||
@ -60,10 +61,8 @@ async function searchNotesForAutocomplete(query) {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsingContext = {
|
const parsingContext = new ParsingContext(false);
|
||||||
includeNoteContent: false,
|
parsingContext.fuzzyAttributeSearch = true;
|
||||||
highlightedTokens: []
|
|
||||||
};
|
|
||||||
|
|
||||||
const expression = parseQueryToExpression(query, parsingContext);
|
const expression = parseQueryToExpression(query, parsingContext);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user