mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port services/search/services/lex
This commit is contained in:
parent
deed58c2fc
commit
533a597a5c
@ -1,4 +1,4 @@
|
|||||||
const lex = require('../../src/services/search/services/lex.js');
|
const lex = require('../../src/services/search/services/lex');
|
||||||
|
|
||||||
describe("Lexer fulltext", () => {
|
describe("Lexer fulltext", () => {
|
||||||
it("simple lexing", () => {
|
it("simple lexing", () => {
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
function lex(str) {
|
interface TokenData {
|
||||||
|
token: string;
|
||||||
|
inQuotes: boolean;
|
||||||
|
startIndex: number;
|
||||||
|
endIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lex(str: string) {
|
||||||
str = str.toLowerCase();
|
str = str.toLowerCase();
|
||||||
|
|
||||||
let fulltextQuery = "";
|
let fulltextQuery = "";
|
||||||
const fulltextTokens = [];
|
const fulltextTokens: TokenData[] = [];
|
||||||
const expressionTokens = [];
|
const expressionTokens: TokenData[] = [];
|
||||||
|
|
||||||
/** @type {boolean|string} */
|
let quotes: boolean | string = false; // otherwise contains used quote - ', " or `
|
||||||
let quotes = false; // otherwise contains used quote - ', " or `
|
|
||||||
let fulltextEnded = false;
|
let fulltextEnded = false;
|
||||||
let currentWord = '';
|
let currentWord = '';
|
||||||
|
|
||||||
function isSymbolAnOperator(chr) {
|
function isSymbolAnOperator(chr: string) {
|
||||||
return ['=', '*', '>', '<', '!', "-", "+", '%', ','].includes(chr);
|
return ['=', '*', '>', '<', '!', "-", "+", '%', ','].includes(chr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,12 +29,12 @@ function lex(str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function finishWord(endIndex, createAlsoForEmptyWords = false) {
|
function finishWord(endIndex: number, createAlsoForEmptyWords = false) {
|
||||||
if (currentWord === '' && !createAlsoForEmptyWords) {
|
if (currentWord === '' && !createAlsoForEmptyWords) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rec = {
|
const rec: TokenData = {
|
||||||
token: currentWord,
|
token: currentWord,
|
||||||
inQuotes: !!quotes,
|
inQuotes: !!quotes,
|
||||||
startIndex: endIndex - currentWord.length + 1,
|
startIndex: endIndex - currentWord.length + 1,
|
||||||
@ -146,4 +152,4 @@ function lex(str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = lex;
|
export = lex;
|
@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const normalizeString = require("normalize-strings");
|
const normalizeString = require("normalize-strings");
|
||||||
const lex = require('./lex.js');
|
const lex = require('./lex');
|
||||||
const handleParens = require('./handle_parens');
|
const handleParens = require('./handle_parens');
|
||||||
const parse = require('./parse.js');
|
const parse = require('./parse.js');
|
||||||
const SearchResult = require('../search_result');
|
const SearchResult = require('../search_result');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user