Skip to content

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed May 23, 2024
1 parent a902060 commit ceeafc4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/facets/src/Facets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class Facets<S extends Schema, I extends Item<S>> {
const sortConfig = this.#sortConfigForFacet(field);
if (
(resultSet && sortConfig[0] === "frequency") ||
(selectedFirst && selected.length > 0)
(selectedFirst && Array.isArray(selected) && selected.length > 0)
) {
newFacet.sort(
this.#sortForFacet(field, selectedFirst ? selected : undefined)
Expand All @@ -461,7 +461,11 @@ export class Facets<S extends Schema, I extends Item<S>> {
}

return {
...paginate(newFacet, page, perPage, ([x, y]) => [x, y]),
// If there are selected values - do not paginate
// other way would be - cherry pick selected items in addition to a page
...(Array.isArray(selected) && selected.length > 0
? paginate(newFacet, 0, -1, ([x, y]) => [x, y])
: paginate(newFacet, page, perPage, ([x, y]) => [x, y])),
stats,
} as FacetResult;
}
Expand Down

0 comments on commit ceeafc4

Please sign in to comment.