typesense-instantsearch-adapter 2.8.0-3 → 2.8.0-4

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
@@ -469,11 +469,16 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
469
469
  brand: "(sort_by: _alpha:asc)",
470
470
  category: "(sort_by: _alpha:desc)",
471
471
  }, // <======= Add any facet_by parameter as a key value pair. Don't forget the surrounding parantheses in the value.
472
+ collectionSpecificFacetByOptions: {
473
+ collection1: {
474
+ brand: "(sort_by: _alpha:desc)",
475
+ },
476
+ }, // <======= Use this parameter if multiple collections share the same field names, and you want to use different options for each field. This will override facetByOptions for that particular collection.
472
477
  additionalSearchParameters,
473
478
  });
474
479
  ```
475
480
 
476
- Note that for sorting in refinementLists, in addition to sorting on the Typesense Server-side, you'd also need to pass the [`sortBy`](https://www.algolia.com/doc/api-reference/widgets/refinement-list/js/#widget-param-sortby) parameter to the refinementList widget to also sort the results appropriately on the client-side.
481
+ Note that for sorting in refinementLists, in addition to sorting on the Typesense Server-side, you'd also need to pass the [`sortBy`](https://www.algolia.com/doc/api-reference/widgets/refinement-list/js/#widget-param-sortby) parameter to the refinementList widget to also sort the results appropriately on the client-side.
477
482
 
478
483
  ### Grouped Hits
479
484
 
@@ -2207,7 +2207,8 @@ var Configuration = /*#__PURE__*/function () {
2207
2207
  _options$collectionSp,
2208
2208
  _this = this,
2209
2209
  _options$flattenGroup,
2210
- _options$facetByOptio;
2210
+ _options$facetByOptio,
2211
+ _options$collectionSp2;
2211
2212
 
2212
2213
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2213
2214
 
@@ -2246,6 +2247,7 @@ var Configuration = /*#__PURE__*/function () {
2246
2247
  this.renderingContent = options.renderingContent;
2247
2248
  this.flattenGroupedHits = (_options$flattenGroup = options.flattenGroupedHits) !== null && _options$flattenGroup !== void 0 ? _options$flattenGroup : true;
2248
2249
  this.facetByOptions = (_options$facetByOptio = options.facetByOptions) !== null && _options$facetByOptio !== void 0 ? _options$facetByOptio : {};
2250
+ this.collectionSpecificFacetByOptions = (_options$collectionSp2 = options.collectionSpecificFacetByOptions) !== null && _options$collectionSp2 !== void 0 ? _options$collectionSp2 : {};
2249
2251
  }
2250
2252
 
2251
2253
  (0,_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__["default"])(Configuration, [{
@@ -2752,11 +2754,15 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
2752
2754
  }
2753
2755
  }, {
2754
2756
  key: "_adaptFacetBy",
2755
- value: function _adaptFacetBy(facets) {
2757
+ value: function _adaptFacetBy(facets, collectionName) {
2756
2758
  var _this3 = this;
2757
2759
 
2758
2760
  return [facets].flat().map(function (facet) {
2759
- if (_this3.configuration.facetByOptions[facet]) {
2761
+ var _this3$configuration$;
2762
+
2763
+ if ((_this3$configuration$ = _this3.configuration.collectionSpecificFacetByOptions) !== null && _this3$configuration$ !== void 0 && (_this3$configuration$ = _this3$configuration$[collectionName]) !== null && _this3$configuration$ !== void 0 && _this3$configuration$[facet]) {
2764
+ return "".concat(facet).concat(_this3.configuration.collectionSpecificFacetByOptions[collectionName][facet]);
2765
+ } else if (_this3.configuration.facetByOptions[facet]) {
2760
2766
  return "".concat(facet).concat(_this3.configuration.facetByOptions[facet]);
2761
2767
  } else {
2762
2768
  return facet;
@@ -2800,7 +2806,7 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
2800
2806
  Object.assign(typesenseSearchParams, {
2801
2807
  collection: adaptedCollectionName,
2802
2808
  q: params.query === "" || params.query === undefined ? "*" : params.query,
2803
- facet_by: snakeCasedAdditionalSearchParameters.facet_by || this._adaptFacetBy(params.facets),
2809
+ facet_by: snakeCasedAdditionalSearchParameters.facet_by || this._adaptFacetBy(params.facets, adaptedCollectionName),
2804
2810
  filter_by: this._adaptFilters(params) || snakeCasedAdditionalSearchParameters.filter_by,
2805
2811
  sort_by: adaptedSortBy || snakeCasedAdditionalSearchParameters.sort_by,
2806
2812
  max_facet_values: params.maxValuesPerFacet,