allow operators =, *= and =* on note content

This commit is contained in:
zadam 2022-05-11 22:43:21 +02:00
parent 91d23c540a
commit bf49648896

View File

@ -8,14 +8,17 @@ const protectedSessionService = require('../../protected_session');
const striptags = require('striptags');
const utils = require("../../utils");
const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*'];
class NoteContentFulltextExp extends Expression {
constructor(operator, {tokens, raw, flatText}) {
super();
if (operator !== '*=*') {
throw new Error(`Note content can be searched only with *=* operator`);
if (!ALLOWED_OPERATORS.includes(operator)) {
throw new Error(`Note content can be searched only with operators: ` + ALLOWED_OPERATORS.join(", "));
}
this.operator = operator;
this.tokens = tokens;
this.raw = !!raw;
this.flatText = !!flatText;
@ -49,6 +52,17 @@ class NoteContentFulltextExp extends Expression {
content = this.preprocessContent(content, type, mime);
if (this.tokens.length === 1 && this.operator !== '*=*') {
const [token] = this.tokens;
if ((this.operator === '=' && token === content)
|| (this.operator === '*=' && content.endsWith(token))
|| (this.operator === '=*' && content.startsWith(token))) {
resultNoteSet.add(becca.notes[noteId]);
}
}
else {
const nonMatchingToken = this.tokens.find(token =>
!content.includes(token) &&
(
@ -63,6 +77,7 @@ class NoteContentFulltextExp extends Expression {
resultNoteSet.add(becca.notes[noteId]);
}
}
}
return resultNoteSet;
}