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", () => {
|
||||
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();
|
||||
|
||||
let fulltextQuery = "";
|
||||
const fulltextTokens = [];
|
||||
const expressionTokens = [];
|
||||
const fulltextTokens: TokenData[] = [];
|
||||
const expressionTokens: TokenData[] = [];
|
||||
|
||||
/** @type {boolean|string} */
|
||||
let quotes = false; // otherwise contains used quote - ', " or `
|
||||
let quotes: boolean | string = false; // otherwise contains used quote - ', " or `
|
||||
let fulltextEnded = false;
|
||||
let currentWord = '';
|
||||
|
||||
function isSymbolAnOperator(chr) {
|
||||
function isSymbolAnOperator(chr: string) {
|
||||
return ['=', '*', '>', '<', '!', "-", "+", '%', ','].includes(chr);
|
||||
}
|
||||
|
||||
@ -23,12 +29,12 @@ function lex(str) {
|
||||
}
|
||||
}
|
||||
|
||||
function finishWord(endIndex, createAlsoForEmptyWords = false) {
|
||||
function finishWord(endIndex: number, createAlsoForEmptyWords = false) {
|
||||
if (currentWord === '' && !createAlsoForEmptyWords) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rec = {
|
||||
const rec: TokenData = {
|
||||
token: currentWord,
|
||||
inQuotes: !!quotes,
|
||||
startIndex: endIndex - currentWord.length + 1,
|
||||
@ -146,4 +152,4 @@ function lex(str) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = lex;
|
||||
export = lex;
|
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const normalizeString = require("normalize-strings");
|
||||
const lex = require('./lex.js');
|
||||
const lex = require('./lex');
|
||||
const handleParens = require('./handle_parens');
|
||||
const parse = require('./parse.js');
|
||||
const SearchResult = require('../search_result');
|
||||
|
Loading…
x
Reference in New Issue
Block a user