typesense-instantsearch-adapter 2.8.0-0 → 2.8.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
@@ -444,6 +444,37 @@ Read more about all available options for `renderingContent` in [Algolia's docum
444
444
  });
445
445
  ```
446
446
 
447
+ ### Setting `facet_by` options
448
+
449
+ > Available as of typesense-instantsearch-adapter `2.8.0-1` and Typesense Server `v0.26.0.rc25`
450
+
451
+ The `facet_by` parameter is managed by InstantSearch internally when you use the various filter widget.
452
+
453
+ But if you need to pass custom options to the `facet_by` parameter (eg: server-side sort options), then you can use the `facetByOptions` parameter as shown below:
454
+
455
+ ```js
456
+ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
457
+ server: {
458
+ apiKey: "xyz",
459
+ nodes: [
460
+ {
461
+ host: "localhost",
462
+ port: "8108",
463
+ path: "/",
464
+ protocol: "http",
465
+ },
466
+ ],
467
+ },
468
+ facetByOptions: {
469
+ brand: "(sort_by: _alpha:asc)",
470
+ category: "(sort_by: _alpha:desc)",
471
+ }, // <======= Add any facet_by parameter as a key value pair. Don't forget the surrounding parantheses in the value.
472
+ additionalSearchParameters,
473
+ });
474
+ ```
475
+
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.
477
+
447
478
  ### Grouped Hits
448
479
 
449
480
  > Available as of typesense-instantsearch-adapter `2.7.1-4`
@@ -2206,7 +2206,8 @@ var Configuration = /*#__PURE__*/function () {
2206
2206
  _options$facetableFie,
2207
2207
  _options$collectionSp,
2208
2208
  _this = this,
2209
- _options$flattenGroup;
2209
+ _options$flattenGroup,
2210
+ _options$facetByOptio;
2210
2211
 
2211
2212
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2212
2213
 
@@ -2244,6 +2245,7 @@ var Configuration = /*#__PURE__*/function () {
2244
2245
  });
2245
2246
  this.renderingContent = options.renderingContent;
2246
2247
  this.flattenGroupedHits = (_options$flattenGroup = options.flattenGroupedHits) !== null && _options$flattenGroup !== void 0 ? _options$flattenGroup : true;
2248
+ this.facetByOptions = (_options$facetByOptio = options.facetByOptions) !== null && _options$facetByOptio !== void 0 ? _options$facetByOptio : {};
2247
2249
  }
2248
2250
 
2249
2251
  (0,_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__["default"])(Configuration, [{
@@ -2748,6 +2750,19 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
2748
2750
  value: function _adaptSortBy(indexName) {
2749
2751
  return indexName.match(this.constructor.INDEX_NAME_MATCHING_REGEX)[3];
2750
2752
  }
2753
+ }, {
2754
+ key: "_adaptFacetBy",
2755
+ value: function _adaptFacetBy(facets) {
2756
+ var _this3 = this;
2757
+
2758
+ return [facets].flat().map(function (facet) {
2759
+ if (_this3.configuration.facetByOptions[facet]) {
2760
+ return "".concat(facet).concat(_this3.configuration.facetByOptions[facet]);
2761
+ } else {
2762
+ return facet;
2763
+ }
2764
+ }).join(",");
2765
+ }
2751
2766
  }, {
2752
2767
  key: "_buildSearchParameters",
2753
2768
  value: function _buildSearchParameters(instantsearchRequest) {
@@ -2785,7 +2800,7 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
2785
2800
  Object.assign(typesenseSearchParams, {
2786
2801
  collection: adaptedCollectionName,
2787
2802
  q: params.query === "" || params.query === undefined ? "*" : params.query,
2788
- facet_by: [params.facets].flat().join(","),
2803
+ facet_by: this._adaptFacetBy(params.facets),
2789
2804
  filter_by: this._adaptFilters(params) || snakeCasedAdditionalSearchParameters.filter_by,
2790
2805
  sort_by: adaptedSortBy || snakeCasedAdditionalSearchParameters.sort_by,
2791
2806
  max_facet_values: params.maxValuesPerFacet,
@@ -2827,7 +2842,7 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
2827
2842
  key: "request",
2828
2843
  value: function () {
2829
2844
  var _request = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__["default"])( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().mark(function _callee() {
2830
- var _this3 = this;
2845
+ var _this4 = this;
2831
2846
 
2832
2847
  var searches;
2833
2848
  return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().wrap(function _callee$(_context) {
@@ -2835,7 +2850,7 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
2835
2850
  case 0:
2836
2851
  // console.log(this.instantsearchRequests);
2837
2852
  searches = this.instantsearchRequests.map(function (instantsearchRequest) {
2838
- return _this3._buildSearchParameters(instantsearchRequest);
2853
+ return _this4._buildSearchParameters(instantsearchRequest);
2839
2854
  });
2840
2855
  return _context.abrupt("return", this.typesenseClient.multiSearch.perform({
2841
2856
  searches: searches