mirror of
https://github.com/zadam/trilium.git
synced 2025-01-15 19:51:57 +08:00
fix fulltext content search
This commit is contained in:
parent
c753f228ac
commit
dc2d5a0a79
6 changed files with 30 additions and 11 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -10328,9 +10328,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"sqlite": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/sqlite/-/sqlite-4.0.8.tgz",
|
||||
"integrity": "sha512-MOy63kITfjJnZimrwgQ50+L83J3IBPjuyTZ98YooAmSXdLtfGHDTMgH5csWturZ/mzm4TafLvtjkIbhmQVNgcw=="
|
||||
"version": "4.0.9",
|
||||
"resolved": "https://registry.npmjs.org/sqlite/-/sqlite-4.0.9.tgz",
|
||||
"integrity": "sha512-vB6Xzn5S5XxMfmyO0ErKjuP5jEQ0z+oFXFC4zXC0s12NMULLETUTb6+PST8sZ7/2HR4KLk4Jsj5yeXkCvogYxg=="
|
||||
},
|
||||
"sqlite3": {
|
||||
"version": "4.1.1",
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
"serve-favicon": "2.5.0",
|
||||
"session-file-store": "1.4.0",
|
||||
"simple-node-logger": "18.12.24",
|
||||
"sqlite": "4.0.8",
|
||||
"sqlite": "4.0.9",
|
||||
"sqlite3": "4.1.1",
|
||||
"string-similarity": "4.0.1",
|
||||
"tar-stream": "2.1.2",
|
||||
|
|
|
@ -18,9 +18,9 @@ class AndExp extends Expression {
|
|||
this.subExpressions = subExpressions;
|
||||
}
|
||||
|
||||
execute(inputNoteSet, searchContext) {
|
||||
async execute(inputNoteSet, searchContext) {
|
||||
for (const subExpression of this.subExpressions) {
|
||||
inputNoteSet = subExpression.execute(inputNoteSet, searchContext);
|
||||
inputNoteSet = await subExpression.execute(inputNoteSet, searchContext);
|
||||
}
|
||||
|
||||
return inputNoteSet;
|
||||
|
|
|
@ -3,17 +3,21 @@
|
|||
const Expression = require('./expression');
|
||||
const NoteSet = require('../note_set');
|
||||
const noteCache = require('../../note_cache/note_cache');
|
||||
const utils = require('../../utils');
|
||||
|
||||
class NoteContentFulltextExp extends Expression {
|
||||
constructor(tokens) {
|
||||
constructor(operator, tokens) {
|
||||
super();
|
||||
|
||||
this.likePrefix = ["*=*", "*="].includes(operator) ? "%" : "";
|
||||
this.likeSuffix = ["*=*", "=*"].includes(operator) ? "%" : "";
|
||||
|
||||
this.tokens = tokens;
|
||||
}
|
||||
|
||||
async execute(inputNoteSet) {
|
||||
const resultNoteSet = new NoteSet();
|
||||
const wheres = this.tokens.map(token => "note_contents.content LIKE " + utils.prepareSqlForLike('%', token, '%'));
|
||||
const wheres = this.tokens.map(token => "note_contents.content LIKE " + utils.prepareSqlForLike(this.likePrefix, token, this.likeSuffix));
|
||||
|
||||
const sql = require('../../sql');
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ class OrExp extends Expression {
|
|||
this.subExpressions = subExpressions;
|
||||
}
|
||||
|
||||
execute(inputNoteSet, searchContext) {
|
||||
async execute(inputNoteSet, searchContext) {
|
||||
const resultNoteSet = new NoteSet();
|
||||
|
||||
for (const subExpression of this.subExpressions) {
|
||||
resultNoteSet.mergeIn(subExpression.execute(inputNoteSet, searchContext));
|
||||
resultNoteSet.mergeIn(await subExpression.execute(inputNoteSet, searchContext));
|
||||
}
|
||||
|
||||
return resultNoteSet;
|
||||
|
|
|
@ -25,7 +25,7 @@ function getFulltext(tokens, parsingContext) {
|
|||
else if (parsingContext.includeNoteContent) {
|
||||
return new OrExp([
|
||||
new NoteCacheFulltextExp(tokens),
|
||||
new NoteContentFulltextExp(tokens)
|
||||
new NoteContentFulltextExp('*=*', tokens)
|
||||
]);
|
||||
}
|
||||
else {
|
||||
|
@ -55,6 +55,21 @@ function getExpression(tokens, parsingContext, level = 0) {
|
|||
|
||||
i++;
|
||||
|
||||
if (tokens[i] === 'content') {
|
||||
i += 1;
|
||||
|
||||
const operator = tokens[i];
|
||||
|
||||
if (!isOperator(operator)) {
|
||||
parsingContext.addError(`After content expected operator, but got "${tokens[i]}"`);
|
||||
return;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
return new NoteContentFulltextExp(operator, [tokens[i]]);
|
||||
}
|
||||
|
||||
if (tokens[i] === 'parents') {
|
||||
i += 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue