typesense-instantsearch-adapter 2.6.0-0 → 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 +4 -9
- package/dist/typesense-instantsearch-adapter.js +22 -3
- 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/SearchResponseAdapter.js +22 -3
- package/lib/SearchResponseAdapter.js.map +1 -1
- package/package.json +1 -1
- package/src/SearchResponseAdapter.js +15 -1
package/README.md
CHANGED
|
@@ -369,12 +369,9 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
369
369
|
|
|
370
370
|
> Available as of Typesense Server `v0.25.0.rc12`
|
|
371
371
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
In Algolia, this configuration can be set via the dashboard or via the API.
|
|
377
|
-
But when using Typesense and this adapter, this setting has to be configured when instantiating the adapter like this:
|
|
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.
|
|
378
375
|
|
|
379
376
|
```js
|
|
380
377
|
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
@@ -389,10 +386,8 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
389
386
|
},
|
|
390
387
|
],
|
|
391
388
|
},
|
|
392
|
-
renderingContent: {
|
|
393
|
-
// <<====== Required
|
|
389
|
+
renderingContent: { // <<===== Add this, only if you want to control the order of the widgets displayed by dynamicWidgets
|
|
394
390
|
facetOrdering: {
|
|
395
|
-
// <<====== Required: this controls the order in which the dynamic facets are displayed, and is *required* for the dynamicWidget to render
|
|
396
391
|
facets: {
|
|
397
392
|
order: ["size", "brand"], // <<===== Change this as needed
|
|
398
393
|
},
|
|
@@ -3073,8 +3073,27 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3073
3073
|
return adaptedResult;
|
|
3074
3074
|
}
|
|
3075
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
|
+
}, {
|
|
3076
3093
|
key: "adapt",
|
|
3077
3094
|
value: function adapt() {
|
|
3095
|
+
var adaptedRenderingContent = this._adaptRenderingContent(this.typesenseResponse.facet_counts || []);
|
|
3096
|
+
|
|
3078
3097
|
var adaptedResult = _objectSpread({
|
|
3079
3098
|
hits: this.typesenseResponse.grouped_hits ? this._adaptGroupedHits(this.typesenseResponse.grouped_hits) : this._adaptHits(this.typesenseResponse.hits),
|
|
3080
3099
|
nbHits: this.typesenseResponse.found,
|
|
@@ -3085,9 +3104,9 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3085
3104
|
facets_stats: this._adaptFacetStats(this.typesenseResponse.facet_counts || {}),
|
|
3086
3105
|
query: this.typesenseResponse.request_params.q,
|
|
3087
3106
|
processingTimeMS: this.typesenseResponse.search_time_ms
|
|
3088
|
-
},
|
|
3089
|
-
renderingContent:
|
|
3090
|
-
}); // console.log(adaptedResult);
|
|
3107
|
+
}, Object.keys(adaptedRenderingContent).length > 0 ? {
|
|
3108
|
+
renderingContent: adaptedRenderingContent
|
|
3109
|
+
} : null); // console.log(adaptedResult);
|
|
3091
3110
|
|
|
3092
3111
|
|
|
3093
3112
|
return adaptedResult;
|