mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
new ~ operator in search for regex
This commit is contained in:
parent
bf49648896
commit
45edef2d71
@ -8,7 +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 = ['*=*', '=', '*=', '=*'];
|
const ALLOWED_OPERATORS = ['*=*', '=', '*=', '=*', '~'];
|
||||||
|
|
||||||
|
const cachedRegexes = {};
|
||||||
|
|
||||||
|
function getRegex(str) {
|
||||||
|
if (!(str in cachedRegexes)) {
|
||||||
|
cachedRegexes[str] = new RegExp(str, 'ms'); // multiline, dot-all
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachedRegexes[str];
|
||||||
|
}
|
||||||
|
|
||||||
class NoteContentFulltextExp extends Expression {
|
class NoteContentFulltextExp extends Expression {
|
||||||
constructor(operator, {tokens, raw, flatText}) {
|
constructor(operator, {tokens, raw, flatText}) {
|
||||||
@ -57,7 +67,8 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
|
|
||||||
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))) {
|
||||||
|
|
||||||
resultNoteSet.add(becca.notes[noteId]);
|
resultNoteSet.add(becca.notes[noteId]);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
const cachedRegexes = {};
|
||||||
|
|
||||||
|
function getRegex(str) {
|
||||||
|
if (!(str in cachedRegexes)) {
|
||||||
|
cachedRegexes[str] = new RegExp(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachedRegexes[str];
|
||||||
|
}
|
||||||
|
|
||||||
const stringComparators = {
|
const stringComparators = {
|
||||||
"=": comparedValue => (val => val === comparedValue),
|
"=": comparedValue => (val => val === comparedValue),
|
||||||
"!=": comparedValue => (val => val !== comparedValue),
|
"!=": comparedValue => (val => val !== comparedValue),
|
||||||
@ -8,6 +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)),
|
||||||
};
|
};
|
||||||
|
|
||||||
const numericComparators = {
|
const numericComparators = {
|
||||||
|
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user