Skip to content

Commit

Permalink
Add ability to pass in custom facet_by options
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbosco committed Oct 26, 2023
1 parent cba3362 commit 41913cf
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 16 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,37 @@ Read more about all available options for `renderingContent` in [Algolia's docum
});
```

### Setting `facet_by` options

> Available as of typesense-instantsearch-adapter `2.8.0-1` and Typesense Server `v0.26.0.rc25`
The `facet_by` parameter is managed by InstantSearch internally when you use the various filter widget.

But if you need to pass custom options to the `facet_by` parameter (eg: server-side sort options), then you can use the `facetByOptions` parameter as shown below:

```js
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: "xyz",
nodes: [
{
host: "localhost",
port: "8108",
path: "/",
protocol: "http",
},
],
},
facetByOptions: {
brand: "(sort_by: _alpha:asc)",
category: "(sort_by: _alpha:desc)",
}, // <======= Add any facet_by parameter as a key value pair. Don't forget the surrounding parantheses in the value.
additionalSearchParameters,
});
```

Note that for sorting in refinementLists, in addition to sorting on the Typesense Server-side, you'd also need to pass the [`sortBy`](https://www.algolia.com/doc/api-reference/widgets/refinement-list/js/#widget-param-sortby) parameter to the refinementList widget to also sort the results appropriately on the client-side.

### Grouped Hits

> Available as of typesense-instantsearch-adapter `2.7.1-4`
Expand Down
23 changes: 19 additions & 4 deletions dist/typesense-instantsearch-adapter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/typesense-instantsearch-adapter.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense-instantsearch-adapter.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense-instantsearch-adapter.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ interface BaseAdapterOptions {
facetableFieldsWithSpecialCharacters?: string[];
renderingContent?: object;
flattenGroupedHits?: boolean;
facetByOptions?: object;
}

interface CollectionSearchParameters {
Expand Down
3 changes: 2 additions & 1 deletion jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const isDebugMode = process.env.NODE_OPTIONS && process.env.NODE_OPTIONS.includes("javascript-debugger");
module.exports = {
launch: {
dumpio: true,
// headless: process.env.HEADLESS === "true" || process.env.CI === "true",
headless: true,
headless: isDebugMode ? false : true,
slowMo: 10,
defaultViewport: null,
// devtools: true
Expand Down
4 changes: 3 additions & 1 deletion lib/Configuration.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41913cf

Please sign in to comment.