mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	changed regex operator to %=
This commit is contained in:
		
							parent
							
								
									45edef2d71
								
							
						
					
					
						commit
						6906c82408
					
				@ -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]);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
@ -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 = {
 | 
				
			||||||
 | 
				
			|||||||
@ -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() {
 | 
				
			||||||
 | 
				
			|||||||
@ -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) {
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@
 | 
				
			|||||||
      <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" />
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user