typesense-instantsearch-adapter 2.5.0 → 2.6.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 CHANGED
@@ -365,10 +365,50 @@ 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
+ In order to use [`dynamicWidgets`](https://www.algolia.com/doc/api-reference/widgets/dynamic-facets/js/),
373
+ Instantsearch expects a parameter called [`renderingContent`](https://www.algolia.com/doc/api-reference/api-parameters/renderingContent/) to be set
374
+ which controls the display logic for this widget.
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:
378
+
379
+ ```js
380
+ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
381
+ server: {
382
+ apiKey: "xyz",
383
+ nodes: [
384
+ {
385
+ host: "localhost",
386
+ port: "8108",
387
+ path: "/",
388
+ protocol: "http",
389
+ },
390
+ ],
391
+ },
392
+ renderingContent: {
393
+ // <<====== Required
394
+ facetOrdering: {
395
+ // <<====== Required: this controls the order in which the dynamic facets are displayed, and is *required* for the dynamicWidget to render
396
+ facets: {
397
+ order: ["size", "brand"], // <<===== Change this as needed
398
+ },
399
+ },
400
+ },
401
+ additionalSearchParameters,
402
+ });
403
+ ```
404
+
405
+ 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).
406
+
368
407
  ## Compatibility
369
408
 
370
409
  | Typesense Server | typesense-instantsearch-adapter | instantsearch.js | react-instantsearch | vue-instantsearch | angular-instantsearch |
371
- |------------------|---------------------------------|------------------|---------------------|-------------------|-----------------------|
410
+ | ---------------- | ------------------------------- | ---------------- | ------------------- | ----------------- | --------------------- |
411
+ | \>= v0.25.0.rc12 | \>= v2.6.0 | \>= 4.51 | \>= 6.39 | \>= 4.8 | \>= 4.4 |
372
412
  | \>= v0.24 | \>= v2.5.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
373
413
  | \>= v0.21 | \>= v2.0.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
374
414
  | \>= 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, [{
@@ -3024,8 +3025,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
3024
3025
  key: "_adaptHighlightInPrimitiveValue",
3025
3026
  value: function _adaptHighlightInPrimitiveValue(primitiveValue, highlightPrimitiveValue, snippetOrValue) {
3026
3027
  if (highlightPrimitiveValue != null) {
3028
+ var _ref9, _highlightPrimitiveVa;
3029
+
3027
3030
  return {
3028
- value: this._adaptHighlightTag("".concat(highlightPrimitiveValue[snippetOrValue]), this.instantsearchRequest.params.highlightPreTag, this.instantsearchRequest.params.highlightPostTag),
3031
+ value: this._adaptHighlightTag("".concat((_ref9 = (_highlightPrimitiveVa = highlightPrimitiveValue[snippetOrValue]) !== null && _highlightPrimitiveVa !== void 0 ? _highlightPrimitiveVa : highlightPrimitiveValue["highlight"]) !== null && _ref9 !== void 0 ? _ref9 : highlightPrimitiveValue["snippet"]), this.instantsearchRequest.params.highlightPreTag, this.instantsearchRequest.params.highlightPostTag),
3029
3032
  matchLevel: (highlightPrimitiveValue.matched_tokens || []).length > 0 ? "full" : "none",
3030
3033
  matchedWords: highlightPrimitiveValue.matched_tokens || []
3031
3034
  };
@@ -3072,7 +3075,7 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
3072
3075
  }, {
3073
3076
  key: "adapt",
3074
3077
  value: function adapt() {
3075
- var adaptedResult = {
3078
+ var adaptedResult = _objectSpread({
3076
3079
  hits: this.typesenseResponse.grouped_hits ? this._adaptGroupedHits(this.typesenseResponse.grouped_hits) : this._adaptHits(this.typesenseResponse.hits),
3077
3080
  nbHits: this.typesenseResponse.found,
3078
3081
  page: this.typesenseResponse.page - 1,
@@ -3082,7 +3085,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
3082
3085
  facets_stats: this._adaptFacetStats(this.typesenseResponse.facet_counts || {}),
3083
3086
  query: this.typesenseResponse.request_params.q,
3084
3087
  processingTimeMS: this.typesenseResponse.search_time_ms
3085
- }; // console.log(adaptedResult);
3088
+ }, this.configuration.renderingContent != null && {
3089
+ renderingContent: this.configuration.renderingContent
3090
+ }); // console.log(adaptedResult);
3091
+
3086
3092
 
3087
3093
  return adaptedResult;
3088
3094
  }