mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 04:45:47 +01:00
fix fulltext content search
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user