typesense-instantsearch-adapter 2.6.0 → 2.7.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 CHANGED
@@ -365,10 +365,47 @@ 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.rc14 | \>= v2.7.0-1 | \>= 4.51 | \>= 6.39 | \>= 4.8 | \>= 4.4 |
408
+ | \>= v0.25.0.rc12 | \>= v2.6.0 | \>= 4.51 | \>= 6.39 | \>= 4.8 | \>= 4.4 |
372
409
  | \>= v0.24 | \>= v2.5.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
373
410
  | \>= v0.21 | \>= v2.0.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
374
411
  | \>= v0.19 | \>= v1.0.0 | \>= 4.2.0 | \>= 6.0.0 | \>= 2.2.1 | \>= 3.0.0 |
@@ -7,7 +7,7 @@
7
7
  exports["TypesenseInstantSearchAdapter"] = factory();
8
8
  else
9
9
  root["TypesenseInstantSearchAdapter"] = factory();
10
- })(self, function() {
10
+ })(self, () => {
11
11
  return /******/ (() => { // webpackBootstrap
12
12
  /******/ var __webpack_modules__ = ({
13
13
 
@@ -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, [{
@@ -2821,7 +2822,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
2821
2822
  var adaptedHits = _this._adaptHits(groupedHit.hits);
2822
2823
 
2823
2824
  adaptedHits.forEach(function (hit) {
2824
- return hit["group_key"] = groupedHit.group_key;
2825
+ hit["group_key"] = hit["_group_key"] = groupedHit.group_key;
2826
+
2827
+ if (groupedHit.found) {
2828
+ hit["_group_found"] = groupedHit.found;
2829
+ }
2825
2830
  });
2826
2831
  return adaptedHits;
2827
2832
  }); // adaptedResult is now in the form of [[{}, {}], [{}, {}], ...]
@@ -2842,7 +2847,8 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
2842
2847
 
2843
2848
  adaptedHit.objectID = typesenseHit.document.id;
2844
2849
  adaptedHit._snippetResult = _this2._adaptHighlightResult(typesenseHit, "snippet");
2845
- adaptedHit._highlightResult = _this2._adaptHighlightResult(typesenseHit, "value"); // Add metadata fields to result, if a field with that name doesn't already exist
2850
+ adaptedHit._highlightResult = _this2._adaptHighlightResult(typesenseHit, "value");
2851
+ adaptedHit._rawTypesenseHit = typesenseHit; // Add metadata fields to result, if a field with that name doesn't already exist
2846
2852
 
2847
2853
  ["text_match", "geo_distance_meters", "curated", "text_match_info"].forEach(function (metadataField) {
2848
2854
  if (Object.keys(typesenseHit).includes(metadataField) && !Object.keys(adaptedHit).includes(metadataField)) {
@@ -3072,9 +3078,28 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
3072
3078
  return adaptedResult;
3073
3079
  }
3074
3080
  }, {
3081
+ key: "_adaptRenderingContent",
3082
+ value: function _adaptRenderingContent(typesenseFacetCounts) {
3083
+ var _adaptedResult$facetO, _adaptedResult$facetO2;
3084
+
3085
+ var adaptedResult = Object.assign({}, this.configuration.renderingContent); // Only set facet ordering if the user has not set one
3086
+
3087
+ 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) {
3088
+ adaptedResult.facetOrdering = adaptedResult.facetOrdering || {};
3089
+ adaptedResult.facetOrdering.facets = adaptedResult.facetOrdering.facets || {};
3090
+ adaptedResult.facetOrdering.facets.order = typesenseFacetCounts.map(function (fc) {
3091
+ return fc["field_name"];
3092
+ });
3093
+ }
3094
+
3095
+ return adaptedResult;
3096
+ }
3097
+ }, {
3075
3098
  key: "adapt",
3076
3099
  value: function adapt() {
3077
- var adaptedResult = {
3100
+ var adaptedRenderingContent = this._adaptRenderingContent(this.typesenseResponse.facet_counts || []);
3101
+
3102
+ var adaptedResult = _objectSpread({
3078
3103
  hits: this.typesenseResponse.grouped_hits ? this._adaptGroupedHits(this.typesenseResponse.grouped_hits) : this._adaptHits(this.typesenseResponse.hits),
3079
3104
  nbHits: this.typesenseResponse.found,
3080
3105
  page: this.typesenseResponse.page - 1,
@@ -3084,7 +3109,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
3084
3109
  facets_stats: this._adaptFacetStats(this.typesenseResponse.facet_counts || {}),
3085
3110
  query: this.typesenseResponse.request_params.q,
3086
3111
  processingTimeMS: this.typesenseResponse.search_time_ms
3087
- }; // console.log(adaptedResult);
3112
+ }, Object.keys(adaptedRenderingContent).length > 0 ? {
3113
+ renderingContent: adaptedRenderingContent
3114
+ } : null); // console.log(adaptedResult);
3115
+
3088
3116
 
3089
3117
  return adaptedResult;
3090
3118
  }