mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
fix(search): limit from UI not applied (closes #920)
This commit is contained in:
parent
7ea324bc5b
commit
180af2ce30
@ -3,6 +3,7 @@
|
||||
// but we access properties like "subExpressions" which is not defined in the "Expression" class.
|
||||
|
||||
import Expression from "../../src/services/search/expressions/expression.js";
|
||||
import OrderByAndLimitExp from "../../src/services/search/expressions/order_by_and_limit.js";
|
||||
import SearchContext from "../../src/services/search/search_context.js";
|
||||
import parse from "../../src/services/search/services/parse.js";
|
||||
|
||||
@ -244,6 +245,21 @@ describe("Parser", () => {
|
||||
expect(thirdSub.constructor.name).toEqual("AttributeExistsExp");
|
||||
expect(thirdSub.attributeName).toEqual("fourth");
|
||||
});
|
||||
|
||||
it("parses limit without order by", () => {
|
||||
const rootExp = parse({
|
||||
fulltextTokens: tokens(["hello", "hi"]),
|
||||
expressionTokens: [],
|
||||
searchContext: new SearchContext({
|
||||
excludeArchived: true,
|
||||
limit: 2
|
||||
})
|
||||
});
|
||||
|
||||
expect(rootExp).toBeInstanceOf(OrderByAndLimitExp);
|
||||
expect(rootExp.limit).toBe(2);
|
||||
expect(rootExp.subExpression).toBeInstanceOf(AndExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Invalid expressions", () => {
|
||||
|
@ -441,6 +441,12 @@ function parse({ fulltextTokens, expressionTokens, searchContext }: { fulltextTo
|
||||
expression
|
||||
]);
|
||||
|
||||
if (searchContext.limit && !searchContext.orderBy) {
|
||||
const filterExp = exp;
|
||||
exp = new OrderByAndLimitExp([], searchContext.limit || undefined );
|
||||
(exp as any).subExpression = filterExp;
|
||||
}
|
||||
|
||||
if (searchContext.orderBy && searchContext.orderBy !== "relevancy") {
|
||||
const filterExp = exp;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user