mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
allow operators =, *= and =* on note content
This commit is contained in:
parent
91d23c540a
commit
bf49648896
@ -8,14 +8,17 @@ const protectedSessionService = require('../../protected_session');
|
|||||||
const striptags = require('striptags');
|
const striptags = require('striptags');
|
||||||
const utils = require("../../utils");
|
const utils = require("../../utils");
|
||||||
|
|
||||||
|
const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*'];
|
||||||
|
|
||||||
class NoteContentFulltextExp extends Expression {
|
class NoteContentFulltextExp extends Expression {
|
||||||
constructor(operator, {tokens, raw, flatText}) {
|
constructor(operator, {tokens, raw, flatText}) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
if (operator !== '*=*') {
|
if (!ALLOWED_OPERATORS.includes(operator)) {
|
||||||
throw new Error(`Note content can be searched only with *=* operator`);
|
throw new Error(`Note content can be searched only with operators: ` + ALLOWED_OPERATORS.join(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.operator = operator;
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
this.raw = !!raw;
|
this.raw = !!raw;
|
||||||
this.flatText = !!flatText;
|
this.flatText = !!flatText;
|
||||||
@ -49,18 +52,30 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
|
|
||||||
content = this.preprocessContent(content, type, mime);
|
content = this.preprocessContent(content, type, mime);
|
||||||
|
|
||||||
const nonMatchingToken = this.tokens.find(token =>
|
if (this.tokens.length === 1 && this.operator !== '*=*') {
|
||||||
!content.includes(token) &&
|
const [token] = this.tokens;
|
||||||
(
|
|
||||||
// in case of default fulltext search we should consider both title, attrs and content
|
|
||||||
// so e.g. "hello world" should match when "hello" is in title and "world" in content
|
|
||||||
!this.flatText
|
|
||||||
|| !becca.notes[noteId].getFlatText().includes(token)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!nonMatchingToken) {
|
if ((this.operator === '=' && token === content)
|
||||||
resultNoteSet.add(becca.notes[noteId]);
|
|| (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) &&
|
||||||
|
(
|
||||||
|
// in case of default fulltext search we should consider both title, attrs and content
|
||||||
|
// so e.g. "hello world" should match when "hello" is in title and "world" in content
|
||||||
|
!this.flatText
|
||||||
|
|| !becca.notes[noteId].getFlatText().includes(token)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!nonMatchingToken) {
|
||||||
|
resultNoteSet.add(becca.notes[noteId]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user