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,12 +1,12 @@
|
|||||||
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", () => {
|
describe("Parens handler", () => {
|
||||||
it("handles parens", () => {
|
it("handles parens", () => {
|
||||||
const input = ["(", "hello", ")", "and", "(", "(", "pick", "one", ")", "and", "another", ")"]
|
const input = ["(", "hello", ")", "and", "(", "(", "pick", "one", ")", "and", "another", ")"]
|
||||||
.map(token => ({token}));
|
.map(token => ({token}));
|
||||||
|
|
||||||
expect(handleParens(input))
|
const actual: TokenStructure = [
|
||||||
.toEqual([
|
|
||||||
[
|
[
|
||||||
{token: "hello"}
|
{token: "hello"}
|
||||||
],
|
],
|
||||||
@ -19,6 +19,8 @@ describe("Parens handler", () => {
|
|||||||
{token: "and"},
|
{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
|
* 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) {
|
if (tokens.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import utils from "../../utils.js";
|
|||||||
import TrueExp from "../expressions/true.js";
|
import TrueExp from "../expressions/true.js";
|
||||||
import IsHiddenExp from "../expressions/is_hidden.js";
|
import IsHiddenExp from "../expressions/is_hidden.js";
|
||||||
import SearchContext from "../search_context.js";
|
import SearchContext from "../search_context.js";
|
||||||
import { TokenData } from "./types";
|
import { TokenData, TokenStructure } from "./types";
|
||||||
import Expression from "../expressions/expression.js";
|
import Expression from "../expressions/expression.js";
|
||||||
|
|
||||||
function getFulltext(_tokens: TokenData[], searchContext: SearchContext) {
|
function getFulltext(_tokens: TokenData[], searchContext: SearchContext) {
|
||||||
@ -448,7 +448,7 @@ function getExpression(tokens: TokenData[], searchContext: SearchContext, level
|
|||||||
|
|
||||||
function parse({fulltextTokens, expressionTokens, searchContext}: {
|
function parse({fulltextTokens, expressionTokens, searchContext}: {
|
||||||
fulltextTokens: TokenData[],
|
fulltextTokens: TokenData[],
|
||||||
expressionTokens: (TokenData | TokenData[])[],
|
expressionTokens: TokenStructure,
|
||||||
searchContext: SearchContext,
|
searchContext: SearchContext,
|
||||||
originalQuery: string
|
originalQuery: string
|
||||||
}) {
|
}) {
|
||||||
|
@ -13,7 +13,7 @@ import log from "../../log.js";
|
|||||||
import hoistedNoteService from "../../hoisted_note.js";
|
import hoistedNoteService from "../../hoisted_note.js";
|
||||||
import BNote from "../../../becca/entities/bnote.js";
|
import BNote from "../../../becca/entities/bnote.js";
|
||||||
import BAttribute from "../../../becca/entities/battribute.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 Expression from "../expressions/expression.js";
|
||||||
import sql from "../../sql.js";
|
import sql from "../../sql.js";
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ function parseQueryToExpression(query: string, searchContext: SearchContext) {
|
|||||||
const {fulltextQuery, fulltextTokens, expressionTokens} = lex(query);
|
const {fulltextQuery, fulltextTokens, expressionTokens} = lex(query);
|
||||||
searchContext.fulltextQuery = fulltextQuery;
|
searchContext.fulltextQuery = fulltextQuery;
|
||||||
|
|
||||||
let structuredExpressionTokens: (TokenData | TokenData[])[];
|
let structuredExpressionTokens: TokenStructure;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
structuredExpressionTokens = handleParens(expressionTokens);
|
structuredExpressionTokens = handleParens(expressionTokens);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
export type TokenStructure = (TokenData | TokenStructure)[];
|
||||||
|
|
||||||
export interface TokenData {
|
export interface TokenData {
|
||||||
token: string;
|
token: string;
|
||||||
inQuotes?: boolean;
|
inQuotes?: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user