mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-esm: Fix wonderful token type mismatch
This commit is contained in:
parent
20c729e62b
commit
0c87fab550
@ -1,24 +1,26 @@
|
||||
const handleParens = require('../../src/services/search/services/handle_parens');
|
||||
import handleParens from "../../src/services/search/services/handle_parens";
|
||||
import { TokenStructure } from "../../src/services/search/services/types";
|
||||
|
||||
describe("Parens handler", () => {
|
||||
it("handles parens", () => {
|
||||
const input = ["(", "hello", ")", "and", "(", "(", "pick", "one", ")", "and", "another", ")"]
|
||||
.map(token => ({token}));
|
||||
|
||||
expect(handleParens(input))
|
||||
.toEqual([
|
||||
const actual: TokenStructure = [
|
||||
[
|
||||
{token: "hello"}
|
||||
],
|
||||
{token: "and"},
|
||||
[
|
||||
[
|
||||
{token: "hello"}
|
||||
{token: "pick"},
|
||||
{token: "one"}
|
||||
],
|
||||
{token: "and"},
|
||||
[
|
||||
[
|
||||
{token: "pick"},
|
||||
{token: "one"}
|
||||
],
|
||||
{token: "and"},
|
||||
{token: "another"}
|
||||
]
|
||||
]);
|
||||
{token: "another"}
|
||||
]
|
||||
];
|
||||
|
||||
expect(handleParens(input)).toEqual(actual);
|
||||
});
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { TokenData } from "./types";
|
||||
import { TokenData, TokenStructure } from "./types";
|
||||
|
||||
/**
|
||||
* This will create a recursive object from a list of tokens - tokens between parenthesis are grouped in a single array
|
||||
*/
|
||||
function handleParens(tokens: (TokenData | TokenData[])[]) {
|
||||
function handleParens(tokens: TokenStructure) {
|
||||
if (tokens.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import utils from "../../utils.js";
|
||||
import TrueExp from "../expressions/true.js";
|
||||
import IsHiddenExp from "../expressions/is_hidden.js";
|
||||
import SearchContext from "../search_context.js";
|
||||
import { TokenData } from "./types";
|
||||
import { TokenData, TokenStructure } from "./types";
|
||||
import Expression from "../expressions/expression.js";
|
||||
|
||||
function getFulltext(_tokens: TokenData[], searchContext: SearchContext) {
|
||||
@ -448,7 +448,7 @@ function getExpression(tokens: TokenData[], searchContext: SearchContext, level
|
||||
|
||||
function parse({fulltextTokens, expressionTokens, searchContext}: {
|
||||
fulltextTokens: TokenData[],
|
||||
expressionTokens: (TokenData | TokenData[])[],
|
||||
expressionTokens: TokenStructure,
|
||||
searchContext: SearchContext,
|
||||
originalQuery: string
|
||||
}) {
|
||||
|
@ -13,7 +13,7 @@ import log from "../../log.js";
|
||||
import hoistedNoteService from "../../hoisted_note.js";
|
||||
import BNote from "../../../becca/entities/bnote.js";
|
||||
import BAttribute from "../../../becca/entities/battribute.js";
|
||||
import { SearchParams, TokenData } from "./types";
|
||||
import { SearchParams, TokenStructure } from "./types";
|
||||
import Expression from "../expressions/expression.js";
|
||||
import sql from "../../sql.js";
|
||||
|
||||
@ -273,7 +273,7 @@ function parseQueryToExpression(query: string, searchContext: SearchContext) {
|
||||
const {fulltextQuery, fulltextTokens, expressionTokens} = lex(query);
|
||||
searchContext.fulltextQuery = fulltextQuery;
|
||||
|
||||
let structuredExpressionTokens: (TokenData | TokenData[])[];
|
||||
let structuredExpressionTokens: TokenStructure;
|
||||
|
||||
try {
|
||||
structuredExpressionTokens = handleParens(expressionTokens);
|
||||
|
@ -1,3 +1,5 @@
|
||||
export type TokenStructure = (TokenData | TokenStructure)[];
|
||||
|
||||
export interface TokenData {
|
||||
token: string;
|
||||
inQuotes?: boolean;
|
||||
|
Loading…
x
Reference in New Issue
Block a user