typesense-instantsearch-adapter 2.5.1 → 2.6.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/typesense-instantsearch-adapter.js +25 -2
- package/dist/typesense-instantsearch-adapter.js.map +1 -1
- package/dist/typesense-instantsearch-adapter.min.js +1 -1
- package/dist/typesense-instantsearch-adapter.min.js.map +1 -1
- package/lib/Configuration.js +1 -0
- package/lib/Configuration.js.map +1 -1
- package/lib/SearchResponseAdapter.js +24 -2
- package/lib/SearchResponseAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/Configuration.js +2 -0
- package/src/SearchResponseAdapter.js +15 -0
package/README.md
CHANGED
|
@@ -365,10 +365,45 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
365
365
|
});
|
|
366
366
|
```
|
|
367
367
|
|
|
368
|
+
### `dynamicWidgets`
|
|
369
|
+
|
|
370
|
+
> Available as of Typesense Server `v0.25.0.rc12`
|
|
371
|
+
|
|
372
|
+
This [`dynamicWidgets`](https://www.algolia.com/doc/api-reference/widgets/dynamic-facets/js/) widget works out of the box with no additional changes,
|
|
373
|
+
but if you want to control the order in which these facets are displayed in the UI
|
|
374
|
+
Instantsearch expects a parameter called [`renderingContent`](https://www.algolia.com/doc/api-reference/api-parameters/renderingContent/) to be set.
|
|
375
|
+
|
|
376
|
+
```js
|
|
377
|
+
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
378
|
+
server: {
|
|
379
|
+
apiKey: "xyz",
|
|
380
|
+
nodes: [
|
|
381
|
+
{
|
|
382
|
+
host: "localhost",
|
|
383
|
+
port: "8108",
|
|
384
|
+
path: "/",
|
|
385
|
+
protocol: "http",
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
},
|
|
389
|
+
renderingContent: { // <<===== Add this, only if you want to control the order of the widgets displayed by dynamicWidgets
|
|
390
|
+
facetOrdering: {
|
|
391
|
+
facets: {
|
|
392
|
+
order: ["size", "brand"], // <<===== Change this as needed
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
additionalSearchParameters,
|
|
397
|
+
});
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Read more about all available options for `renderingContent` in [Algolia's documentation here](https://www.algolia.com/doc/api-reference/api-parameters/renderingContent/?client=javascript#examples).
|
|
401
|
+
|
|
368
402
|
## Compatibility
|
|
369
403
|
|
|
370
404
|
| Typesense Server | typesense-instantsearch-adapter | instantsearch.js | react-instantsearch | vue-instantsearch | angular-instantsearch |
|
|
371
405
|
| ---------------- | ------------------------------- | ---------------- | ------------------- | ----------------- | --------------------- |
|
|
406
|
+
| \>= v0.25.0.rc12 | \>= v2.6.0 | \>= 4.51 | \>= 6.39 | \>= 4.8 | \>= 4.4 |
|
|
372
407
|
| \>= v0.24 | \>= v2.5.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
|
|
373
408
|
| \>= v0.21 | \>= v2.0.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
|
|
374
409
|
| \>= v0.19 | \>= v1.0.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
|
|
@@ -2250,6 +2250,7 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2250
2250
|
return params[key] === undefined ? delete params[key] : {};
|
|
2251
2251
|
});
|
|
2252
2252
|
});
|
|
2253
|
+
this.renderingContent = options.renderingContent;
|
|
2253
2254
|
}
|
|
2254
2255
|
|
|
2255
2256
|
(0,_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__["default"])(Configuration, [{
|
|
@@ -3072,9 +3073,28 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3072
3073
|
return adaptedResult;
|
|
3073
3074
|
}
|
|
3074
3075
|
}, {
|
|
3076
|
+
key: "_adaptRenderingContent",
|
|
3077
|
+
value: function _adaptRenderingContent(typesenseFacetCounts) {
|
|
3078
|
+
var _adaptedResult$facetO, _adaptedResult$facetO2;
|
|
3079
|
+
|
|
3080
|
+
var adaptedResult = Object.assign({}, this.configuration.renderingContent); // Only set facet ordering if the user has not set one
|
|
3081
|
+
|
|
3082
|
+
if (((_adaptedResult$facetO = adaptedResult.facetOrdering) === null || _adaptedResult$facetO === void 0 ? void 0 : (_adaptedResult$facetO2 = _adaptedResult$facetO.facets) === null || _adaptedResult$facetO2 === void 0 ? void 0 : _adaptedResult$facetO2.order) == null) {
|
|
3083
|
+
adaptedResult.facetOrdering = adaptedResult.facetOrdering || {};
|
|
3084
|
+
adaptedResult.facetOrdering.facets = adaptedResult.facetOrdering.facets || {};
|
|
3085
|
+
adaptedResult.facetOrdering.facets.order = typesenseFacetCounts.map(function (fc) {
|
|
3086
|
+
return fc["field_name"];
|
|
3087
|
+
});
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
return adaptedResult;
|
|
3091
|
+
}
|
|
3092
|
+
}, {
|
|
3075
3093
|
key: "adapt",
|
|
3076
3094
|
value: function adapt() {
|
|
3077
|
-
var
|
|
3095
|
+
var adaptedRenderingContent = this._adaptRenderingContent(this.typesenseResponse.facet_counts || []);
|
|
3096
|
+
|
|
3097
|
+
var adaptedResult = _objectSpread({
|
|
3078
3098
|
hits: this.typesenseResponse.grouped_hits ? this._adaptGroupedHits(this.typesenseResponse.grouped_hits) : this._adaptHits(this.typesenseResponse.hits),
|
|
3079
3099
|
nbHits: this.typesenseResponse.found,
|
|
3080
3100
|
page: this.typesenseResponse.page - 1,
|
|
@@ -3084,7 +3104,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3084
3104
|
facets_stats: this._adaptFacetStats(this.typesenseResponse.facet_counts || {}),
|
|
3085
3105
|
query: this.typesenseResponse.request_params.q,
|
|
3086
3106
|
processingTimeMS: this.typesenseResponse.search_time_ms
|
|
3087
|
-
}
|
|
3107
|
+
}, Object.keys(adaptedRenderingContent).length > 0 ? {
|
|
3108
|
+
renderingContent: adaptedRenderingContent
|
|
3109
|
+
} : null); // console.log(adaptedResult);
|
|
3110
|
+
|
|
3088
3111
|
|
|
3089
3112
|
return adaptedResult;
|
|
3090
3113
|
}
|