Skip to content

Commit

Permalink
fix(search): limit from UI not applied (closes #920)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jan 10, 2025
1 parent 7ea324b commit 180af2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/search/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/services/search/services/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 180af2c

Please sign in to comment.