From 6906c824085a9ebc874141b0095a4c59a903d4b4 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 11 May 2022 23:19:32 +0200 Subject: [PATCH] changed regex operator to %= --- src/services/search/expressions/note_content_fulltext.js | 9 +++++---- src/services/search/services/build_comparator.js | 2 +- src/services/search/services/lex.js | 2 +- src/services/search/services/parse.js | 2 +- trilium.iml | 3 ++- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index f7758ef31e..548578c2bc 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -8,7 +8,7 @@ const protectedSessionService = require('../../protected_session'); const striptags = require('striptags'); const utils = require("../../utils"); -const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*', '~']; +const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*', '%=']; const cachedRegexes = {}; @@ -25,7 +25,7 @@ class NoteContentFulltextExp extends Expression { super(); if (!ALLOWED_OPERATORS.includes(operator)) { - throw new Error(`Note content can be searched only with operators: ` + ALLOWED_OPERATORS.join(", ")); + throw new Error(`Note content can be searched only with operators: ` + ALLOWED_OPERATORS.join(", ") + `, operator ${operator} given.`); } this.operator = operator; @@ -62,13 +62,14 @@ class NoteContentFulltextExp extends Expression { content = this.preprocessContent(content, type, mime); - if (this.tokens.length === 1 && this.operator !== '*=*') { + if (this.tokens.length === 1) { const [token] = this.tokens; if ((this.operator === '=' && token === content) || (this.operator === '*=' && content.endsWith(token)) || (this.operator === '=*' && content.startsWith(token)) - || (this.operator === '~' && getRegex(token).test(content))) { + || (this.operator === '*=*' && content.includes(token)) + || (this.operator === '%=' && getRegex(token).test(content))) { resultNoteSet.add(becca.notes[noteId]); } diff --git a/src/services/search/services/build_comparator.js b/src/services/search/services/build_comparator.js index 0776b834fc..6d3ba463a4 100644 --- a/src/services/search/services/build_comparator.js +++ b/src/services/search/services/build_comparator.js @@ -18,7 +18,7 @@ const stringComparators = { "*=": comparedValue => (val => val && val.endsWith(comparedValue)), "=*": comparedValue => (val => val && val.startsWith(comparedValue)), "*=*": comparedValue => (val => val && val.includes(comparedValue)), - "~": comparedValue => (val => val && !!getRegex(comparedValue).test(val)), + "%=": comparedValue => (val => val && !!getRegex(comparedValue).test(val)), }; const numericComparators = { diff --git a/src/services/search/services/lex.js b/src/services/search/services/lex.js index 5234900f72..c6bdc2dfdc 100644 --- a/src/services/search/services/lex.js +++ b/src/services/search/services/lex.js @@ -9,7 +9,7 @@ function lex(str) { let currentWord = ''; function isSymbolAnOperator(chr) { - return ['=', '*', '>', '<', '!', "-", "+"].includes(chr); + return ['=', '*', '>', '<', '!', "-", "+", '%'].includes(chr); } function isPreviousSymbolAnOperator() { diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index 32ce9eeec5..8ab99fe31d 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -40,7 +40,7 @@ function getFulltext(tokens, searchContext) { } function isOperator(str) { - return str.match(/^[!=<>*~]+$/); + return str.match(/^[!=<>*%]+$/); } function getExpression(tokens, searchContext, level = 0) { diff --git a/trilium.iml b/trilium.iml index 6905b014ef..cffe441d0b 100644 --- a/trilium.iml +++ b/trilium.iml @@ -13,9 +13,10 @@ + - + \ No newline at end of file