typesense-instantsearch-adapter 2.6.0 → 2.7.0-0
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 +36 -0
- package/dist/typesense-instantsearch-adapter.js +27 -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/Configuration.js +1 -0
- package/lib/Configuration.js.map +1 -1
- package/lib/SearchResponseAdapter.js +26 -3
- package/lib/SearchResponseAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/Configuration.js +2 -0
- package/src/SearchResponseAdapter.js +16 -0
package/README.md
CHANGED
|
@@ -365,10 +365,46 @@ 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: {
|
|
390
|
+
// <<===== Add this, only if you want to control the order of the widgets displayed by dynamicWidgets
|
|
391
|
+
facetOrdering: {
|
|
392
|
+
facets: {
|
|
393
|
+
order: ["size", "brand"], // <<===== Change this as needed
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
additionalSearchParameters,
|
|
398
|
+
});
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
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).
|
|
402
|
+
|
|
368
403
|
## Compatibility
|
|
369
404
|
|
|
370
405
|
| Typesense Server | typesense-instantsearch-adapter | instantsearch.js | react-instantsearch | vue-instantsearch | angular-instantsearch |
|
|
371
406
|
| ---------------- | ------------------------------- | ---------------- | ------------------- | ----------------- | --------------------- |
|
|
407
|
+
| \>= v0.25.0.rc12 | \>= v2.6.0 | \>= 4.51 | \>= 6.39 | \>= 4.8 | \>= 4.4 |
|
|
372
408
|
| \>= v0.24 | \>= v2.5.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
|
|
373
409
|
| \>= v0.21 | \>= v2.0.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
|
|
374
410
|
| \>= 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, [{
|
|
@@ -2842,7 +2843,8 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2842
2843
|
|
|
2843
2844
|
adaptedHit.objectID = typesenseHit.document.id;
|
|
2844
2845
|
adaptedHit._snippetResult = _this2._adaptHighlightResult(typesenseHit, "snippet");
|
|
2845
|
-
adaptedHit._highlightResult = _this2._adaptHighlightResult(typesenseHit, "value");
|
|
2846
|
+
adaptedHit._highlightResult = _this2._adaptHighlightResult(typesenseHit, "value");
|
|
2847
|
+
adaptedHit._rawTypesenseHit = typesenseHit; // Add metadata fields to result, if a field with that name doesn't already exist
|
|
2846
2848
|
|
|
2847
2849
|
["text_match", "geo_distance_meters", "curated", "text_match_info"].forEach(function (metadataField) {
|
|
2848
2850
|
if (Object.keys(typesenseHit).includes(metadataField) && !Object.keys(adaptedHit).includes(metadataField)) {
|
|
@@ -3072,9 +3074,28 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3072
3074
|
return adaptedResult;
|
|
3073
3075
|
}
|
|
3074
3076
|
}, {
|
|
3077
|
+
key: "_adaptRenderingContent",
|
|
3078
|
+
value: function _adaptRenderingContent(typesenseFacetCounts) {
|
|
3079
|
+
var _adaptedResult$facetO, _adaptedResult$facetO2;
|
|
3080
|
+
|
|
3081
|
+
var adaptedResult = Object.assign({}, this.configuration.renderingContent); // Only set facet ordering if the user has not set one
|
|
3082
|
+
|
|
3083
|
+
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) {
|
|
3084
|
+
adaptedResult.facetOrdering = adaptedResult.facetOrdering || {};
|
|
3085
|
+
adaptedResult.facetOrdering.facets = adaptedResult.facetOrdering.facets || {};
|
|
3086
|
+
adaptedResult.facetOrdering.facets.order = typesenseFacetCounts.map(function (fc) {
|
|
3087
|
+
return fc["field_name"];
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
return adaptedResult;
|
|
3092
|
+
}
|
|
3093
|
+
}, {
|
|
3075
3094
|
key: "adapt",
|
|
3076
3095
|
value: function adapt() {
|
|
3077
|
-
var
|
|
3096
|
+
var adaptedRenderingContent = this._adaptRenderingContent(this.typesenseResponse.facet_counts || []);
|
|
3097
|
+
|
|
3098
|
+
var adaptedResult = _objectSpread({
|
|
3078
3099
|
hits: this.typesenseResponse.grouped_hits ? this._adaptGroupedHits(this.typesenseResponse.grouped_hits) : this._adaptHits(this.typesenseResponse.hits),
|
|
3079
3100
|
nbHits: this.typesenseResponse.found,
|
|
3080
3101
|
page: this.typesenseResponse.page - 1,
|
|
@@ -3084,7 +3105,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3084
3105
|
facets_stats: this._adaptFacetStats(this.typesenseResponse.facet_counts || {}),
|
|
3085
3106
|
query: this.typesenseResponse.request_params.q,
|
|
3086
3107
|
processingTimeMS: this.typesenseResponse.search_time_ms
|
|
3087
|
-
}
|
|
3108
|
+
}, Object.keys(adaptedRenderingContent).length > 0 ? {
|
|
3109
|
+
renderingContent: adaptedRenderingContent
|
|
3110
|
+
} : null); // console.log(adaptedResult);
|
|
3111
|
+
|
|
3088
3112
|
|
|
3089
3113
|
return adaptedResult;
|
|
3090
3114
|
}
|