changed regex operator to %=

This commit is contained in:
zadam 2022-05-11 23:19:32 +02:00
parent 45edef2d71
commit 6906c82408
5 changed files with 10 additions and 8 deletions

View File

@ -8,7 +8,7 @@ const protectedSessionService = require('../../protected_session');
const striptags = require('striptags'); const striptags = require('striptags');
const utils = require("../../utils"); const utils = require("../../utils");
const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*', '~']; const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*', '%='];
const cachedRegexes = {}; const cachedRegexes = {};
@ -25,7 +25,7 @@ class NoteContentFulltextExp extends Expression {
super(); super();
if (!ALLOWED_OPERATORS.includes(operator)) { 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; this.operator = operator;
@ -62,13 +62,14 @@ class NoteContentFulltextExp extends Expression {
content = this.preprocessContent(content, type, mime); content = this.preprocessContent(content, type, mime);
if (this.tokens.length === 1 && this.operator !== '*=*') { if (this.tokens.length === 1) {
const [token] = this.tokens; const [token] = this.tokens;
if ((this.operator === '=' && token === content) if ((this.operator === '=' && token === content)
|| (this.operator === '*=' && content.endsWith(token)) || (this.operator === '*=' && content.endsWith(token))
|| (this.operator === '=*' && content.startsWith(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]); resultNoteSet.add(becca.notes[noteId]);
} }

View File

@ -18,7 +18,7 @@ const stringComparators = {
"*=": comparedValue => (val => val && val.endsWith(comparedValue)), "*=": comparedValue => (val => val && val.endsWith(comparedValue)),
"=*": comparedValue => (val => val && val.startsWith(comparedValue)), "=*": comparedValue => (val => val && val.startsWith(comparedValue)),
"*=*": comparedValue => (val => val && val.includes(comparedValue)), "*=*": comparedValue => (val => val && val.includes(comparedValue)),
"~": comparedValue => (val => val && !!getRegex(comparedValue).test(val)), "%=": comparedValue => (val => val && !!getRegex(comparedValue).test(val)),
}; };
const numericComparators = { const numericComparators = {

View File

@ -9,7 +9,7 @@ function lex(str) {
let currentWord = ''; let currentWord = '';
function isSymbolAnOperator(chr) { function isSymbolAnOperator(chr) {
return ['=', '*', '>', '<', '!', "-", "+"].includes(chr); return ['=', '*', '>', '<', '!', "-", "+", '%'].includes(chr);
} }
function isPreviousSymbolAnOperator() { function isPreviousSymbolAnOperator() {

View File

@ -40,7 +40,7 @@ function getFulltext(tokens, searchContext) {
} }
function isOperator(str) { function isOperator(str) {
return str.match(/^[!=<>*~]+$/); return str.match(/^[!=<>*%]+$/);
} }
function getExpression(tokens, searchContext, level = 0) { function getExpression(tokens, searchContext, level = 0) {

View File

@ -13,9 +13,10 @@
<excludeFolder url="file://$MODULE_DIR$/libraries" /> <excludeFolder url="file://$MODULE_DIR$/libraries" />
<excludeFolder url="file://$MODULE_DIR$/docs" /> <excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/bin/better-sqlite3" /> <excludeFolder url="file://$MODULE_DIR$/bin/better-sqlite3" />
<excludeFolder url="file://$MODULE_DIR$/data" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="@types/jquery" level="application" /> <orderEntry type="library" name="@types/jquery" level="application" />
</component> </component>
</module> </module>