Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed Mar 26, 2024
1 parent 8ad8772 commit d8e215c
Show file tree
Hide file tree
Showing 6 changed files with 1,568 additions and 1,349 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ Client-side:

### Sorting

See https://github.com/CloudCannon/pagefind/issues/513
See:

- https://github.com/CloudCannon/pagefind/issues/513
- https://github.com/CloudCannon/pagefind/issues/259

### Stats for numerical facets

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tsc": "turbo run tsc"
},
"devDependencies": {
"turbo": "^1.10.16",
"typescript": "^5.2.2"
"turbo": "^1.13.0",
"typescript": "^5.4.3"
}
}
6 changes: 3 additions & 3 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"dependencies": {
"@stereobooster/pagefind-instantsearch": "workspace:*",
"instantsearch.css": "^8.1.0",
"instantsearch.js": "4.60.0"
"instantsearch.js": "4.66.0"
},
"devDependencies": {
"pagefind": "^1.0.4",
"typescript": "^5.2.2",
"vite": "^5.0.12"
"typescript": "^5.4.3",
"vite": "^5.2.6"
}
}
8 changes: 4 additions & 4 deletions packages/pagefind-instantsearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"pagefind": "^1.0.4"
},
"devDependencies": {
"@algolia/client-search": "^4.20.0",
"instantsearch.js": "4.60.0",
"@algolia/client-search": "^4.23.1",
"instantsearch.js": "4.66.0",
"microbundle": "^0.15.1",
"pagefind": "^1.0.4",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
"typescript": "^5.4.3",
"vitest": "^1.4.0"
}
}
12 changes: 8 additions & 4 deletions packages/pagefind-instantsearch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export type Schema = S;
import { adaptHit, adaptFacets } from "./adaptResponse";
import { adaptRequest } from "./adaptRequest";

const isEmpty = (o: Record<string, any>) => Object.keys(o).length === 0;

export function getSearchClient<S extends Schema>(
clientPromise: Promise<any>,
schema: S
): SearchClient {
const indexPromise = clientPromise.then(async (pagefind) => {
pagefind.init();
await pagefind.filters();
pagefind.filters();
return pagefind;
});

Expand All @@ -45,7 +47,8 @@ export function getSearchClient<S extends Schema>(
.map(adaptHit)
);
const nbHits = response.results.length;
const facets = !request.params?.query
// TODO: if search is null and there are no filters - use `await index.filters()`
const facets = isEmpty(response.filters)
? await index.filters()
: response.filters;
const maxValuesPerFacet = request.params?.maxValuesPerFacet || 10;
Expand Down Expand Up @@ -77,11 +80,12 @@ export function getSearchClient<S extends Schema>(
Promise.all(
requests.map(async (request) => {
const response = await index.search(
request.params?.query,
request.params?.query?.trim() || null,
adaptRequest(request)
);

const facets = !request.params?.query
// TODO: if search is null and there are no filters - use `await index.filters()`
const facets = isEmpty(response.filters)
? await index.filters()
: response.filters;

Expand Down
Loading

0 comments on commit d8e215c

Please sign in to comment.