instantsearch.js 4.56.6 → 4.56.7

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.
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.56.6 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.56.7 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -5571,14 +5571,20 @@
5571
5571
  };
5572
5572
 
5573
5573
  function clone(value) {
5574
- if (_typeof(value) === 'object' && value !== null) {
5574
+ if (typeof value === 'object' && value !== null) {
5575
5575
  return _merge(Array.isArray(value) ? [] : {}, value);
5576
5576
  }
5577
5577
  return value;
5578
5578
  }
5579
+
5579
5580
  function isObjectOrArrayOrFunction(value) {
5580
- return typeof value === 'function' || Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]';
5581
+ return (
5582
+ typeof value === 'function' ||
5583
+ Array.isArray(value) ||
5584
+ Object.prototype.toString.call(value) === '[object Object]'
5585
+ );
5581
5586
  }
5587
+
5582
5588
  function _merge(target, source) {
5583
5589
  if (target === source) {
5584
5590
  return target;
@@ -5586,17 +5592,27 @@
5586
5592
 
5587
5593
  // eslint-disable-next-line no-restricted-syntax
5588
5594
  for (var key in source) {
5589
- if (!Object.prototype.hasOwnProperty.call(source, key) || key === '__proto__' || key === 'constructor') {
5595
+ if (
5596
+ !Object.prototype.hasOwnProperty.call(source, key) ||
5597
+ key === '__proto__' ||
5598
+ key === 'constructor'
5599
+ ) {
5590
5600
  // eslint-disable-next-line no-continue
5591
5601
  continue;
5592
5602
  }
5603
+
5593
5604
  var sourceVal = source[key];
5594
5605
  var targetVal = target[key];
5606
+
5595
5607
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
5596
5608
  // eslint-disable-next-line no-continue
5597
5609
  continue;
5598
5610
  }
5599
- if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
5611
+
5612
+ if (
5613
+ isObjectOrArrayOrFunction(targetVal) &&
5614
+ isObjectOrArrayOrFunction(sourceVal)
5615
+ ) {
5600
5616
  target[key] = _merge(targetVal, sourceVal);
5601
5617
  } else {
5602
5618
  target[key] = clone(sourceVal);
@@ -5624,24 +5640,24 @@
5624
5640
  if (!isObjectOrArrayOrFunction(target)) {
5625
5641
  target = {};
5626
5642
  }
5643
+
5627
5644
  for (var i = 1, l = arguments.length; i < l; i++) {
5628
5645
  var source = arguments[i];
5646
+
5629
5647
  if (isObjectOrArrayOrFunction(source)) {
5630
5648
  _merge(target, source);
5631
5649
  }
5632
5650
  }
5633
5651
  return target;
5634
5652
  }
5635
- module.exports = merge;
5636
5653
 
5637
- var merge$1 = /*#__PURE__*/Object.freeze({
5638
- __proto__: null
5639
- });
5654
+ var merge_1 = merge;
5640
5655
 
5641
5656
  // NOTE: this behaves like lodash/defaults, but doesn't mutate the target
5642
5657
  // it also preserve keys order
5643
5658
  var defaultsPure = function defaultsPure() {
5644
5659
  var sources = Array.prototype.slice.call(arguments);
5660
+
5645
5661
  return sources.reduceRight(function (acc, source) {
5646
5662
  Object.keys(Object(source)).forEach(function (key) {
5647
5663
  if (source[key] === undefined) {
@@ -5659,7 +5675,10 @@
5659
5675
 
5660
5676
  function intersection(arr1, arr2) {
5661
5677
  return arr1.filter(function (value, index) {
5662
- return arr2.indexOf(value) > -1 && arr1.indexOf(value) === index /* skips duplicates */;
5678
+ return (
5679
+ arr2.indexOf(value) > -1 &&
5680
+ arr1.indexOf(value) === index /* skips duplicates */
5681
+ );
5663
5682
  });
5664
5683
  }
5665
5684
 
@@ -5670,11 +5689,13 @@
5670
5689
  if (!Array.isArray(array)) {
5671
5690
  return undefined;
5672
5691
  }
5692
+
5673
5693
  for (var i = 0; i < array.length; i++) {
5674
5694
  if (comparator(array[i])) {
5675
5695
  return array[i];
5676
5696
  }
5677
5697
  }
5698
+
5678
5699
  return undefined;
5679
5700
  };
5680
5701
 
@@ -5686,8 +5707,12 @@
5686
5707
  } else if (Array.isArray(v)) {
5687
5708
  return v.map(valToNumber);
5688
5709
  }
5689
- throw new Error('The value should be a number, a parsable string or an array of those.');
5710
+
5711
+ throw new Error(
5712
+ 'The value should be a number, a parsable string or an array of those.'
5713
+ );
5690
5714
  }
5715
+
5691
5716
  var valToNumber_1 = valToNumber;
5692
5717
 
5693
5718
  // https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
@@ -5705,11 +5730,13 @@
5705
5730
  }
5706
5731
  return target;
5707
5732
  }
5733
+
5708
5734
  var omit$1 = _objectWithoutPropertiesLoose$1;
5709
5735
 
5710
5736
  function objectHasKeys(obj) {
5711
5737
  return obj && Object.keys(obj).length > 0;
5712
5738
  }
5739
+
5713
5740
  var objectHasKeys_1 = objectHasKeys;
5714
5741
 
5715
5742
  var isValidUserToken = function isValidUserToken(userToken) {
@@ -5733,6 +5760,8 @@
5733
5760
 
5734
5761
 
5735
5762
 
5763
+
5764
+
5736
5765
  var lib = {
5737
5766
  /**
5738
5767
  * Adds a refinement to a RefinementList
@@ -5745,10 +5774,17 @@
5745
5774
  if (lib.isRefined(refinementList, attribute, value)) {
5746
5775
  return refinementList;
5747
5776
  }
5777
+
5748
5778
  var valueAsString = '' + value;
5749
- var facetRefinement = !refinementList[attribute] ? [valueAsString] : refinementList[attribute].concat(valueAsString);
5779
+
5780
+ var facetRefinement = !refinementList[attribute]
5781
+ ? [valueAsString]
5782
+ : refinementList[attribute].concat(valueAsString);
5783
+
5750
5784
  var mod = {};
5785
+
5751
5786
  mod[attribute] = facetRefinement;
5787
+
5752
5788
  return defaultsPure({}, mod, refinementList);
5753
5789
  },
5754
5790
  /**
@@ -5760,7 +5796,11 @@
5760
5796
  * @param {string} [value] the value of the refinement
5761
5797
  * @return {RefinementList} a new and updated refinement lst
5762
5798
  */
5763
- removeRefinement: function removeRefinement(refinementList, attribute, value) {
5799
+ removeRefinement: function removeRefinement(
5800
+ refinementList,
5801
+ attribute,
5802
+ value
5803
+ ) {
5764
5804
  if (value === undefined) {
5765
5805
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
5766
5806
  // the form with a string will remove the attribute completely
@@ -5768,7 +5808,9 @@
5768
5808
  return attribute === f;
5769
5809
  });
5770
5810
  }
5811
+
5771
5812
  var valueAsString = '' + value;
5813
+
5772
5814
  return lib.clearRefinement(refinementList, function (v, f) {
5773
5815
  return attribute === f && valueAsString === v;
5774
5816
  });
@@ -5780,11 +5822,18 @@
5780
5822
  * @param {string} value the value of the refinement
5781
5823
  * @return {RefinementList} a new and updated list
5782
5824
  */
5783
- toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
5784
- if (value === undefined) throw new Error('toggleRefinement should be used with a value');
5825
+ toggleRefinement: function toggleRefinement(
5826
+ refinementList,
5827
+ attribute,
5828
+ value
5829
+ ) {
5830
+ if (value === undefined)
5831
+ throw new Error('toggleRefinement should be used with a value');
5832
+
5785
5833
  if (lib.isRefined(refinementList, attribute, value)) {
5786
5834
  return lib.removeRefinement(refinementList, attribute, value);
5787
5835
  }
5836
+
5788
5837
  return lib.addRefinement(refinementList, attribute, value);
5789
5838
  },
5790
5839
  /**
@@ -5798,7 +5847,11 @@
5798
5847
  * @param {string} [refinementType] optional parameter to give more context to the attribute function
5799
5848
  * @return {RefinementList} a new and updated refinement list
5800
5849
  */
5801
- clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
5850
+ clearRefinement: function clearRefinement(
5851
+ refinementList,
5852
+ attribute,
5853
+ refinementType
5854
+ ) {
5802
5855
  if (attribute === undefined) {
5803
5856
  // return the same object if the list is already empty
5804
5857
  // this is mainly for tests, as it doesn't have much impact on performance
@@ -5810,17 +5863,26 @@
5810
5863
  return omit$1(refinementList, [attribute]);
5811
5864
  } else if (typeof attribute === 'function') {
5812
5865
  var hasChanged = false;
5813
- var newRefinementList = Object.keys(refinementList).reduce(function (memo, key) {
5866
+
5867
+ var newRefinementList = Object.keys(refinementList).reduce(function (
5868
+ memo,
5869
+ key
5870
+ ) {
5814
5871
  var values = refinementList[key] || [];
5815
5872
  var facetList = values.filter(function (value) {
5816
5873
  return !attribute(value, key, refinementType);
5817
5874
  });
5875
+
5818
5876
  if (facetList.length !== values.length) {
5819
5877
  hasChanged = true;
5820
5878
  }
5879
+
5821
5880
  memo[key] = facetList;
5881
+
5822
5882
  return memo;
5823
- }, {});
5883
+ },
5884
+ {});
5885
+
5824
5886
  if (hasChanged) return newRefinementList;
5825
5887
  return refinementList;
5826
5888
  }
@@ -5839,14 +5901,20 @@
5839
5901
  * @return {boolean} true if the attribute is refined, false otherwise
5840
5902
  */
5841
5903
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
5842
- var containsRefinements = Boolean(refinementList[attribute]) && refinementList[attribute].length > 0;
5904
+ var containsRefinements =
5905
+ Boolean(refinementList[attribute]) &&
5906
+ refinementList[attribute].length > 0;
5907
+
5843
5908
  if (refinementValue === undefined || !containsRefinements) {
5844
5909
  return containsRefinements;
5845
5910
  }
5911
+
5846
5912
  var refinementValueAsString = '' + refinementValue;
5913
+
5847
5914
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
5848
- }
5915
+ },
5849
5916
  };
5917
+
5850
5918
  var RefinementList = lib;
5851
5919
 
5852
5920
  /**
@@ -5861,9 +5929,12 @@
5861
5929
  */
5862
5930
  function isEqualNumericRefinement(a, b) {
5863
5931
  if (Array.isArray(a) && Array.isArray(b)) {
5864
- return a.length === b.length && a.every(function (el, i) {
5865
- return isEqualNumericRefinement(b[i], el);
5866
- });
5932
+ return (
5933
+ a.length === b.length &&
5934
+ a.every(function (el, i) {
5935
+ return isEqualNumericRefinement(b[i], el);
5936
+ })
5937
+ );
5867
5938
  }
5868
5939
  return a === b;
5869
5940
  }
@@ -5930,10 +6001,15 @@
5930
6001
  }
5931
6002
  */
5932
6003
  function SearchParameters(newParameters) {
5933
- var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
6004
+ var params = newParameters
6005
+ ? SearchParameters._parseNumbers(newParameters)
6006
+ : {};
6007
+
5934
6008
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
5935
6009
  // eslint-disable-next-line no-console
5936
- console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
6010
+ console.warn(
6011
+ '[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}'
6012
+ );
5937
6013
  }
5938
6014
  /**
5939
6015
  * This attribute contains the list of all the conjunctive facets
@@ -6033,13 +6109,15 @@
6033
6109
  * be translated into the `facetFilters` attribute.
6034
6110
  * @member {Object.<string, SearchParameters.FacetList>}
6035
6111
  */
6036
- this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
6112
+ this.hierarchicalFacetsRefinements =
6113
+ params.hierarchicalFacetsRefinements || {};
6037
6114
 
6038
6115
  // eslint-disable-next-line consistent-this
6039
6116
  var self = this;
6040
6117
  Object.keys(params).forEach(function (paramName) {
6041
6118
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
6042
6119
  var isValueDefined = params[paramName] !== undefined;
6120
+
6043
6121
  if (!isKeyKnown && isValueDefined) {
6044
6122
  self[paramName] = params[paramName];
6045
6123
  }
@@ -6061,8 +6139,23 @@
6061
6139
  SearchParameters._parseNumbers = function (partialState) {
6062
6140
  // Do not parse numbers again in SearchParameters, they ought to be parsed already
6063
6141
  if (partialState instanceof SearchParameters) return partialState;
6142
+
6064
6143
  var numbers = {};
6065
- var numberKeys = ['aroundPrecision', 'aroundRadius', 'getRankingInfo', 'minWordSizefor2Typos', 'minWordSizefor1Typo', 'page', 'maxValuesPerFacet', 'distinct', 'minimumAroundRadius', 'hitsPerPage', 'minProximity'];
6144
+
6145
+ var numberKeys = [
6146
+ 'aroundPrecision',
6147
+ 'aroundRadius',
6148
+ 'getRankingInfo',
6149
+ 'minWordSizefor2Typos',
6150
+ 'minWordSizefor1Typo',
6151
+ 'page',
6152
+ 'maxValuesPerFacet',
6153
+ 'distinct',
6154
+ 'minimumAroundRadius',
6155
+ 'hitsPerPage',
6156
+ 'minProximity',
6157
+ ];
6158
+
6066
6159
  numberKeys.forEach(function (k) {
6067
6160
  var value = partialState[k];
6068
6161
  if (typeof value === 'string') {
@@ -6075,7 +6168,9 @@
6075
6168
  // there's two formats of insideBoundingBox, we need to parse
6076
6169
  // the one which is an array of float geo rectangles
6077
6170
  if (Array.isArray(partialState.insideBoundingBox)) {
6078
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (geoRect) {
6171
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
6172
+ geoRect
6173
+ ) {
6079
6174
  if (Array.isArray(geoRect)) {
6080
6175
  return geoRect.map(function (value) {
6081
6176
  return parseFloat(value);
@@ -6084,6 +6179,7 @@
6084
6179
  return geoRect;
6085
6180
  });
6086
6181
  }
6182
+
6087
6183
  if (partialState.numericRefinements) {
6088
6184
  var numericRefinements = {};
6089
6185
  Object.keys(partialState.numericRefinements).forEach(function (attribute) {
@@ -6109,7 +6205,8 @@
6109
6205
  });
6110
6206
  numbers.numericRefinements = numericRefinements;
6111
6207
  }
6112
- return merge$1({}, partialState, numbers);
6208
+
6209
+ return merge_1({}, partialState, numbers);
6113
6210
  };
6114
6211
 
6115
6212
  /**
@@ -6120,21 +6217,30 @@
6120
6217
  */
6121
6218
  SearchParameters.make = function makeSearchParameters(newParameters) {
6122
6219
  var instance = new SearchParameters(newParameters);
6220
+
6123
6221
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
6124
6222
  hierarchicalFacets.forEach(function (facet) {
6125
6223
  if (facet.rootPath) {
6126
6224
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
6127
- if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
6225
+
6226
+ if (
6227
+ currentRefinement.length > 0 &&
6228
+ currentRefinement[0].indexOf(facet.rootPath) !== 0
6229
+ ) {
6128
6230
  instance = instance.clearRefinements(facet.name);
6129
6231
  }
6130
6232
 
6131
6233
  // get it again in case it has been cleared
6132
6234
  currentRefinement = instance.getHierarchicalRefinement(facet.name);
6133
6235
  if (currentRefinement.length === 0) {
6134
- instance = instance.toggleHierarchicalFacetRefinement(facet.name, facet.rootPath);
6236
+ instance = instance.toggleHierarchicalFacetRefinement(
6237
+ facet.name,
6238
+ facet.rootPath
6239
+ );
6135
6240
  }
6136
6241
  }
6137
6242
  });
6243
+
6138
6244
  return instance;
6139
6245
  };
6140
6246
 
@@ -6146,22 +6252,51 @@
6146
6252
  */
6147
6253
  SearchParameters.validate = function (currentState, parameters) {
6148
6254
  var params = parameters || {};
6149
- if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
6150
- return new Error('[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' + 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
6255
+
6256
+ if (
6257
+ currentState.tagFilters &&
6258
+ params.tagRefinements &&
6259
+ params.tagRefinements.length > 0
6260
+ ) {
6261
+ return new Error(
6262
+ '[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
6263
+ 'an error, if it is really what you want, you should first clear the tags with clearTags method.'
6264
+ );
6151
6265
  }
6266
+
6152
6267
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
6153
- return new Error('[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' + 'an error, if it is not, you should first clear the tags with clearTags method.');
6268
+ return new Error(
6269
+ '[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
6270
+ 'an error, if it is not, you should first clear the tags with clearTags method.'
6271
+ );
6154
6272
  }
6155
- if (currentState.numericFilters && params.numericRefinements && objectHasKeys_1(params.numericRefinements)) {
6156
- return new Error("[Numeric filters] Can't switch from the advanced to the managed API. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
6273
+
6274
+ if (
6275
+ currentState.numericFilters &&
6276
+ params.numericRefinements &&
6277
+ objectHasKeys_1(params.numericRefinements)
6278
+ ) {
6279
+ return new Error(
6280
+ "[Numeric filters] Can't switch from the advanced to the managed API. It" +
6281
+ ' is probably an error, if this is really what you want, you have to first' +
6282
+ ' clear the numeric filters.'
6283
+ );
6157
6284
  }
6285
+
6158
6286
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
6159
- return new Error("[Numeric filters] Can't switch from the managed API to the advanced. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
6287
+ return new Error(
6288
+ "[Numeric filters] Can't switch from the managed API to the advanced. It" +
6289
+ ' is probably an error, if this is really what you want, you have to first' +
6290
+ ' clear the numeric filters.'
6291
+ );
6160
6292
  }
6293
+
6161
6294
  return null;
6162
6295
  };
6296
+
6163
6297
  SearchParameters.prototype = {
6164
6298
  constructor: SearchParameters,
6299
+
6165
6300
  /**
6166
6301
  * Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
6167
6302
  * @method
@@ -6174,12 +6309,35 @@
6174
6309
  clearRefinements: function clearRefinements(attribute) {
6175
6310
  var patch = {
6176
6311
  numericRefinements: this._clearNumericRefinements(attribute),
6177
- facetsRefinements: RefinementList.clearRefinement(this.facetsRefinements, attribute, 'conjunctiveFacet'),
6178
- facetsExcludes: RefinementList.clearRefinement(this.facetsExcludes, attribute, 'exclude'),
6179
- disjunctiveFacetsRefinements: RefinementList.clearRefinement(this.disjunctiveFacetsRefinements, attribute, 'disjunctiveFacet'),
6180
- hierarchicalFacetsRefinements: RefinementList.clearRefinement(this.hierarchicalFacetsRefinements, attribute, 'hierarchicalFacet')
6312
+ facetsRefinements: RefinementList.clearRefinement(
6313
+ this.facetsRefinements,
6314
+ attribute,
6315
+ 'conjunctiveFacet'
6316
+ ),
6317
+ facetsExcludes: RefinementList.clearRefinement(
6318
+ this.facetsExcludes,
6319
+ attribute,
6320
+ 'exclude'
6321
+ ),
6322
+ disjunctiveFacetsRefinements: RefinementList.clearRefinement(
6323
+ this.disjunctiveFacetsRefinements,
6324
+ attribute,
6325
+ 'disjunctiveFacet'
6326
+ ),
6327
+ hierarchicalFacetsRefinements: RefinementList.clearRefinement(
6328
+ this.hierarchicalFacetsRefinements,
6329
+ attribute,
6330
+ 'hierarchicalFacet'
6331
+ ),
6181
6332
  };
6182
- if (patch.numericRefinements === this.numericRefinements && patch.facetsRefinements === this.facetsRefinements && patch.facetsExcludes === this.facetsExcludes && patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements && patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements) {
6333
+ if (
6334
+ patch.numericRefinements === this.numericRefinements &&
6335
+ patch.facetsRefinements === this.facetsRefinements &&
6336
+ patch.facetsExcludes === this.facetsExcludes &&
6337
+ patch.disjunctiveFacetsRefinements ===
6338
+ this.disjunctiveFacetsRefinements &&
6339
+ patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
6340
+ ) {
6183
6341
  return this;
6184
6342
  }
6185
6343
  return this.setQueryParameters(patch);
@@ -6190,10 +6348,12 @@
6190
6348
  * @return {SearchParameters} new instance with tags cleared
6191
6349
  */
6192
6350
  clearTags: function clearTags() {
6193
- if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
6351
+ if (this.tagFilters === undefined && this.tagRefinements.length === 0)
6352
+ return this;
6353
+
6194
6354
  return this.setQueryParameters({
6195
6355
  tagFilters: undefined,
6196
- tagRefinements: []
6356
+ tagRefinements: [],
6197
6357
  });
6198
6358
  },
6199
6359
  /**
@@ -6204,8 +6364,9 @@
6204
6364
  */
6205
6365
  setIndex: function setIndex(index) {
6206
6366
  if (index === this.index) return this;
6367
+
6207
6368
  return this.setQueryParameters({
6208
- index: index
6369
+ index: index,
6209
6370
  });
6210
6371
  },
6211
6372
  /**
@@ -6216,8 +6377,9 @@
6216
6377
  */
6217
6378
  setQuery: function setQuery(newQuery) {
6218
6379
  if (newQuery === this.query) return this;
6380
+
6219
6381
  return this.setQueryParameters({
6220
- query: newQuery
6382
+ query: newQuery,
6221
6383
  });
6222
6384
  },
6223
6385
  /**
@@ -6228,8 +6390,9 @@
6228
6390
  */
6229
6391
  setPage: function setPage(newPage) {
6230
6392
  if (newPage === this.page) return this;
6393
+
6231
6394
  return this.setQueryParameters({
6232
- page: newPage
6395
+ page: newPage,
6233
6396
  });
6234
6397
  },
6235
6398
  /**
@@ -6241,7 +6404,7 @@
6241
6404
  */
6242
6405
  setFacets: function setFacets(facets) {
6243
6406
  return this.setQueryParameters({
6244
- facets: facets
6407
+ facets: facets,
6245
6408
  });
6246
6409
  },
6247
6410
  /**
@@ -6253,7 +6416,7 @@
6253
6416
  */
6254
6417
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
6255
6418
  return this.setQueryParameters({
6256
- disjunctiveFacets: facets
6419
+ disjunctiveFacets: facets,
6257
6420
  });
6258
6421
  },
6259
6422
  /**
@@ -6265,8 +6428,9 @@
6265
6428
  */
6266
6429
  setHitsPerPage: function setHitsPerPage(n) {
6267
6430
  if (this.hitsPerPage === n) return this;
6431
+
6268
6432
  return this.setQueryParameters({
6269
- hitsPerPage: n
6433
+ hitsPerPage: n,
6270
6434
  });
6271
6435
  },
6272
6436
  /**
@@ -6278,8 +6442,9 @@
6278
6442
  */
6279
6443
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
6280
6444
  if (this.typoTolerance === typoTolerance) return this;
6445
+
6281
6446
  return this.setQueryParameters({
6282
- typoTolerance: typoTolerance
6447
+ typoTolerance: typoTolerance,
6283
6448
  });
6284
6449
  },
6285
6450
  /**
@@ -6299,11 +6464,15 @@
6299
6464
  * state.addNumericRefinement('size', '=', 38);
6300
6465
  * state.addNumericRefinement('size', '=', 40);
6301
6466
  */
6302
- addNumericRefinement: function addNumericRefinement(attribute, operator, value) {
6467
+ addNumericRefinement: function (attribute, operator, value) {
6303
6468
  var val = valToNumber_1(value);
6469
+
6304
6470
  if (this.isNumericRefined(attribute, operator, val)) return this;
6305
- var mod = merge$1({}, this.numericRefinements);
6306
- mod[attribute] = merge$1({}, mod[attribute]);
6471
+
6472
+ var mod = merge_1({}, this.numericRefinements);
6473
+
6474
+ mod[attribute] = merge_1({}, mod[attribute]);
6475
+
6307
6476
  if (mod[attribute][operator]) {
6308
6477
  // Array copy
6309
6478
  mod[attribute][operator] = mod[attribute][operator].slice();
@@ -6312,8 +6481,9 @@
6312
6481
  } else {
6313
6482
  mod[attribute][operator] = [val];
6314
6483
  }
6484
+
6315
6485
  return this.setQueryParameters({
6316
- numericRefinements: mod
6486
+ numericRefinements: mod,
6317
6487
  });
6318
6488
  },
6319
6489
  /**
@@ -6321,7 +6491,7 @@
6321
6491
  * @param {string} facetName name of the attribute used for faceting
6322
6492
  * @return {string[]} list of refinements
6323
6493
  */
6324
- getConjunctiveRefinements: function getConjunctiveRefinements(facetName) {
6494
+ getConjunctiveRefinements: function (facetName) {
6325
6495
  if (!this.isConjunctiveFacet(facetName)) {
6326
6496
  return [];
6327
6497
  }
@@ -6332,7 +6502,7 @@
6332
6502
  * @param {string} facetName name of the attribute used for faceting
6333
6503
  * @return {string[]} list of refinements
6334
6504
  */
6335
- getDisjunctiveRefinements: function getDisjunctiveRefinements(facetName) {
6505
+ getDisjunctiveRefinements: function (facetName) {
6336
6506
  if (!this.isDisjunctiveFacet(facetName)) {
6337
6507
  return [];
6338
6508
  }
@@ -6343,7 +6513,7 @@
6343
6513
  * @param {string} facetName name of the attribute used for faceting
6344
6514
  * @return {string[]} list of refinements
6345
6515
  */
6346
- getHierarchicalRefinement: function getHierarchicalRefinement(facetName) {
6516
+ getHierarchicalRefinement: function (facetName) {
6347
6517
  // we send an array but we currently do not support multiple
6348
6518
  // hierarchicalRefinements for a hierarchicalFacet
6349
6519
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -6353,12 +6523,13 @@
6353
6523
  * @param {string} facetName name of the attribute used for faceting
6354
6524
  * @return {string[]} list of refinements
6355
6525
  */
6356
- getExcludeRefinements: function getExcludeRefinements(facetName) {
6526
+ getExcludeRefinements: function (facetName) {
6357
6527
  if (!this.isConjunctiveFacet(facetName)) {
6358
6528
  return [];
6359
6529
  }
6360
6530
  return this.facetsExcludes[facetName] || [];
6361
6531
  },
6532
+
6362
6533
  /**
6363
6534
  * Remove all the numeric filter for a given (attribute, operator)
6364
6535
  * @method
@@ -6367,30 +6538,41 @@
6367
6538
  * @param {number} [number] the value to be removed
6368
6539
  * @return {SearchParameters} new instance
6369
6540
  */
6370
- removeNumericRefinement: function removeNumericRefinement(attribute, operator, number) {
6541
+ removeNumericRefinement: function (attribute, operator, number) {
6371
6542
  var paramValue = number;
6372
6543
  if (paramValue !== undefined) {
6373
6544
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
6374
6545
  return this;
6375
6546
  }
6376
6547
  return this.setQueryParameters({
6377
- numericRefinements: this._clearNumericRefinements(function (value, key) {
6378
- return key === attribute && value.op === operator && isEqualNumericRefinement(value.val, valToNumber_1(paramValue));
6379
- })
6548
+ numericRefinements: this._clearNumericRefinements(function (
6549
+ value,
6550
+ key
6551
+ ) {
6552
+ return (
6553
+ key === attribute &&
6554
+ value.op === operator &&
6555
+ isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
6556
+ );
6557
+ }),
6380
6558
  });
6381
6559
  } else if (operator !== undefined) {
6382
6560
  if (!this.isNumericRefined(attribute, operator)) return this;
6383
6561
  return this.setQueryParameters({
6384
- numericRefinements: this._clearNumericRefinements(function (value, key) {
6562
+ numericRefinements: this._clearNumericRefinements(function (
6563
+ value,
6564
+ key
6565
+ ) {
6385
6566
  return key === attribute && value.op === operator;
6386
- })
6567
+ }),
6387
6568
  });
6388
6569
  }
6570
+
6389
6571
  if (!this.isNumericRefined(attribute)) return this;
6390
6572
  return this.setQueryParameters({
6391
6573
  numericRefinements: this._clearNumericRefinements(function (value, key) {
6392
6574
  return key === attribute;
6393
- })
6575
+ }),
6394
6576
  });
6395
6577
  },
6396
6578
  /**
@@ -6398,7 +6580,7 @@
6398
6580
  * @param {string} facetName name of the attribute used for faceting
6399
6581
  * @return {SearchParameters.OperatorList} list of refinements
6400
6582
  */
6401
- getNumericRefinements: function getNumericRefinements(facetName) {
6583
+ getNumericRefinements: function (facetName) {
6402
6584
  return this.numericRefinements[facetName] || {};
6403
6585
  },
6404
6586
  /**
@@ -6407,8 +6589,11 @@
6407
6589
  * @param {string} operator operator applied on the refined values
6408
6590
  * @return {Array.<number|number[]>} refined values
6409
6591
  */
6410
- getNumericRefinement: function getNumericRefinement(attribute, operator) {
6411
- return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
6592
+ getNumericRefinement: function (attribute, operator) {
6593
+ return (
6594
+ this.numericRefinements[attribute] &&
6595
+ this.numericRefinements[attribute][operator]
6596
+ );
6412
6597
  },
6413
6598
  /**
6414
6599
  * Clear numeric filters.
@@ -6431,28 +6616,36 @@
6431
6616
  } else if (typeof attribute === 'function') {
6432
6617
  var hasChanged = false;
6433
6618
  var numericRefinements = this.numericRefinements;
6434
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function (memo, key) {
6435
- var operators = numericRefinements[key];
6436
- var operatorList = {};
6437
- operators = operators || {};
6438
- Object.keys(operators).forEach(function (operator) {
6439
- var values = operators[operator] || [];
6440
- var outValues = [];
6441
- values.forEach(function (value) {
6442
- var predicateResult = attribute({
6443
- val: value,
6444
- op: operator
6445
- }, key, 'numeric');
6446
- if (!predicateResult) outValues.push(value);
6619
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(
6620
+ function (memo, key) {
6621
+ var operators = numericRefinements[key];
6622
+ var operatorList = {};
6623
+
6624
+ operators = operators || {};
6625
+ Object.keys(operators).forEach(function (operator) {
6626
+ var values = operators[operator] || [];
6627
+ var outValues = [];
6628
+ values.forEach(function (value) {
6629
+ var predicateResult = attribute(
6630
+ { val: value, op: operator },
6631
+ key,
6632
+ 'numeric'
6633
+ );
6634
+ if (!predicateResult) outValues.push(value);
6635
+ });
6636
+ if (outValues.length !== values.length) {
6637
+ hasChanged = true;
6638
+ }
6639
+ operatorList[operator] = outValues;
6447
6640
  });
6448
- if (outValues.length !== values.length) {
6449
- hasChanged = true;
6450
- }
6451
- operatorList[operator] = outValues;
6452
- });
6453
- memo[key] = operatorList;
6454
- return memo;
6455
- }, {});
6641
+
6642
+ memo[key] = operatorList;
6643
+
6644
+ return memo;
6645
+ },
6646
+ {}
6647
+ );
6648
+
6456
6649
  if (hasChanged) return newNumericRefinements;
6457
6650
  return this.numericRefinements;
6458
6651
  }
@@ -6472,8 +6665,9 @@
6472
6665
  if (this.isConjunctiveFacet(facet)) {
6473
6666
  return this;
6474
6667
  }
6668
+
6475
6669
  return this.setQueryParameters({
6476
- facets: this.facets.concat([facet])
6670
+ facets: this.facets.concat([facet]),
6477
6671
  });
6478
6672
  },
6479
6673
  /**
@@ -6487,8 +6681,9 @@
6487
6681
  if (this.isDisjunctiveFacet(facet)) {
6488
6682
  return this;
6489
6683
  }
6684
+
6490
6685
  return this.setQueryParameters({
6491
- disjunctiveFacets: this.disjunctiveFacets.concat([facet])
6686
+ disjunctiveFacets: this.disjunctiveFacets.concat([facet]),
6492
6687
  });
6493
6688
  },
6494
6689
  /**
@@ -6501,10 +6696,15 @@
6501
6696
  */
6502
6697
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
6503
6698
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
6504
- throw new Error('Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
6699
+ throw new Error(
6700
+ 'Cannot declare two hierarchical facets with the same name: `' +
6701
+ hierarchicalFacet.name +
6702
+ '`'
6703
+ );
6505
6704
  }
6705
+
6506
6706
  return this.setQueryParameters({
6507
- hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
6707
+ hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet]),
6508
6708
  });
6509
6709
  },
6510
6710
  /**
@@ -6516,11 +6716,20 @@
6516
6716
  */
6517
6717
  addFacetRefinement: function addFacetRefinement(facet, value) {
6518
6718
  if (!this.isConjunctiveFacet(facet)) {
6519
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6719
+ throw new Error(
6720
+ facet +
6721
+ ' is not defined in the facets attribute of the helper configuration'
6722
+ );
6520
6723
  }
6521
- if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
6724
+ if (RefinementList.isRefined(this.facetsRefinements, facet, value))
6725
+ return this;
6726
+
6522
6727
  return this.setQueryParameters({
6523
- facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
6728
+ facetsRefinements: RefinementList.addRefinement(
6729
+ this.facetsRefinements,
6730
+ facet,
6731
+ value
6732
+ ),
6524
6733
  });
6525
6734
  },
6526
6735
  /**
@@ -6532,11 +6741,20 @@
6532
6741
  */
6533
6742
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
6534
6743
  if (!this.isConjunctiveFacet(facet)) {
6535
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6744
+ throw new Error(
6745
+ facet +
6746
+ ' is not defined in the facets attribute of the helper configuration'
6747
+ );
6536
6748
  }
6537
- if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
6749
+ if (RefinementList.isRefined(this.facetsExcludes, facet, value))
6750
+ return this;
6751
+
6538
6752
  return this.setQueryParameters({
6539
- facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
6753
+ facetsExcludes: RefinementList.addRefinement(
6754
+ this.facetsExcludes,
6755
+ facet,
6756
+ value
6757
+ ),
6540
6758
  });
6541
6759
  },
6542
6760
  /**
@@ -6546,13 +6764,28 @@
6546
6764
  * @param {string} value value of the attribute (will be converted to string)
6547
6765
  * @return {SearchParameters} new instance
6548
6766
  */
6549
- addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
6767
+ addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
6768
+ facet,
6769
+ value
6770
+ ) {
6550
6771
  if (!this.isDisjunctiveFacet(facet)) {
6551
- throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6772
+ throw new Error(
6773
+ facet +
6774
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
6775
+ );
6552
6776
  }
6553
- if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
6777
+
6778
+ if (
6779
+ RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
6780
+ )
6781
+ return this;
6782
+
6554
6783
  return this.setQueryParameters({
6555
- disjunctiveFacetsRefinements: RefinementList.addRefinement(this.disjunctiveFacetsRefinements, facet, value)
6784
+ disjunctiveFacetsRefinements: RefinementList.addRefinement(
6785
+ this.disjunctiveFacetsRefinements,
6786
+ facet,
6787
+ value
6788
+ ),
6556
6789
  });
6557
6790
  },
6558
6791
  /**
@@ -6562,9 +6795,11 @@
6562
6795
  */
6563
6796
  addTagRefinement: function addTagRefinement(tag) {
6564
6797
  if (this.isTagRefined(tag)) return this;
6798
+
6565
6799
  var modification = {
6566
- tagRefinements: this.tagRefinements.concat(tag)
6800
+ tagRefinements: this.tagRefinements.concat(tag),
6567
6801
  };
6802
+
6568
6803
  return this.setQueryParameters(modification);
6569
6804
  },
6570
6805
  /**
@@ -6578,10 +6813,11 @@
6578
6813
  if (!this.isConjunctiveFacet(facet)) {
6579
6814
  return this;
6580
6815
  }
6816
+
6581
6817
  return this.clearRefinements(facet).setQueryParameters({
6582
6818
  facets: this.facets.filter(function (f) {
6583
6819
  return f !== facet;
6584
- })
6820
+ }),
6585
6821
  });
6586
6822
  },
6587
6823
  /**
@@ -6595,10 +6831,11 @@
6595
6831
  if (!this.isDisjunctiveFacet(facet)) {
6596
6832
  return this;
6597
6833
  }
6834
+
6598
6835
  return this.clearRefinements(facet).setQueryParameters({
6599
6836
  disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
6600
6837
  return f !== facet;
6601
- })
6838
+ }),
6602
6839
  });
6603
6840
  },
6604
6841
  /**
@@ -6612,10 +6849,11 @@
6612
6849
  if (!this.isHierarchicalFacet(facet)) {
6613
6850
  return this;
6614
6851
  }
6852
+
6615
6853
  return this.clearRefinements(facet).setQueryParameters({
6616
6854
  hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
6617
6855
  return f.name !== facet;
6618
- })
6856
+ }),
6619
6857
  });
6620
6858
  },
6621
6859
  /**
@@ -6629,11 +6867,20 @@
6629
6867
  */
6630
6868
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
6631
6869
  if (!this.isConjunctiveFacet(facet)) {
6632
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6870
+ throw new Error(
6871
+ facet +
6872
+ ' is not defined in the facets attribute of the helper configuration'
6873
+ );
6633
6874
  }
6634
- if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
6875
+ if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
6876
+ return this;
6877
+
6635
6878
  return this.setQueryParameters({
6636
- facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
6879
+ facetsRefinements: RefinementList.removeRefinement(
6880
+ this.facetsRefinements,
6881
+ facet,
6882
+ value
6883
+ ),
6637
6884
  });
6638
6885
  },
6639
6886
  /**
@@ -6645,11 +6892,20 @@
6645
6892
  */
6646
6893
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
6647
6894
  if (!this.isConjunctiveFacet(facet)) {
6648
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6895
+ throw new Error(
6896
+ facet +
6897
+ ' is not defined in the facets attribute of the helper configuration'
6898
+ );
6649
6899
  }
6650
- if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
6900
+ if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
6901
+ return this;
6902
+
6651
6903
  return this.setQueryParameters({
6652
- facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
6904
+ facetsExcludes: RefinementList.removeRefinement(
6905
+ this.facetsExcludes,
6906
+ facet,
6907
+ value
6908
+ ),
6653
6909
  });
6654
6910
  },
6655
6911
  /**
@@ -6659,13 +6915,27 @@
6659
6915
  * @param {string} value value used to filter
6660
6916
  * @return {SearchParameters} new instance
6661
6917
  */
6662
- removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
6918
+ removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
6919
+ facet,
6920
+ value
6921
+ ) {
6663
6922
  if (!this.isDisjunctiveFacet(facet)) {
6664
- throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6923
+ throw new Error(
6924
+ facet +
6925
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
6926
+ );
6665
6927
  }
6666
- if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
6928
+ if (
6929
+ !RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
6930
+ )
6931
+ return this;
6932
+
6667
6933
  return this.setQueryParameters({
6668
- disjunctiveFacetsRefinements: RefinementList.removeRefinement(this.disjunctiveFacetsRefinements, facet, value)
6934
+ disjunctiveFacetsRefinements: RefinementList.removeRefinement(
6935
+ this.disjunctiveFacetsRefinements,
6936
+ facet,
6937
+ value
6938
+ ),
6669
6939
  });
6670
6940
  },
6671
6941
  /**
@@ -6676,11 +6946,13 @@
6676
6946
  */
6677
6947
  removeTagRefinement: function removeTagRefinement(tag) {
6678
6948
  if (!this.isTagRefined(tag)) return this;
6949
+
6679
6950
  var modification = {
6680
6951
  tagRefinements: this.tagRefinements.filter(function (t) {
6681
6952
  return t !== tag;
6682
- })
6953
+ }),
6683
6954
  };
6955
+
6684
6956
  return this.setQueryParameters(modification);
6685
6957
  },
6686
6958
  /**
@@ -6711,7 +6983,12 @@
6711
6983
  } else if (this.isDisjunctiveFacet(facet)) {
6712
6984
  return this.toggleDisjunctiveFacetRefinement(facet, value);
6713
6985
  }
6714
- throw new Error('Cannot refine the undeclared facet ' + facet + '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
6986
+
6987
+ throw new Error(
6988
+ 'Cannot refine the undeclared facet ' +
6989
+ facet +
6990
+ '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets'
6991
+ );
6715
6992
  },
6716
6993
  /**
6717
6994
  * Switch the refinement applied over a facet/value
@@ -6720,12 +6997,23 @@
6720
6997
  * @param {value} value value used for filtering
6721
6998
  * @return {SearchParameters} new instance
6722
6999
  */
6723
- toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
7000
+ toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
7001
+ facet,
7002
+ value
7003
+ ) {
6724
7004
  if (!this.isConjunctiveFacet(facet)) {
6725
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
7005
+ throw new Error(
7006
+ facet +
7007
+ ' is not defined in the facets attribute of the helper configuration'
7008
+ );
6726
7009
  }
7010
+
6727
7011
  return this.setQueryParameters({
6728
- facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
7012
+ facetsRefinements: RefinementList.toggleRefinement(
7013
+ this.facetsRefinements,
7014
+ facet,
7015
+ value
7016
+ ),
6729
7017
  });
6730
7018
  },
6731
7019
  /**
@@ -6735,12 +7023,23 @@
6735
7023
  * @param {value} value value used for filtering
6736
7024
  * @return {SearchParameters} new instance
6737
7025
  */
6738
- toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
7026
+ toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
7027
+ facet,
7028
+ value
7029
+ ) {
6739
7030
  if (!this.isConjunctiveFacet(facet)) {
6740
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
7031
+ throw new Error(
7032
+ facet +
7033
+ ' is not defined in the facets attribute of the helper configuration'
7034
+ );
6741
7035
  }
7036
+
6742
7037
  return this.setQueryParameters({
6743
- facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
7038
+ facetsExcludes: RefinementList.toggleRefinement(
7039
+ this.facetsExcludes,
7040
+ facet,
7041
+ value
7042
+ ),
6744
7043
  });
6745
7044
  },
6746
7045
  /**
@@ -6750,12 +7049,23 @@
6750
7049
  * @param {value} value value used for filtering
6751
7050
  * @return {SearchParameters} new instance
6752
7051
  */
6753
- toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
7052
+ toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
7053
+ facet,
7054
+ value
7055
+ ) {
6754
7056
  if (!this.isDisjunctiveFacet(facet)) {
6755
- throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
7057
+ throw new Error(
7058
+ facet +
7059
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
7060
+ );
6756
7061
  }
7062
+
6757
7063
  return this.setQueryParameters({
6758
- disjunctiveFacetsRefinements: RefinementList.toggleRefinement(this.disjunctiveFacetsRefinements, facet, value)
7064
+ disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
7065
+ this.disjunctiveFacetsRefinements,
7066
+ facet,
7067
+ value
7068
+ ),
6759
7069
  });
6760
7070
  },
6761
7071
  /**
@@ -6765,21 +7075,37 @@
6765
7075
  * @param {value} value value used for filtering
6766
7076
  * @return {SearchParameters} new instance
6767
7077
  */
6768
- toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
7078
+ toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
7079
+ facet,
7080
+ value
7081
+ ) {
6769
7082
  if (!this.isHierarchicalFacet(facet)) {
6770
- throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
7083
+ throw new Error(
7084
+ facet +
7085
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration'
7086
+ );
6771
7087
  }
6772
- var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
7088
+
7089
+ var separator = this._getHierarchicalFacetSeparator(
7090
+ this.getHierarchicalFacetByName(facet)
7091
+ );
7092
+
6773
7093
  var mod = {};
6774
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined && this.hierarchicalFacetsRefinements[facet].length > 0 && (
6775
- // remove current refinement:
6776
- // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
6777
- this.hierarchicalFacetsRefinements[facet][0] === value ||
6778
- // remove a parent refinement of the current refinement:
6779
- // - refinement was 'beer > IPA > Flying dog'
6780
- // - call is toggleRefine('beer > IPA')
6781
- // - refinement should be `beer`
6782
- this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0);
7094
+
7095
+ var upOneOrMultipleLevel =
7096
+ this.hierarchicalFacetsRefinements[facet] !== undefined &&
7097
+ this.hierarchicalFacetsRefinements[facet].length > 0 &&
7098
+ // remove current refinement:
7099
+ // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
7100
+ (this.hierarchicalFacetsRefinements[facet][0] === value ||
7101
+ // remove a parent refinement of the current refinement:
7102
+ // - refinement was 'beer > IPA > Flying dog'
7103
+ // - call is toggleRefine('beer > IPA')
7104
+ // - refinement should be `beer`
7105
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(
7106
+ value + separator
7107
+ ) === 0);
7108
+
6783
7109
  if (upOneOrMultipleLevel) {
6784
7110
  if (value.indexOf(separator) === -1) {
6785
7111
  // go back to root level
@@ -6790,10 +7116,16 @@
6790
7116
  } else {
6791
7117
  mod[facet] = [value];
6792
7118
  }
7119
+
6793
7120
  return this.setQueryParameters({
6794
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
7121
+ hierarchicalFacetsRefinements: defaultsPure(
7122
+ {},
7123
+ mod,
7124
+ this.hierarchicalFacetsRefinements
7125
+ ),
6795
7126
  });
6796
7127
  },
7128
+
6797
7129
  /**
6798
7130
  * Adds a refinement on a hierarchical facet.
6799
7131
  * @param {string} facet the facet name
@@ -6801,33 +7133,45 @@
6801
7133
  * @return {SearchParameter} the new state
6802
7134
  * @throws Error if the facet is not defined or if the facet is refined
6803
7135
  */
6804
- addHierarchicalFacetRefinement: function addHierarchicalFacetRefinement(facet, path) {
7136
+ addHierarchicalFacetRefinement: function (facet, path) {
6805
7137
  if (this.isHierarchicalFacetRefined(facet)) {
6806
7138
  throw new Error(facet + ' is already refined.');
6807
7139
  }
6808
7140
  if (!this.isHierarchicalFacet(facet)) {
6809
- throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration.');
7141
+ throw new Error(
7142
+ facet +
7143
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration.'
7144
+ );
6810
7145
  }
6811
7146
  var mod = {};
6812
7147
  mod[facet] = [path];
6813
7148
  return this.setQueryParameters({
6814
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
7149
+ hierarchicalFacetsRefinements: defaultsPure(
7150
+ {},
7151
+ mod,
7152
+ this.hierarchicalFacetsRefinements
7153
+ ),
6815
7154
  });
6816
7155
  },
7156
+
6817
7157
  /**
6818
7158
  * Removes the refinement set on a hierarchical facet.
6819
7159
  * @param {string} facet the facet name
6820
7160
  * @return {SearchParameter} the new state
6821
7161
  * @throws Error if the facet is not defined or if the facet is not refined
6822
7162
  */
6823
- removeHierarchicalFacetRefinement: function removeHierarchicalFacetRefinement(facet) {
7163
+ removeHierarchicalFacetRefinement: function (facet) {
6824
7164
  if (!this.isHierarchicalFacetRefined(facet)) {
6825
7165
  return this;
6826
7166
  }
6827
7167
  var mod = {};
6828
7168
  mod[facet] = [];
6829
7169
  return this.setQueryParameters({
6830
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
7170
+ hierarchicalFacetsRefinements: defaultsPure(
7171
+ {},
7172
+ mod,
7173
+ this.hierarchicalFacetsRefinements
7174
+ ),
6831
7175
  });
6832
7176
  },
6833
7177
  /**
@@ -6840,6 +7184,7 @@
6840
7184
  if (this.isTagRefined(tag)) {
6841
7185
  return this.removeTagRefinement(tag);
6842
7186
  }
7187
+
6843
7188
  return this.addTagRefinement(tag);
6844
7189
  },
6845
7190
  /**
@@ -6848,7 +7193,7 @@
6848
7193
  * @param {string} facet facet name to test
6849
7194
  * @return {boolean} true if facet is a disjunctive facet
6850
7195
  */
6851
- isDisjunctiveFacet: function isDisjunctiveFacet(facet) {
7196
+ isDisjunctiveFacet: function (facet) {
6852
7197
  return this.disjunctiveFacets.indexOf(facet) > -1;
6853
7198
  },
6854
7199
  /**
@@ -6857,7 +7202,7 @@
6857
7202
  * @param {string} facetName facet name to test
6858
7203
  * @return {boolean} true if facetName is a hierarchical facet
6859
7204
  */
6860
- isHierarchicalFacet: function isHierarchicalFacet(facetName) {
7205
+ isHierarchicalFacet: function (facetName) {
6861
7206
  return this.getHierarchicalFacetByName(facetName) !== undefined;
6862
7207
  },
6863
7208
  /**
@@ -6866,7 +7211,7 @@
6866
7211
  * @param {string} facet facet name to test
6867
7212
  * @return {boolean} true if facet is a conjunctive facet
6868
7213
  */
6869
- isConjunctiveFacet: function isConjunctiveFacet(facet) {
7214
+ isConjunctiveFacet: function (facet) {
6870
7215
  return this.facets.indexOf(facet) > -1;
6871
7216
  },
6872
7217
  /**
@@ -6913,7 +7258,11 @@
6913
7258
  if (!this.isDisjunctiveFacet(facet)) {
6914
7259
  return false;
6915
7260
  }
6916
- return RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value);
7261
+ return RefinementList.isRefined(
7262
+ this.disjunctiveFacetsRefinements,
7263
+ facet,
7264
+ value
7265
+ );
6917
7266
  },
6918
7267
  /**
6919
7268
  * Returns true if the facet contains a refinement, or if a value passed is a
@@ -6924,14 +7273,20 @@
6924
7273
  * if there is one, otherwise will test if the facet contains any refinement
6925
7274
  * @return {boolean} true if the facet is refined
6926
7275
  */
6927
- isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
7276
+ isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
7277
+ facet,
7278
+ value
7279
+ ) {
6928
7280
  if (!this.isHierarchicalFacet(facet)) {
6929
7281
  return false;
6930
7282
  }
7283
+
6931
7284
  var refinements = this.getHierarchicalRefinement(facet);
7285
+
6932
7286
  if (!value) {
6933
7287
  return refinements.length > 0;
6934
7288
  }
7289
+
6935
7290
  return refinements.indexOf(value) !== -1;
6936
7291
  },
6937
7292
  /**
@@ -6948,12 +7303,20 @@
6948
7303
  if (value === undefined && operator === undefined) {
6949
7304
  return Boolean(this.numericRefinements[attribute]);
6950
7305
  }
6951
- var isOperatorDefined = this.numericRefinements[attribute] && this.numericRefinements[attribute][operator] !== undefined;
7306
+
7307
+ var isOperatorDefined =
7308
+ this.numericRefinements[attribute] &&
7309
+ this.numericRefinements[attribute][operator] !== undefined;
7310
+
6952
7311
  if (value === undefined || !isOperatorDefined) {
6953
7312
  return isOperatorDefined;
6954
7313
  }
7314
+
6955
7315
  var parsedValue = valToNumber_1(value);
6956
- var isAttributeValueDefined = findArray(this.numericRefinements[attribute][operator], parsedValue) !== undefined;
7316
+ var isAttributeValueDefined =
7317
+ findArray(this.numericRefinements[attribute][operator], parsedValue) !==
7318
+ undefined;
7319
+
6957
7320
  return isOperatorDefined && isAttributeValueDefined;
6958
7321
  },
6959
7322
  /**
@@ -6977,12 +7340,19 @@
6977
7340
  var self = this;
6978
7341
 
6979
7342
  // attributes used for numeric filter can also be disjunctive
6980
- var disjunctiveNumericRefinedFacets = intersection_1(Object.keys(this.numericRefinements).filter(function (facet) {
6981
- return Object.keys(self.numericRefinements[facet]).length > 0;
6982
- }), this.disjunctiveFacets);
6983
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function (facet) {
6984
- return self.disjunctiveFacetsRefinements[facet].length > 0;
6985
- }).concat(disjunctiveNumericRefinedFacets).concat(this.getRefinedHierarchicalFacets());
7343
+ var disjunctiveNumericRefinedFacets = intersection_1(
7344
+ Object.keys(this.numericRefinements).filter(function (facet) {
7345
+ return Object.keys(self.numericRefinements[facet]).length > 0;
7346
+ }),
7347
+ this.disjunctiveFacets
7348
+ );
7349
+
7350
+ return Object.keys(this.disjunctiveFacetsRefinements)
7351
+ .filter(function (facet) {
7352
+ return self.disjunctiveFacetsRefinements[facet].length > 0;
7353
+ })
7354
+ .concat(disjunctiveNumericRefinedFacets)
7355
+ .concat(this.getRefinedHierarchicalFacets());
6986
7356
  },
6987
7357
  /**
6988
7358
  * Returns the list of all disjunctive facets refined
@@ -6995,38 +7365,61 @@
6995
7365
  // eslint-disable-next-line consistent-this
6996
7366
  var self = this;
6997
7367
  return intersection_1(
6998
- // enforce the order between the two arrays,
6999
- // so that refinement name index === hierarchical facet index
7000
- this.hierarchicalFacets.map(function (facet) {
7001
- return facet.name;
7002
- }), Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
7003
- return self.hierarchicalFacetsRefinements[facet].length > 0;
7004
- }));
7368
+ // enforce the order between the two arrays,
7369
+ // so that refinement name index === hierarchical facet index
7370
+ this.hierarchicalFacets.map(function (facet) {
7371
+ return facet.name;
7372
+ }),
7373
+ Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
7374
+ return self.hierarchicalFacetsRefinements[facet].length > 0;
7375
+ })
7376
+ );
7005
7377
  },
7006
7378
  /**
7007
7379
  * Returned the list of all disjunctive facets not refined
7008
7380
  * @method
7009
7381
  * @return {string[]} returns the list of facets that are not refined
7010
7382
  */
7011
- getUnrefinedDisjunctiveFacets: function getUnrefinedDisjunctiveFacets() {
7383
+ getUnrefinedDisjunctiveFacets: function () {
7012
7384
  var refinedFacets = this.getRefinedDisjunctiveFacets();
7385
+
7013
7386
  return this.disjunctiveFacets.filter(function (f) {
7014
7387
  return refinedFacets.indexOf(f) === -1;
7015
7388
  });
7016
7389
  },
7017
- managedParameters: ['index', 'facets', 'disjunctiveFacets', 'facetsRefinements', 'hierarchicalFacets', 'facetsExcludes', 'disjunctiveFacetsRefinements', 'numericRefinements', 'tagRefinements', 'hierarchicalFacetsRefinements'],
7390
+
7391
+ managedParameters: [
7392
+ 'index',
7393
+
7394
+ 'facets',
7395
+ 'disjunctiveFacets',
7396
+ 'facetsRefinements',
7397
+ 'hierarchicalFacets',
7398
+ 'facetsExcludes',
7399
+
7400
+ 'disjunctiveFacetsRefinements',
7401
+ 'numericRefinements',
7402
+ 'tagRefinements',
7403
+ 'hierarchicalFacetsRefinements',
7404
+ ],
7405
+
7018
7406
  getQueryParams: function getQueryParams() {
7019
7407
  var managedParameters = this.managedParameters;
7408
+
7020
7409
  var queryParams = {};
7021
7410
 
7022
7411
  // eslint-disable-next-line consistent-this
7023
7412
  var self = this;
7024
7413
  Object.keys(this).forEach(function (paramName) {
7025
7414
  var paramValue = self[paramName];
7026
- if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
7415
+ if (
7416
+ managedParameters.indexOf(paramName) === -1 &&
7417
+ paramValue !== undefined
7418
+ ) {
7027
7419
  queryParams[paramName] = paramValue;
7028
7420
  }
7029
7421
  });
7422
+
7030
7423
  return queryParams;
7031
7424
  },
7032
7425
  /**
@@ -7041,8 +7434,11 @@
7041
7434
  */
7042
7435
  setQueryParameter: function setParameter(parameter, value) {
7043
7436
  if (this[parameter] === value) return this;
7437
+
7044
7438
  var modification = {};
7439
+
7045
7440
  modification[parameter] = value;
7441
+
7046
7442
  return this.setQueryParameters(modification);
7047
7443
  },
7048
7444
  /**
@@ -7053,7 +7449,9 @@
7053
7449
  */
7054
7450
  setQueryParameters: function setQueryParameters(params) {
7055
7451
  if (!params) return this;
7452
+
7056
7453
  var error = SearchParameters.validate(this, params);
7454
+
7057
7455
  if (error) {
7058
7456
  throw error;
7059
7457
  }
@@ -7065,99 +7463,121 @@
7065
7463
  acc[key] = self[key];
7066
7464
  return acc;
7067
7465
  }, {});
7068
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (previous, key) {
7466
+
7467
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (
7468
+ previous,
7469
+ key
7470
+ ) {
7069
7471
  var isPreviousValueDefined = previous[key] !== undefined;
7070
7472
  var isNextValueDefined = nextWithNumbers[key] !== undefined;
7473
+
7071
7474
  if (isPreviousValueDefined && !isNextValueDefined) {
7072
7475
  return omit$1(previous, [key]);
7073
7476
  }
7477
+
7074
7478
  if (isNextValueDefined) {
7075
7479
  previous[key] = nextWithNumbers[key];
7076
7480
  }
7481
+
7077
7482
  return previous;
7078
- }, previousPlainObject);
7483
+ },
7484
+ previousPlainObject);
7485
+
7079
7486
  return new this.constructor(nextPlainObject);
7080
7487
  },
7488
+
7081
7489
  /**
7082
7490
  * Returns a new instance with the page reset. Two scenarios possible:
7083
7491
  * the page is omitted -> return the given instance
7084
7492
  * the page is set -> return a new instance with a page of 0
7085
7493
  * @return {SearchParameters} a new updated instance
7086
7494
  */
7087
- resetPage: function resetPage() {
7495
+ resetPage: function () {
7088
7496
  if (this.page === undefined) {
7089
7497
  return this;
7090
7498
  }
7499
+
7091
7500
  return this.setPage(0);
7092
7501
  },
7502
+
7093
7503
  /**
7094
7504
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
7095
7505
  * @param {object} hierarchicalFacet the hierarchicalFacet object
7096
7506
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
7097
7507
  */
7098
- _getHierarchicalFacetSortBy: function _getHierarchicalFacetSortBy(hierarchicalFacet) {
7508
+ _getHierarchicalFacetSortBy: function (hierarchicalFacet) {
7099
7509
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
7100
7510
  },
7511
+
7101
7512
  /**
7102
7513
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
7103
7514
  * @private
7104
7515
  * @param {object} hierarchicalFacet the hierarchicalFacet object
7105
7516
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
7106
7517
  */
7107
- _getHierarchicalFacetSeparator: function _getHierarchicalFacetSeparator(hierarchicalFacet) {
7518
+ _getHierarchicalFacetSeparator: function (hierarchicalFacet) {
7108
7519
  return hierarchicalFacet.separator || ' > ';
7109
7520
  },
7521
+
7110
7522
  /**
7111
7523
  * Helper function to get the hierarchicalFacet prefix path or null
7112
7524
  * @private
7113
7525
  * @param {object} hierarchicalFacet the hierarchicalFacet object
7114
7526
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
7115
7527
  */
7116
- _getHierarchicalRootPath: function _getHierarchicalRootPath(hierarchicalFacet) {
7528
+ _getHierarchicalRootPath: function (hierarchicalFacet) {
7117
7529
  return hierarchicalFacet.rootPath || null;
7118
7530
  },
7531
+
7119
7532
  /**
7120
7533
  * Helper function to check if we show the parent level of the hierarchicalFacet
7121
7534
  * @private
7122
7535
  * @param {object} hierarchicalFacet the hierarchicalFacet object
7123
7536
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
7124
7537
  */
7125
- _getHierarchicalShowParentLevel: function _getHierarchicalShowParentLevel(hierarchicalFacet) {
7538
+ _getHierarchicalShowParentLevel: function (hierarchicalFacet) {
7126
7539
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
7127
7540
  return hierarchicalFacet.showParentLevel;
7128
7541
  }
7129
7542
  return true;
7130
7543
  },
7544
+
7131
7545
  /**
7132
7546
  * Helper function to get the hierarchicalFacet by it's name
7133
7547
  * @param {string} hierarchicalFacetName the hierarchicalFacet name
7134
7548
  * @return {object} a hierarchicalFacet
7135
7549
  */
7136
- getHierarchicalFacetByName: function getHierarchicalFacetByName(hierarchicalFacetName) {
7550
+ getHierarchicalFacetByName: function (hierarchicalFacetName) {
7137
7551
  return find$1(this.hierarchicalFacets, function (f) {
7138
7552
  return f.name === hierarchicalFacetName;
7139
7553
  });
7140
7554
  },
7555
+
7141
7556
  /**
7142
7557
  * Get the current breadcrumb for a hierarchical facet, as an array
7143
7558
  * @param {string} facetName Hierarchical facet name
7144
7559
  * @return {array.<string>} the path as an array of string
7145
7560
  */
7146
- getHierarchicalFacetBreadcrumb: function getHierarchicalFacetBreadcrumb(facetName) {
7561
+ getHierarchicalFacetBreadcrumb: function (facetName) {
7147
7562
  if (!this.isHierarchicalFacet(facetName)) {
7148
7563
  return [];
7149
7564
  }
7565
+
7150
7566
  var refinement = this.getHierarchicalRefinement(facetName)[0];
7151
7567
  if (!refinement) return [];
7152
- var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facetName));
7568
+
7569
+ var separator = this._getHierarchicalFacetSeparator(
7570
+ this.getHierarchicalFacetByName(facetName)
7571
+ );
7153
7572
  var path = refinement.split(separator);
7154
7573
  return path.map(function (part) {
7155
7574
  return part.trim();
7156
7575
  });
7157
7576
  },
7158
- toString: function toString() {
7577
+
7578
+ toString: function () {
7159
7579
  return JSON.stringify(this, null, 2);
7160
- }
7580
+ },
7161
7581
  };
7162
7582
 
7163
7583
  /**
@@ -7175,12 +7595,22 @@
7175
7595
  if (value !== other) {
7176
7596
  var valIsDefined = value !== undefined;
7177
7597
  var valIsNull = value === null;
7598
+
7178
7599
  var othIsDefined = other !== undefined;
7179
7600
  var othIsNull = other === null;
7180
- if (!othIsNull && value > other || valIsNull && othIsDefined || !valIsDefined) {
7601
+
7602
+ if (
7603
+ (!othIsNull && value > other) ||
7604
+ (valIsNull && othIsDefined) ||
7605
+ !valIsDefined
7606
+ ) {
7181
7607
  return 1;
7182
7608
  }
7183
- if (!valIsNull && value < other || othIsNull && valIsDefined || !othIsDefined) {
7609
+ if (
7610
+ (!valIsNull && value < other) ||
7611
+ (othIsNull && valIsDefined) ||
7612
+ !othIsDefined
7613
+ ) {
7184
7614
  return -1;
7185
7615
  }
7186
7616
  }
@@ -7197,20 +7627,24 @@
7197
7627
  if (!Array.isArray(collection)) {
7198
7628
  return [];
7199
7629
  }
7630
+
7200
7631
  if (!Array.isArray(orders)) {
7201
7632
  orders = [];
7202
7633
  }
7634
+
7203
7635
  var result = collection.map(function (value, index) {
7204
7636
  return {
7205
7637
  criteria: iteratees.map(function (iteratee) {
7206
7638
  return value[iteratee];
7207
7639
  }),
7208
7640
  index: index,
7209
- value: value
7641
+ value: value,
7210
7642
  };
7211
7643
  });
7644
+
7212
7645
  result.sort(function comparer(object, other) {
7213
7646
  var index = -1;
7647
+
7214
7648
  while (++index < object.criteria.length) {
7215
7649
  var res = compareAscending(object.criteria[index], other.criteria[index]);
7216
7650
  if (res) {
@@ -7228,16 +7662,19 @@
7228
7662
  // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
7229
7663
  return object.index - other.index;
7230
7664
  });
7665
+
7231
7666
  return result.map(function (res) {
7232
7667
  return res.value;
7233
7668
  });
7234
7669
  }
7670
+
7235
7671
  var orderBy_1 = orderBy;
7236
7672
 
7237
7673
  var compact = function compact(array) {
7238
7674
  if (!Array.isArray(array)) {
7239
7675
  return [];
7240
7676
  }
7677
+
7241
7678
  return array.filter(Boolean);
7242
7679
  };
7243
7680
 
@@ -7246,6 +7683,7 @@
7246
7683
  if (!Array.isArray(array)) {
7247
7684
  return -1;
7248
7685
  }
7686
+
7249
7687
  for (var i = 0; i < array.length; i++) {
7250
7688
  if (comparator(array[i])) {
7251
7689
  return i;
@@ -7264,20 +7702,30 @@
7264
7702
  var defaultInstructions = (defaults || []).map(function (sort) {
7265
7703
  return sort.split(':');
7266
7704
  });
7267
- return sortBy.reduce(function preparePredicate(out, sort) {
7268
- var sortInstruction = sort.split(':');
7269
- var matchingDefault = find$1(defaultInstructions, function (defaultInstruction) {
7270
- return defaultInstruction[0] === sortInstruction[0];
7271
- });
7272
- if (sortInstruction.length > 1 || !matchingDefault) {
7273
- out[0].push(sortInstruction[0]);
7274
- out[1].push(sortInstruction[1]);
7705
+
7706
+ return sortBy.reduce(
7707
+ function preparePredicate(out, sort) {
7708
+ var sortInstruction = sort.split(':');
7709
+
7710
+ var matchingDefault = find$1(
7711
+ defaultInstructions,
7712
+ function (defaultInstruction) {
7713
+ return defaultInstruction[0] === sortInstruction[0];
7714
+ }
7715
+ );
7716
+
7717
+ if (sortInstruction.length > 1 || !matchingDefault) {
7718
+ out[0].push(sortInstruction[0]);
7719
+ out[1].push(sortInstruction[1]);
7720
+ return out;
7721
+ }
7722
+
7723
+ out[0].push(matchingDefault[0]);
7724
+ out[1].push(matchingDefault[1]);
7275
7725
  return out;
7276
- }
7277
- out[0].push(matchingDefault[0]);
7278
- out[1].push(matchingDefault[1]);
7279
- return out;
7280
- }, [[], []]);
7726
+ },
7727
+ [[], []]
7728
+ );
7281
7729
  };
7282
7730
 
7283
7731
  /**
@@ -7288,6 +7736,7 @@
7288
7736
  */
7289
7737
  function escapeFacetValue$1(value) {
7290
7738
  if (typeof value !== 'string') return value;
7739
+
7291
7740
  return String(value).replace(/^-/, '\\-');
7292
7741
  }
7293
7742
 
@@ -7299,11 +7748,13 @@
7299
7748
  */
7300
7749
  function unescapeFacetValue$1(value) {
7301
7750
  if (typeof value !== 'string') return value;
7751
+
7302
7752
  return value.replace(/^\\-/, '-');
7303
7753
  }
7754
+
7304
7755
  var escapeFacetValue_1 = {
7305
7756
  escapeFacetValue: escapeFacetValue$1,
7306
- unescapeFacetValue: unescapeFacetValue$1
7757
+ unescapeFacetValue: unescapeFacetValue$1,
7307
7758
  };
7308
7759
 
7309
7760
  var generateHierarchicalTree_1 = generateTrees;
@@ -7311,44 +7762,78 @@
7311
7762
 
7312
7763
 
7313
7764
 
7765
+
7314
7766
  var escapeFacetValue$2 = escapeFacetValue_1.escapeFacetValue;
7315
7767
  var unescapeFacetValue$2 = escapeFacetValue_1.unescapeFacetValue;
7768
+
7316
7769
  function generateTrees(state) {
7317
7770
  return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
7318
7771
  var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
7319
- var hierarchicalFacetRefinement = state.hierarchicalFacetsRefinements[hierarchicalFacet.name] && state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0] || '';
7320
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
7321
- var hierarchicalRootPath = state._getHierarchicalRootPath(hierarchicalFacet);
7322
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(hierarchicalFacet);
7323
- var sortBy = formatSort(state._getHierarchicalFacetSortBy(hierarchicalFacet));
7772
+ var hierarchicalFacetRefinement =
7773
+ (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
7774
+ state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
7775
+ '';
7776
+ var hierarchicalSeparator =
7777
+ state._getHierarchicalFacetSeparator(hierarchicalFacet);
7778
+ var hierarchicalRootPath =
7779
+ state._getHierarchicalRootPath(hierarchicalFacet);
7780
+ var hierarchicalShowParentLevel =
7781
+ state._getHierarchicalShowParentLevel(hierarchicalFacet);
7782
+ var sortBy = formatSort(
7783
+ state._getHierarchicalFacetSortBy(hierarchicalFacet)
7784
+ );
7785
+
7324
7786
  var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
7325
7787
  return facetResult.exhaustive;
7326
7788
  });
7327
- var generateTreeFn = generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, hierarchicalFacetRefinement);
7789
+
7790
+ var generateTreeFn = generateHierarchicalTree(
7791
+ sortBy,
7792
+ hierarchicalSeparator,
7793
+ hierarchicalRootPath,
7794
+ hierarchicalShowParentLevel,
7795
+ hierarchicalFacetRefinement
7796
+ );
7797
+
7328
7798
  var results = hierarchicalFacetResult;
7799
+
7329
7800
  if (hierarchicalRootPath) {
7330
- results = hierarchicalFacetResult.slice(hierarchicalRootPath.split(hierarchicalSeparator).length);
7801
+ results = hierarchicalFacetResult.slice(
7802
+ hierarchicalRootPath.split(hierarchicalSeparator).length
7803
+ );
7331
7804
  }
7805
+
7332
7806
  return results.reduce(generateTreeFn, {
7333
7807
  name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
7334
- count: null,
7335
- // root level, no count
7336
- isRefined: true,
7337
- // root level, always refined
7338
- path: null,
7339
- // root level, no path
7808
+ count: null, // root level, no count
7809
+ isRefined: true, // root level, always refined
7810
+ path: null, // root level, no path
7340
7811
  escapedValue: null,
7341
7812
  exhaustive: rootExhaustive,
7342
- data: null
7813
+ data: null,
7343
7814
  });
7344
7815
  };
7345
7816
  }
7346
- function generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, currentRefinement) {
7347
- return function generateTree(hierarchicalTree, hierarchicalFacetResult, currentHierarchicalLevel) {
7817
+
7818
+ function generateHierarchicalTree(
7819
+ sortBy,
7820
+ hierarchicalSeparator,
7821
+ hierarchicalRootPath,
7822
+ hierarchicalShowParentLevel,
7823
+ currentRefinement
7824
+ ) {
7825
+ return function generateTree(
7826
+ hierarchicalTree,
7827
+ hierarchicalFacetResult,
7828
+ currentHierarchicalLevel
7829
+ ) {
7348
7830
  var parent = hierarchicalTree;
7831
+
7349
7832
  if (currentHierarchicalLevel > 0) {
7350
7833
  var level = 0;
7834
+
7351
7835
  parent = hierarchicalTree;
7836
+
7352
7837
  while (level < currentHierarchicalLevel) {
7353
7838
  /**
7354
7839
  * @type {object[]]} hierarchical data
@@ -7374,51 +7859,102 @@
7374
7859
  // If parent refinement is `beers`, then we do not want to have `bières > Belges`
7375
7860
  // showing up
7376
7861
 
7377
- var picked = Object.keys(hierarchicalFacetResult.data).map(function (facetValue) {
7378
- return [facetValue, hierarchicalFacetResult.data[facetValue]];
7379
- }).filter(function (tuple) {
7380
- var facetValue = tuple[0];
7381
- return onlyMatchingTree(facetValue, parent.path || hierarchicalRootPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel);
7382
- });
7383
- parent.data = orderBy_1(picked.map(function (tuple) {
7384
- var facetValue = tuple[0];
7385
- var facetCount = tuple[1];
7386
- return format(facetCount, facetValue, hierarchicalSeparator, unescapeFacetValue$2(currentRefinement), hierarchicalFacetResult.exhaustive);
7387
- }), sortBy[0], sortBy[1]);
7862
+ var picked = Object.keys(hierarchicalFacetResult.data)
7863
+ .map(function (facetValue) {
7864
+ return [facetValue, hierarchicalFacetResult.data[facetValue]];
7865
+ })
7866
+ .filter(function (tuple) {
7867
+ var facetValue = tuple[0];
7868
+ return onlyMatchingTree(
7869
+ facetValue,
7870
+ parent.path || hierarchicalRootPath,
7871
+ currentRefinement,
7872
+ hierarchicalSeparator,
7873
+ hierarchicalRootPath,
7874
+ hierarchicalShowParentLevel
7875
+ );
7876
+ });
7877
+
7878
+ parent.data = orderBy_1(
7879
+ picked.map(function (tuple) {
7880
+ var facetValue = tuple[0];
7881
+ var facetCount = tuple[1];
7882
+
7883
+ return format(
7884
+ facetCount,
7885
+ facetValue,
7886
+ hierarchicalSeparator,
7887
+ unescapeFacetValue$2(currentRefinement),
7888
+ hierarchicalFacetResult.exhaustive
7889
+ );
7890
+ }),
7891
+ sortBy[0],
7892
+ sortBy[1]
7893
+ );
7388
7894
  }
7895
+
7389
7896
  return hierarchicalTree;
7390
7897
  };
7391
7898
  }
7392
7899
 
7393
7900
  // eslint-disable-next-line max-params
7394
- function onlyMatchingTree(facetValue, parentPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel) {
7901
+ function onlyMatchingTree(
7902
+ facetValue,
7903
+ parentPath,
7904
+ currentRefinement,
7905
+ hierarchicalSeparator,
7906
+ hierarchicalRootPath,
7907
+ hierarchicalShowParentLevel
7908
+ ) {
7395
7909
  // we want the facetValue is a child of hierarchicalRootPath
7396
- if (hierarchicalRootPath && (facetValue.indexOf(hierarchicalRootPath) !== 0 || hierarchicalRootPath === facetValue)) {
7910
+ if (
7911
+ hierarchicalRootPath &&
7912
+ (facetValue.indexOf(hierarchicalRootPath) !== 0 ||
7913
+ hierarchicalRootPath === facetValue)
7914
+ ) {
7397
7915
  return false;
7398
7916
  }
7399
7917
 
7400
7918
  // we always want root levels (only when there is no prefix path)
7401
- return !hierarchicalRootPath && facetValue.indexOf(hierarchicalSeparator) === -1 ||
7402
- // if there is a rootPath, being root level mean 1 level under rootPath
7403
- hierarchicalRootPath && facetValue.split(hierarchicalSeparator).length - hierarchicalRootPath.split(hierarchicalSeparator).length === 1 ||
7404
- // if current refinement is a root level and current facetValue is a root level,
7405
- // keep the facetValue
7406
- facetValue.indexOf(hierarchicalSeparator) === -1 && currentRefinement.indexOf(hierarchicalSeparator) === -1 ||
7407
- // currentRefinement is a child of the facet value
7408
- currentRefinement.indexOf(facetValue) === 0 ||
7409
- // facetValue is a child of the current parent, add it
7410
- facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 && (hierarchicalShowParentLevel || facetValue.indexOf(currentRefinement) === 0);
7919
+ return (
7920
+ (!hierarchicalRootPath &&
7921
+ facetValue.indexOf(hierarchicalSeparator) === -1) ||
7922
+ // if there is a rootPath, being root level mean 1 level under rootPath
7923
+ (hierarchicalRootPath &&
7924
+ facetValue.split(hierarchicalSeparator).length -
7925
+ hierarchicalRootPath.split(hierarchicalSeparator).length ===
7926
+ 1) ||
7927
+ // if current refinement is a root level and current facetValue is a root level,
7928
+ // keep the facetValue
7929
+ (facetValue.indexOf(hierarchicalSeparator) === -1 &&
7930
+ currentRefinement.indexOf(hierarchicalSeparator) === -1) ||
7931
+ // currentRefinement is a child of the facet value
7932
+ currentRefinement.indexOf(facetValue) === 0 ||
7933
+ // facetValue is a child of the current parent, add it
7934
+ (facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
7935
+ (hierarchicalShowParentLevel ||
7936
+ facetValue.indexOf(currentRefinement) === 0))
7937
+ );
7411
7938
  }
7412
- function format(facetCount, facetValue, hierarchicalSeparator, currentRefinement, exhaustive) {
7939
+
7940
+ function format(
7941
+ facetCount,
7942
+ facetValue,
7943
+ hierarchicalSeparator,
7944
+ currentRefinement,
7945
+ exhaustive
7946
+ ) {
7413
7947
  var parts = facetValue.split(hierarchicalSeparator);
7414
7948
  return {
7415
7949
  name: parts[parts.length - 1].trim(),
7416
7950
  path: facetValue,
7417
7951
  escapedValue: escapeFacetValue$2(facetValue),
7418
7952
  count: facetCount,
7419
- isRefined: currentRefinement === facetValue || currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
7953
+ isRefined:
7954
+ currentRefinement === facetValue ||
7955
+ currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
7420
7956
  exhaustive: exhaustive,
7421
- data: null
7957
+ data: null,
7422
7958
  };
7423
7959
  }
7424
7960
 
@@ -7426,6 +7962,7 @@
7426
7962
  var unescapeFacetValue$3 = escapeFacetValue_1.unescapeFacetValue;
7427
7963
 
7428
7964
 
7965
+
7429
7966
  /**
7430
7967
  * @typedef SearchResults.Facet
7431
7968
  * @type {object}
@@ -7474,11 +8011,14 @@
7474
8011
  */
7475
8012
  function getIndices(attributes) {
7476
8013
  var indices = {};
8014
+
7477
8015
  attributes.forEach(function (val, idx) {
7478
8016
  indices[val] = idx;
7479
8017
  });
8018
+
7480
8019
  return indices;
7481
8020
  }
8021
+
7482
8022
  function assignFacetStats(dest, facetStats, key) {
7483
8023
  if (facetStats && facetStats[key]) {
7484
8024
  dest.stats = facetStats[key];
@@ -7496,11 +8036,17 @@
7496
8036
  * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
7497
8037
  * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
7498
8038
  */
7499
- function findMatchingHierarchicalFacetFromAttributeName(hierarchicalFacets, hierarchicalAttributeName) {
7500
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(hierarchicalFacet) {
7501
- var facetNames = hierarchicalFacet.attributes || [];
7502
- return facetNames.indexOf(hierarchicalAttributeName) > -1;
7503
- });
8039
+ function findMatchingHierarchicalFacetFromAttributeName(
8040
+ hierarchicalFacets,
8041
+ hierarchicalAttributeName
8042
+ ) {
8043
+ return find$1(
8044
+ hierarchicalFacets,
8045
+ function facetKeyMatchesAttribute(hierarchicalFacet) {
8046
+ var facetNames = hierarchicalFacet.attributes || [];
8047
+ return facetNames.indexOf(hierarchicalAttributeName) > -1;
8048
+ }
8049
+ );
7504
8050
  }
7505
8051
 
7506
8052
  // eslint-disable-next-line valid-jsdoc
@@ -7636,6 +8182,7 @@
7636
8182
  **/
7637
8183
  function SearchResults(state, results, options) {
7638
8184
  var mainSubResponse = results[0];
8185
+
7639
8186
  this._rawResults = results;
7640
8187
 
7641
8188
  // eslint-disable-next-line consistent-this
@@ -7792,7 +8339,9 @@
7792
8339
  * @instance
7793
8340
  */
7794
8341
  this.processingTimeMS = results.reduce(function (sum, result) {
7795
- return result.processingTimeMS === undefined ? sum : sum + result.processingTimeMS;
8342
+ return result.processingTimeMS === undefined
8343
+ ? sum
8344
+ : sum + result.processingTimeMS;
7796
8345
  }, 0);
7797
8346
 
7798
8347
  /**
@@ -7804,15 +8353,19 @@
7804
8353
  * disjunctive facets results
7805
8354
  * @member {SearchResults.HierarchicalFacet[]}
7806
8355
  */
7807
- this.hierarchicalFacets = state.hierarchicalFacets.map(function initFutureTree() {
7808
- return [];
7809
- });
8356
+ this.hierarchicalFacets = state.hierarchicalFacets.map(
8357
+ function initFutureTree() {
8358
+ return [];
8359
+ }
8360
+ );
7810
8361
  /**
7811
8362
  * other facets results
7812
8363
  * @member {SearchResults.Facet[]}
7813
8364
  */
7814
8365
  this.facets = [];
8366
+
7815
8367
  var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
8368
+
7816
8369
  var facetsIndices = getIndices(state.facets);
7817
8370
  var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
7818
8371
  var nextDisjunctiveResult = 1;
@@ -7821,9 +8374,15 @@
7821
8374
  // we get the facets information from the first, general, response.
7822
8375
 
7823
8376
  var mainFacets = mainSubResponse.facets || {};
8377
+
7824
8378
  Object.keys(mainFacets).forEach(function (facetKey) {
7825
8379
  var facetValueObject = mainFacets[facetKey];
7826
- var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(state.hierarchicalFacets, facetKey);
8380
+
8381
+ var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
8382
+ state.hierarchicalFacets,
8383
+ facetKey
8384
+ );
8385
+
7827
8386
  if (hierarchicalFacet) {
7828
8387
  // Place the hierarchicalFacet data at the correct index depending on
7829
8388
  // the attributes order that was defined at the helper initialization
@@ -7834,29 +8393,38 @@
7834
8393
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
7835
8394
  attribute: facetKey,
7836
8395
  data: facetValueObject,
7837
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8396
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
7838
8397
  };
7839
8398
  } else {
7840
8399
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
7841
8400
  var isFacetConjunctive = state.facets.indexOf(facetKey) !== -1;
7842
8401
  var position;
8402
+
7843
8403
  if (isFacetDisjunctive) {
7844
8404
  position = disjunctiveFacetsIndices[facetKey];
7845
8405
  self.disjunctiveFacets[position] = {
7846
8406
  name: facetKey,
7847
8407
  data: facetValueObject,
7848
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8408
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
7849
8409
  };
7850
- assignFacetStats(self.disjunctiveFacets[position], mainSubResponse.facets_stats, facetKey);
8410
+ assignFacetStats(
8411
+ self.disjunctiveFacets[position],
8412
+ mainSubResponse.facets_stats,
8413
+ facetKey
8414
+ );
7851
8415
  }
7852
8416
  if (isFacetConjunctive) {
7853
8417
  position = facetsIndices[facetKey];
7854
8418
  self.facets[position] = {
7855
8419
  name: facetKey,
7856
8420
  data: facetValueObject,
7857
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8421
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
7858
8422
  };
7859
- assignFacetStats(self.facets[position], mainSubResponse.facets_stats, facetKey);
8423
+ assignFacetStats(
8424
+ self.facets[position],
8425
+ mainSubResponse.facets_stats,
8426
+ facetKey
8427
+ );
7860
8428
  }
7861
8429
  }
7862
8430
  });
@@ -7873,33 +8441,58 @@
7873
8441
  // There should be only item in facets.
7874
8442
  Object.keys(facets).forEach(function (dfacet) {
7875
8443
  var facetResults = facets[dfacet];
8444
+
7876
8445
  var position;
8446
+
7877
8447
  if (hierarchicalFacet) {
7878
8448
  position = findIndex$1(state.hierarchicalFacets, function (f) {
7879
8449
  return f.name === hierarchicalFacet.name;
7880
8450
  });
7881
- var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function (f) {
7882
- return f.attribute === dfacet;
7883
- });
8451
+ var attributeIndex = findIndex$1(
8452
+ self.hierarchicalFacets[position],
8453
+ function (f) {
8454
+ return f.attribute === dfacet;
8455
+ }
8456
+ );
7884
8457
 
7885
8458
  // previous refinements and no results so not able to find it
7886
8459
  if (attributeIndex === -1) {
7887
8460
  return;
7888
8461
  }
7889
- self.hierarchicalFacets[position][attributeIndex].data = merge$1({}, self.hierarchicalFacets[position][attributeIndex].data, facetResults);
8462
+
8463
+ self.hierarchicalFacets[position][attributeIndex].data = merge_1(
8464
+ {},
8465
+ self.hierarchicalFacets[position][attributeIndex].data,
8466
+ facetResults
8467
+ );
7890
8468
  } else {
7891
8469
  position = disjunctiveFacetsIndices[dfacet];
7892
- var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
8470
+
8471
+ var dataFromMainRequest =
8472
+ (mainSubResponse.facets && mainSubResponse.facets[dfacet]) || {};
8473
+
7893
8474
  self.disjunctiveFacets[position] = {
7894
8475
  name: dfacet,
7895
8476
  data: defaultsPure({}, facetResults, dataFromMainRequest),
7896
- exhaustive: result.exhaustiveFacetsCount
8477
+ exhaustive: result.exhaustiveFacetsCount,
7897
8478
  };
7898
- assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
8479
+ assignFacetStats(
8480
+ self.disjunctiveFacets[position],
8481
+ result.facets_stats,
8482
+ dfacet
8483
+ );
8484
+
7899
8485
  if (state.disjunctiveFacetsRefinements[dfacet]) {
7900
- state.disjunctiveFacetsRefinements[dfacet].forEach(function (refinementValue) {
8486
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (
8487
+ refinementValue
8488
+ ) {
7901
8489
  // add the disjunctive refinements if it is no more retrieved
7902
- if (!self.disjunctiveFacets[position].data[refinementValue] && state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
8490
+ if (
8491
+ !self.disjunctiveFacets[position].data[refinementValue] &&
8492
+ state.disjunctiveFacetsRefinements[dfacet].indexOf(
8493
+ unescapeFacetValue$3(refinementValue)
8494
+ ) > -1
8495
+ ) {
7903
8496
  self.disjunctiveFacets[position].data[refinementValue] = 0;
7904
8497
  }
7905
8498
  });
@@ -7913,22 +8506,31 @@
7913
8506
  state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
7914
8507
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
7915
8508
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
8509
+
7916
8510
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
7917
8511
  // if we are already at a root refinement (or no refinement at all), there is no
7918
8512
  // root level values request
7919
- if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
8513
+ if (
8514
+ currentRefinement.length === 0 ||
8515
+ currentRefinement[0].split(separator).length < 2
8516
+ ) {
7920
8517
  return;
7921
8518
  }
8519
+
7922
8520
  results.slice(nextDisjunctiveResult).forEach(function (result) {
7923
8521
  var facets = result && result.facets ? result.facets : {};
8522
+
7924
8523
  Object.keys(facets).forEach(function (dfacet) {
7925
8524
  var facetResults = facets[dfacet];
7926
8525
  var position = findIndex$1(state.hierarchicalFacets, function (f) {
7927
8526
  return f.name === hierarchicalFacet.name;
7928
8527
  });
7929
- var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function (f) {
7930
- return f.attribute === dfacet;
7931
- });
8528
+ var attributeIndex = findIndex$1(
8529
+ self.hierarchicalFacets[position],
8530
+ function (f) {
8531
+ return f.attribute === dfacet;
8532
+ }
8533
+ );
7932
8534
 
7933
8535
  // previous refinements and no results so not able to find it
7934
8536
  if (attributeIndex === -1) {
@@ -7944,12 +8546,20 @@
7944
8546
  // | beers (5)
7945
8547
  // > IPA (5)
7946
8548
  var defaultData = {};
8549
+
7947
8550
  if (currentRefinement.length > 0) {
7948
8551
  var root = currentRefinement[0].split(separator)[0];
7949
- defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
8552
+ defaultData[root] =
8553
+ self.hierarchicalFacets[position][attributeIndex].data[root];
7950
8554
  }
7951
- self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(defaultData, facetResults, self.hierarchicalFacets[position][attributeIndex].data);
8555
+
8556
+ self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
8557
+ defaultData,
8558
+ facetResults,
8559
+ self.hierarchicalFacets[position][attributeIndex].data
8560
+ );
7952
8561
  });
8562
+
7953
8563
  nextDisjunctiveResult++;
7954
8564
  });
7955
8565
  });
@@ -7958,15 +8568,14 @@
7958
8568
  Object.keys(state.facetsExcludes).forEach(function (facetName) {
7959
8569
  var excludes = state.facetsExcludes[facetName];
7960
8570
  var position = facetsIndices[facetName];
8571
+
7961
8572
  self.facets[position] = {
7962
8573
  name: facetName,
7963
8574
  data: mainFacets[facetName],
7964
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8575
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
7965
8576
  };
7966
8577
  excludes.forEach(function (facetValue) {
7967
- self.facets[position] = self.facets[position] || {
7968
- name: facetName
7969
- };
8578
+ self.facets[position] = self.facets[position] || { name: facetName };
7970
8579
  self.facets[position].data = self.facets[position].data || {};
7971
8580
  self.facets[position].data[facetValue] = 0;
7972
8581
  });
@@ -7975,7 +8584,9 @@
7975
8584
  /**
7976
8585
  * @type {Array}
7977
8586
  */
7978
- this.hierarchicalFacets = this.hierarchicalFacets.map(generateHierarchicalTree_1(state));
8587
+ this.hierarchicalFacets = this.hierarchicalFacets.map(
8588
+ generateHierarchicalTree_1(state)
8589
+ );
7979
8590
 
7980
8591
  /**
7981
8592
  * @type {Array}
@@ -7985,6 +8596,7 @@
7985
8596
  * @type {Array}
7986
8597
  */
7987
8598
  this.disjunctiveFacets = compact(this.disjunctiveFacets);
8599
+
7988
8600
  this._state = state;
7989
8601
  }
7990
8602
 
@@ -7998,7 +8610,12 @@
7998
8610
  function predicate(facet) {
7999
8611
  return facet.name === name;
8000
8612
  }
8001
- return find$1(this.facets, predicate) || find$1(this.disjunctiveFacets, predicate) || find$1(this.hierarchicalFacets, predicate);
8613
+
8614
+ return (
8615
+ find$1(this.facets, predicate) ||
8616
+ find$1(this.disjunctiveFacets, predicate) ||
8617
+ find$1(this.hierarchicalFacets, predicate)
8618
+ );
8002
8619
  };
8003
8620
 
8004
8621
  /**
@@ -8012,9 +8629,11 @@
8012
8629
  function predicate(facet) {
8013
8630
  return facet.name === attribute;
8014
8631
  }
8632
+
8015
8633
  if (results._state.isConjunctiveFacet(attribute)) {
8016
8634
  var facet = find$1(results.facets, predicate);
8017
8635
  if (!facet) return [];
8636
+
8018
8637
  return Object.keys(facet.data).map(function (name) {
8019
8638
  var value = escapeFacetValue$3(name);
8020
8639
  return {
@@ -8022,35 +8641,49 @@
8022
8641
  escapedValue: value,
8023
8642
  count: facet.data[name],
8024
8643
  isRefined: results._state.isFacetRefined(attribute, value),
8025
- isExcluded: results._state.isExcludeRefined(attribute, name)
8644
+ isExcluded: results._state.isExcludeRefined(attribute, name),
8026
8645
  };
8027
8646
  });
8028
8647
  } else if (results._state.isDisjunctiveFacet(attribute)) {
8029
8648
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
8030
8649
  if (!disjunctiveFacet) return [];
8650
+
8031
8651
  return Object.keys(disjunctiveFacet.data).map(function (name) {
8032
8652
  var value = escapeFacetValue$3(name);
8033
8653
  return {
8034
8654
  name: name,
8035
8655
  escapedValue: value,
8036
8656
  count: disjunctiveFacet.data[name],
8037
- isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
8657
+ isRefined: results._state.isDisjunctiveFacetRefined(attribute, value),
8038
8658
  };
8039
8659
  });
8040
8660
  } else if (results._state.isHierarchicalFacet(attribute)) {
8041
8661
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
8042
8662
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
8043
- var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
8044
- var separator = results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
8045
- var currentRefinement = unescapeFacetValue$3(results._state.getHierarchicalRefinement(attribute)[0] || '');
8663
+
8664
+ var hierarchicalFacet =
8665
+ results._state.getHierarchicalFacetByName(attribute);
8666
+ var separator =
8667
+ results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
8668
+ var currentRefinement = unescapeFacetValue$3(
8669
+ results._state.getHierarchicalRefinement(attribute)[0] || ''
8670
+ );
8671
+
8046
8672
  if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
8047
- currentRefinement = currentRefinement.replace(hierarchicalFacet.rootPath + separator, '');
8673
+ currentRefinement = currentRefinement.replace(
8674
+ hierarchicalFacet.rootPath + separator,
8675
+ ''
8676
+ );
8048
8677
  }
8678
+
8049
8679
  var currentRefinementSplit = currentRefinement.split(separator);
8050
8680
  currentRefinementSplit.unshift(attribute);
8681
+
8051
8682
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
8683
+
8052
8684
  return hierarchicalFacetValues;
8053
8685
  }
8686
+
8054
8687
  return undefined;
8055
8688
  }
8056
8689
 
@@ -8081,22 +8714,25 @@
8081
8714
  */
8082
8715
  function recSort(sortFn, node, names, level) {
8083
8716
  level = level || 0;
8717
+
8084
8718
  if (Array.isArray(node)) {
8085
8719
  return sortFn(node, names[level]);
8086
8720
  }
8721
+
8087
8722
  if (!node.data || node.data.length === 0) {
8088
8723
  return node;
8089
8724
  }
8725
+
8090
8726
  var children = node.data.map(function (childNode) {
8091
8727
  return recSort(sortFn, childNode, names, level + 1);
8092
8728
  });
8093
8729
  var sortedChildren = sortFn(children, names[level]);
8094
- var newNode = defaultsPure({
8095
- data: sortedChildren
8096
- }, node);
8730
+ var newNode = defaultsPure({ data: sortedChildren }, node);
8097
8731
  return newNode;
8098
8732
  }
8733
+
8099
8734
  SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
8735
+
8100
8736
  function vanillaSortFn(order, data) {
8101
8737
  return data.sort(order);
8102
8738
  }
@@ -8117,6 +8753,7 @@
8117
8753
  function sortViaFacetOrdering(facetValues, facetOrdering) {
8118
8754
  var orderedFacets = [];
8119
8755
  var remainingFacets = [];
8756
+
8120
8757
  var order = facetOrdering.order || [];
8121
8758
  /**
8122
8759
  * an object with the keys being the values in order, the values their index:
@@ -8126,6 +8763,7 @@
8126
8763
  acc[name] = i;
8127
8764
  return acc;
8128
8765
  }, {});
8766
+
8129
8767
  facetValues.forEach(function (item) {
8130
8768
  // hierarchical facets get sorted using their raw name
8131
8769
  var name = item.path || item.name;
@@ -8135,19 +8773,27 @@
8135
8773
  remainingFacets.push(item);
8136
8774
  }
8137
8775
  });
8776
+
8138
8777
  orderedFacets = orderedFacets.filter(function (facet) {
8139
8778
  return facet;
8140
8779
  });
8780
+
8141
8781
  var sortRemainingBy = facetOrdering.sortRemainingBy;
8142
8782
  var ordering;
8143
8783
  if (sortRemainingBy === 'hidden') {
8144
8784
  return orderedFacets;
8145
8785
  } else if (sortRemainingBy === 'alpha') {
8146
- ordering = [['path', 'name'], ['asc', 'asc']];
8786
+ ordering = [
8787
+ ['path', 'name'],
8788
+ ['asc', 'asc'],
8789
+ ];
8147
8790
  } else {
8148
8791
  ordering = [['count'], ['desc']];
8149
8792
  }
8150
- return orderedFacets.concat(orderBy_1(remainingFacets, ordering[0], ordering[1]));
8793
+
8794
+ return orderedFacets.concat(
8795
+ orderBy_1(remainingFacets, ordering[0], ordering[1])
8796
+ );
8151
8797
  }
8152
8798
 
8153
8799
  /**
@@ -8156,7 +8802,12 @@
8156
8802
  * @returns {FacetOrdering | undefined} the facet ordering
8157
8803
  */
8158
8804
  function getFacetOrdering(results, attribute) {
8159
- return results.renderingContent && results.renderingContent.facetOrdering && results.renderingContent.facetOrdering.values && results.renderingContent.facetOrdering.values[attribute];
8805
+ return (
8806
+ results.renderingContent &&
8807
+ results.renderingContent.facetOrdering &&
8808
+ results.renderingContent.facetOrdering.values &&
8809
+ results.renderingContent.facetOrdering.values[attribute]
8810
+ );
8160
8811
  }
8161
8812
 
8162
8813
  /**
@@ -8212,11 +8863,12 @@
8212
8863
  if (!facetValues) {
8213
8864
  return undefined;
8214
8865
  }
8866
+
8215
8867
  var options = defaultsPure({}, opts, {
8216
8868
  sortBy: SearchResults.DEFAULT_SORT,
8217
8869
  // if no sortBy is given, attempt to sort based on facetOrdering
8218
8870
  // if it is given, we still allow to sort via facet ordering first
8219
- facetOrdering: !(opts && opts.sortBy)
8871
+ facetOrdering: !(opts && opts.sortBy),
8220
8872
  });
8221
8873
 
8222
8874
  // eslint-disable-next-line consistent-this
@@ -8228,21 +8880,30 @@
8228
8880
  var config = results._state.getHierarchicalFacetByName(facetValues.name);
8229
8881
  attributes = config.attributes;
8230
8882
  }
8231
- return recSort(function (data, facetName) {
8232
- if (options.facetOrdering) {
8233
- var facetOrdering = getFacetOrdering(results, facetName);
8234
- if (facetOrdering) {
8235
- return sortViaFacetOrdering(data, facetOrdering);
8883
+
8884
+ return recSort(
8885
+ function (data, facetName) {
8886
+ if (options.facetOrdering) {
8887
+ var facetOrdering = getFacetOrdering(results, facetName);
8888
+ if (facetOrdering) {
8889
+ return sortViaFacetOrdering(data, facetOrdering);
8890
+ }
8891
+ }
8892
+
8893
+ if (Array.isArray(options.sortBy)) {
8894
+ var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
8895
+ return orderBy_1(data, order[0], order[1]);
8896
+ } else if (typeof options.sortBy === 'function') {
8897
+ return vanillaSortFn(options.sortBy, data);
8236
8898
  }
8237
- }
8238
- if (Array.isArray(options.sortBy)) {
8239
- var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
8240
- return orderBy_1(data, order[0], order[1]);
8241
- } else if (typeof options.sortBy === 'function') {
8242
- return vanillaSortFn(options.sortBy, data);
8243
- }
8244
- throw new Error('options.sortBy is optional but if defined it must be ' + 'either an array of string (predicates) or a sorting function');
8245
- }, facetValues, attributes);
8899
+ throw new Error(
8900
+ 'options.sortBy is optional but if defined it must be ' +
8901
+ 'either an array of string (predicates) or a sorting function'
8902
+ );
8903
+ },
8904
+ facetValues,
8905
+ attributes
8906
+ );
8246
8907
  };
8247
8908
 
8248
8909
  /**
@@ -8257,6 +8918,7 @@
8257
8918
  } else if (this._state.isDisjunctiveFacet(attribute)) {
8258
8919
  return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
8259
8920
  }
8921
+
8260
8922
  return undefined;
8261
8923
  };
8262
8924
 
@@ -8294,26 +8956,54 @@
8294
8956
  // eslint-disable-next-line consistent-this
8295
8957
  var results = this;
8296
8958
  var res = [];
8959
+
8297
8960
  Object.keys(state.facetsRefinements).forEach(function (attributeName) {
8298
8961
  state.facetsRefinements[attributeName].forEach(function (name) {
8299
- res.push(getRefinement$1(state, 'facet', attributeName, name, results.facets));
8962
+ res.push(
8963
+ getRefinement$1(state, 'facet', attributeName, name, results.facets)
8964
+ );
8300
8965
  });
8301
8966
  });
8967
+
8302
8968
  Object.keys(state.facetsExcludes).forEach(function (attributeName) {
8303
8969
  state.facetsExcludes[attributeName].forEach(function (name) {
8304
- res.push(getRefinement$1(state, 'exclude', attributeName, name, results.facets));
8970
+ res.push(
8971
+ getRefinement$1(state, 'exclude', attributeName, name, results.facets)
8972
+ );
8305
8973
  });
8306
8974
  });
8307
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function (attributeName) {
8975
+
8976
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (
8977
+ attributeName
8978
+ ) {
8308
8979
  state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
8309
- res.push(getRefinement$1(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
8980
+ res.push(
8981
+ getRefinement$1(
8982
+ state,
8983
+ 'disjunctive',
8984
+ attributeName,
8985
+ name,
8986
+ results.disjunctiveFacets
8987
+ )
8988
+ );
8310
8989
  });
8311
8990
  });
8312
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function (attributeName) {
8991
+
8992
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (
8993
+ attributeName
8994
+ ) {
8313
8995
  state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
8314
- res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
8996
+ res.push(
8997
+ getHierarchicalRefinement(
8998
+ state,
8999
+ attributeName,
9000
+ name,
9001
+ results.hierarchicalFacets
9002
+ )
9003
+ );
8315
9004
  });
8316
9005
  });
9006
+
8317
9007
  Object.keys(state.numericRefinements).forEach(function (attributeName) {
8318
9008
  var operators = state.numericRefinements[attributeName];
8319
9009
  Object.keys(operators).forEach(function (operator) {
@@ -8323,18 +9013,16 @@
8323
9013
  attributeName: attributeName,
8324
9014
  name: value,
8325
9015
  numericValue: value,
8326
- operator: operator
9016
+ operator: operator,
8327
9017
  });
8328
9018
  });
8329
9019
  });
8330
9020
  });
9021
+
8331
9022
  state.tagRefinements.forEach(function (name) {
8332
- res.push({
8333
- type: 'tag',
8334
- attributeName: '_tags',
8335
- name: name
8336
- });
9023
+ res.push({ type: 'tag', attributeName: '_tags', name: name });
8337
9024
  });
9025
+
8338
9026
  return res;
8339
9027
  };
8340
9028
 
@@ -8358,13 +9046,14 @@
8358
9046
  return f.name === attributeName;
8359
9047
  });
8360
9048
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
8361
- var exhaustive = facet && facet.exhaustive || false;
9049
+ var exhaustive = (facet && facet.exhaustive) || false;
9050
+
8362
9051
  return {
8363
9052
  type: type,
8364
9053
  attributeName: attributeName,
8365
9054
  name: name,
8366
9055
  count: count,
8367
- exhaustive: exhaustive
9056
+ exhaustive: exhaustive,
8368
9057
  };
8369
9058
  }
8370
9059
 
@@ -8382,23 +9071,29 @@
8382
9071
  var rootFacet = find$1(resultsFacets, function (facet) {
8383
9072
  return facet.name === attributeName;
8384
9073
  });
9074
+
8385
9075
  var facet = split.reduce(function (intermediateFacet, part) {
8386
- var newFacet = intermediateFacet && find$1(intermediateFacet.data, function (f) {
8387
- return f.name === part;
8388
- });
9076
+ var newFacet =
9077
+ intermediateFacet &&
9078
+ find$1(intermediateFacet.data, function (f) {
9079
+ return f.name === part;
9080
+ });
8389
9081
  return newFacet !== undefined ? newFacet : intermediateFacet;
8390
9082
  }, rootFacet);
8391
- var count = facet && facet.count || 0;
8392
- var exhaustive = facet && facet.exhaustive || false;
8393
- var path = facet && facet.path || '';
9083
+
9084
+ var count = (facet && facet.count) || 0;
9085
+ var exhaustive = (facet && facet.exhaustive) || false;
9086
+ var path = (facet && facet.path) || '';
9087
+
8394
9088
  return {
8395
9089
  type: 'hierarchical',
8396
9090
  attributeName: attributeName,
8397
9091
  name: path,
8398
9092
  count: count,
8399
- exhaustive: exhaustive
9093
+ exhaustive: exhaustive,
8400
9094
  };
8401
9095
  }
9096
+
8402
9097
  var SearchResults_1 = SearchResults;
8403
9098
 
8404
9099
  // Copyright Joyent, Inc. and other Node contributors.
@@ -8710,10 +9405,11 @@
8710
9405
  value: ctor,
8711
9406
  enumerable: false,
8712
9407
  writable: true,
8713
- configurable: true
8714
- }
9408
+ configurable: true,
9409
+ },
8715
9410
  });
8716
9411
  }
9412
+
8717
9413
  var inherits_1 = inherits;
8718
9414
 
8719
9415
  /**
@@ -8733,6 +9429,7 @@
8733
9429
  this.fn = fn;
8734
9430
  this.lastResults = null;
8735
9431
  }
9432
+
8736
9433
  inherits_1(DerivedHelper, events);
8737
9434
 
8738
9435
  /**
@@ -8744,19 +9441,24 @@
8744
9441
  this.removeAllListeners();
8745
9442
  this.main.detachDerivedHelper(this);
8746
9443
  };
9444
+
8747
9445
  DerivedHelper.prototype.getModifiedState = function (parameters) {
8748
9446
  return this.fn(parameters);
8749
9447
  };
9448
+
8750
9449
  var DerivedHelper_1 = DerivedHelper;
8751
9450
 
8752
9451
  function sortObject(obj) {
8753
- return Object.keys(obj).sort(function (a, b) {
8754
- return a.localeCompare(b);
8755
- }).reduce(function (acc, curr) {
8756
- acc[curr] = obj[curr];
8757
- return acc;
8758
- }, {});
9452
+ return Object.keys(obj)
9453
+ .sort(function (a, b) {
9454
+ return a.localeCompare(b);
9455
+ })
9456
+ .reduce(function (acc, curr) {
9457
+ acc[curr] = obj[curr];
9458
+ return acc;
9459
+ }, {});
8759
9460
  }
9461
+
8760
9462
  var requestBuilder = {
8761
9463
  /**
8762
9464
  * Get all the queries to send to the client, those queries can used directly
@@ -8772,14 +9474,17 @@
8772
9474
  // One query for the hits
8773
9475
  queries.push({
8774
9476
  indexName: index,
8775
- params: requestBuilder._getHitsSearchParams(state)
9477
+ params: requestBuilder._getHitsSearchParams(state),
8776
9478
  });
8777
9479
 
8778
9480
  // One for each disjunctive facets
8779
9481
  state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
8780
9482
  queries.push({
8781
9483
  indexName: index,
8782
- params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
9484
+ params: requestBuilder._getDisjunctiveFacetSearchParams(
9485
+ state,
9486
+ refinedFacet
9487
+ ),
8783
9488
  });
8784
9489
  });
8785
9490
 
@@ -8791,16 +9496,30 @@
8791
9496
 
8792
9497
  // If we are deeper than level 0 (starting from `beer > IPA`)
8793
9498
  // we want to get all parent values
8794
- if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
9499
+ if (
9500
+ currentRefinement.length > 0 &&
9501
+ currentRefinement[0].split(separator).length > 1
9502
+ ) {
8795
9503
  // We generate a map of the filters we will use for our facet values queries
8796
- var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(function createFiltersMap(map, segment, level) {
8797
- return map.concat({
8798
- attribute: hierarchicalFacet.attributes[level],
8799
- value: level === 0 ? segment : [map[map.length - 1].value, segment].join(separator)
8800
- });
8801
- }, []);
9504
+ var filtersMap = currentRefinement[0]
9505
+ .split(separator)
9506
+ .slice(0, -1)
9507
+ .reduce(function createFiltersMap(map, segment, level) {
9508
+ return map.concat({
9509
+ attribute: hierarchicalFacet.attributes[level],
9510
+ value:
9511
+ level === 0
9512
+ ? segment
9513
+ : [map[map.length - 1].value, segment].join(separator),
9514
+ });
9515
+ }, []);
9516
+
8802
9517
  filtersMap.forEach(function (filter, level) {
8803
- var params = requestBuilder._getDisjunctiveFacetSearchParams(state, filter.attribute, level === 0);
9518
+ var params = requestBuilder._getDisjunctiveFacetSearchParams(
9519
+ state,
9520
+ filter.attribute,
9521
+ level === 0
9522
+ );
8804
9523
 
8805
9524
  // Keep facet filters unrelated to current hierarchical attributes
8806
9525
  function hasHierarchicalFacetFilter(value) {
@@ -8808,58 +9527,81 @@
8808
9527
  return attribute === value.split(':')[0];
8809
9528
  });
8810
9529
  }
8811
- var filteredFacetFilters = (params.facetFilters || []).reduce(function (acc, facetFilter) {
8812
- if (Array.isArray(facetFilter)) {
8813
- var filtered = facetFilter.filter(function (filterValue) {
8814
- return !hasHierarchicalFacetFilter(filterValue);
8815
- });
8816
- if (filtered.length > 0) {
8817
- acc.push(filtered);
9530
+
9531
+ var filteredFacetFilters = (params.facetFilters || []).reduce(
9532
+ function (acc, facetFilter) {
9533
+ if (Array.isArray(facetFilter)) {
9534
+ var filtered = facetFilter.filter(function (filterValue) {
9535
+ return !hasHierarchicalFacetFilter(filterValue);
9536
+ });
9537
+
9538
+ if (filtered.length > 0) {
9539
+ acc.push(filtered);
9540
+ }
8818
9541
  }
8819
- }
8820
- if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
8821
- acc.push(facetFilter);
8822
- }
8823
- return acc;
8824
- }, []);
9542
+
9543
+ if (
9544
+ typeof facetFilter === 'string' &&
9545
+ !hasHierarchicalFacetFilter(facetFilter)
9546
+ ) {
9547
+ acc.push(facetFilter);
9548
+ }
9549
+
9550
+ return acc;
9551
+ },
9552
+ []
9553
+ );
9554
+
8825
9555
  var parent = filtersMap[level - 1];
8826
9556
  if (level > 0) {
8827
- params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
9557
+ params.facetFilters = filteredFacetFilters.concat(
9558
+ parent.attribute + ':' + parent.value
9559
+ );
8828
9560
  } else {
8829
- params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
9561
+ params.facetFilters =
9562
+ filteredFacetFilters.length > 0
9563
+ ? filteredFacetFilters
9564
+ : undefined;
8830
9565
  }
8831
- queries.push({
8832
- indexName: index,
8833
- params: params
8834
- });
9566
+
9567
+ queries.push({ indexName: index, params: params });
8835
9568
  });
8836
9569
  }
8837
9570
  });
9571
+
8838
9572
  return queries;
8839
9573
  },
9574
+
8840
9575
  /**
8841
9576
  * Build search parameters used to fetch hits
8842
9577
  * @private
8843
9578
  * @param {SearchParameters} state The state from which to get the queries
8844
9579
  * @return {object.<string, any>} The search parameters for hits
8845
9580
  */
8846
- _getHitsSearchParams: function _getHitsSearchParams(state) {
8847
- var facets = state.facets.concat(state.disjunctiveFacets).concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
9581
+ _getHitsSearchParams: function (state) {
9582
+ var facets = state.facets
9583
+ .concat(state.disjunctiveFacets)
9584
+ .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
9585
+
8848
9586
  var facetFilters = requestBuilder._getFacetFilters(state);
8849
9587
  var numericFilters = requestBuilder._getNumericFilters(state);
8850
9588
  var tagFilters = requestBuilder._getTagFilters(state);
8851
9589
  var additionalParams = {
8852
9590
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
8853
- tagFilters: tagFilters
9591
+ tagFilters: tagFilters,
8854
9592
  };
9593
+
8855
9594
  if (facetFilters.length > 0) {
8856
9595
  additionalParams.facetFilters = facetFilters;
8857
9596
  }
9597
+
8858
9598
  if (numericFilters.length > 0) {
8859
9599
  additionalParams.numericFilters = numericFilters;
8860
9600
  }
8861
- return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
9601
+
9602
+ return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
8862
9603
  },
9604
+
8863
9605
  /**
8864
9606
  * Build search parameters used to fetch a disjunctive facet
8865
9607
  * @private
@@ -8868,33 +9610,53 @@
8868
9610
  * @param {boolean} hierarchicalRootLevel ?? FIXME
8869
9611
  * @return {object} The search parameters for a disjunctive facet
8870
9612
  */
8871
- _getDisjunctiveFacetSearchParams: function _getDisjunctiveFacetSearchParams(state, facet, hierarchicalRootLevel) {
8872
- var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
9613
+ _getDisjunctiveFacetSearchParams: function (
9614
+ state,
9615
+ facet,
9616
+ hierarchicalRootLevel
9617
+ ) {
9618
+ var facetFilters = requestBuilder._getFacetFilters(
9619
+ state,
9620
+ facet,
9621
+ hierarchicalRootLevel
9622
+ );
8873
9623
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
8874
9624
  var tagFilters = requestBuilder._getTagFilters(state);
8875
9625
  var additionalParams = {
8876
9626
  hitsPerPage: 0,
8877
9627
  page: 0,
8878
9628
  analytics: false,
8879
- clickAnalytics: false
9629
+ clickAnalytics: false,
8880
9630
  };
9631
+
8881
9632
  if (tagFilters.length > 0) {
8882
9633
  additionalParams.tagFilters = tagFilters;
8883
9634
  }
9635
+
8884
9636
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
9637
+
8885
9638
  if (hierarchicalFacet) {
8886
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, hierarchicalRootLevel);
9639
+ additionalParams.facets =
9640
+ requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
9641
+ state,
9642
+ hierarchicalFacet,
9643
+ hierarchicalRootLevel
9644
+ );
8887
9645
  } else {
8888
9646
  additionalParams.facets = facet;
8889
9647
  }
9648
+
8890
9649
  if (numericFilters.length > 0) {
8891
9650
  additionalParams.numericFilters = numericFilters;
8892
9651
  }
9652
+
8893
9653
  if (facetFilters.length > 0) {
8894
9654
  additionalParams.facetFilters = facetFilters;
8895
9655
  }
8896
- return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
9656
+
9657
+ return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
8897
9658
  },
9659
+
8898
9660
  /**
8899
9661
  * Return the numeric filters in an algolia request fashion
8900
9662
  * @private
@@ -8902,11 +9664,13 @@
8902
9664
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
8903
9665
  * @return {string[]} the numeric filters in the algolia format
8904
9666
  */
8905
- _getNumericFilters: function _getNumericFilters(state, facetName) {
9667
+ _getNumericFilters: function (state, facetName) {
8906
9668
  if (state.numericFilters) {
8907
9669
  return state.numericFilters;
8908
9670
  }
9671
+
8909
9672
  var numericFilters = [];
9673
+
8910
9674
  Object.keys(state.numericRefinements).forEach(function (attribute) {
8911
9675
  var operators = state.numericRefinements[attribute] || {};
8912
9676
  Object.keys(operators).forEach(function (operator) {
@@ -8925,20 +9689,24 @@
8925
9689
  }
8926
9690
  });
8927
9691
  });
9692
+
8928
9693
  return numericFilters;
8929
9694
  },
9695
+
8930
9696
  /**
8931
9697
  * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
8932
9698
  * @private
8933
9699
  * @param {SearchParameters} state the state from which to get the filters
8934
9700
  * @return {string} Tag filters in a single string
8935
9701
  */
8936
- _getTagFilters: function _getTagFilters(state) {
9702
+ _getTagFilters: function (state) {
8937
9703
  if (state.tagFilters) {
8938
9704
  return state.tagFilters;
8939
9705
  }
9706
+
8940
9707
  return state.tagRefinements.join(',');
8941
9708
  },
9709
+
8942
9710
  /**
8943
9711
  * Build facetFilters parameter based on current refinements. The array returned
8944
9712
  * contains strings representing the facet filters in the algolia format.
@@ -8948,8 +9716,9 @@
8948
9716
  * @param {boolean} [hierarchicalRootLevel] ?? FIXME
8949
9717
  * @return {array.<string>} The facet filters in the algolia format
8950
9718
  */
8951
- _getFacetFilters: function _getFacetFilters(state, facet, hierarchicalRootLevel) {
9719
+ _getFacetFilters: function (state, facet, hierarchicalRootLevel) {
8952
9720
  var facetFilters = [];
9721
+
8953
9722
  var facetsRefinements = state.facetsRefinements || {};
8954
9723
  Object.keys(facetsRefinements).forEach(function (facetName) {
8955
9724
  var facetValues = facetsRefinements[facetName] || [];
@@ -8957,6 +9726,7 @@
8957
9726
  facetFilters.push(facetName + ':' + facetValue);
8958
9727
  });
8959
9728
  });
9729
+
8960
9730
  var facetsExcludes = state.facetsExcludes || {};
8961
9731
  Object.keys(facetsExcludes).forEach(function (facetName) {
8962
9732
  var facetValues = facetsExcludes[facetName] || [];
@@ -8964,6 +9734,7 @@
8964
9734
  facetFilters.push(facetName + ':-' + facetValue);
8965
9735
  });
8966
9736
  });
9737
+
8967
9738
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
8968
9739
  Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
8969
9740
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
@@ -8971,18 +9742,24 @@
8971
9742
  return;
8972
9743
  }
8973
9744
  var orFilters = [];
9745
+
8974
9746
  facetValues.forEach(function (facetValue) {
8975
9747
  orFilters.push(facetName + ':' + facetValue);
8976
9748
  });
9749
+
8977
9750
  facetFilters.push(orFilters);
8978
9751
  });
8979
- var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
9752
+
9753
+ var hierarchicalFacetsRefinements =
9754
+ state.hierarchicalFacetsRefinements || {};
8980
9755
  Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
8981
9756
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
8982
9757
  var facetValue = facetValues[0];
9758
+
8983
9759
  if (facetValue === undefined) {
8984
9760
  return;
8985
9761
  }
9762
+
8986
9763
  var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
8987
9764
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
8988
9765
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -8993,9 +9770,16 @@
8993
9770
  if (facet === facetName) {
8994
9771
  // if we are at the root level already, no need to ask for facet values, we get them from
8995
9772
  // the hits query
8996
- if (facetValue.indexOf(separator) === -1 || !rootPath && hierarchicalRootLevel === true || rootPath && rootPath.split(separator).length === facetValue.split(separator).length) {
9773
+ if (
9774
+ facetValue.indexOf(separator) === -1 ||
9775
+ (!rootPath && hierarchicalRootLevel === true) ||
9776
+ (rootPath &&
9777
+ rootPath.split(separator).length ===
9778
+ facetValue.split(separator).length)
9779
+ ) {
8997
9780
  return;
8998
9781
  }
9782
+
8999
9783
  if (!rootPath) {
9000
9784
  attributesIndex = facetValue.split(separator).length - 2;
9001
9785
  facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
@@ -9003,67 +9787,100 @@
9003
9787
  attributesIndex = rootPath.split(separator).length - 1;
9004
9788
  facetValue = rootPath;
9005
9789
  }
9790
+
9006
9791
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
9007
9792
  } else {
9008
9793
  attributesIndex = facetValue.split(separator).length - 1;
9794
+
9009
9795
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
9010
9796
  }
9797
+
9011
9798
  if (attributeToRefine) {
9012
9799
  facetFilters.push([attributeToRefine + ':' + facetValue]);
9013
9800
  }
9014
9801
  });
9802
+
9015
9803
  return facetFilters;
9016
9804
  },
9017
- _getHitsHierarchicalFacetsAttributes: function _getHitsHierarchicalFacetsAttributes(state) {
9805
+
9806
+ _getHitsHierarchicalFacetsAttributes: function (state) {
9018
9807
  var out = [];
9808
+
9019
9809
  return state.hierarchicalFacets.reduce(
9020
- // ask for as much levels as there's hierarchical refinements
9021
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
9022
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
9023
-
9024
- // if no refinement, ask for root level
9025
- if (!hierarchicalRefinement) {
9026
- allAttributes.push(hierarchicalFacet.attributes[0]);
9027
- return allAttributes;
9028
- }
9029
- var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9030
- var level = hierarchicalRefinement.split(separator).length;
9031
- var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
9032
- return allAttributes.concat(newAttributes);
9033
- }, out);
9810
+ // ask for as much levels as there's hierarchical refinements
9811
+ function getHitsAttributesForHierarchicalFacet(
9812
+ allAttributes,
9813
+ hierarchicalFacet
9814
+ ) {
9815
+ var hierarchicalRefinement = state.getHierarchicalRefinement(
9816
+ hierarchicalFacet.name
9817
+ )[0];
9818
+
9819
+ // if no refinement, ask for root level
9820
+ if (!hierarchicalRefinement) {
9821
+ allAttributes.push(hierarchicalFacet.attributes[0]);
9822
+ return allAttributes;
9823
+ }
9824
+
9825
+ var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9826
+ var level = hierarchicalRefinement.split(separator).length;
9827
+ var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
9828
+
9829
+ return allAttributes.concat(newAttributes);
9830
+ },
9831
+ out
9832
+ );
9034
9833
  },
9035
- _getDisjunctiveHierarchicalFacetAttribute: function _getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, rootLevel) {
9834
+
9835
+ _getDisjunctiveHierarchicalFacetAttribute: function (
9836
+ state,
9837
+ hierarchicalFacet,
9838
+ rootLevel
9839
+ ) {
9036
9840
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9037
9841
  if (rootLevel === true) {
9038
9842
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
9039
9843
  var attributeIndex = 0;
9844
+
9040
9845
  if (rootPath) {
9041
9846
  attributeIndex = rootPath.split(separator).length;
9042
9847
  }
9043
9848
  return [hierarchicalFacet.attributes[attributeIndex]];
9044
9849
  }
9045
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
9850
+
9851
+ var hierarchicalRefinement =
9852
+ state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
9046
9853
  // if refinement is 'beers > IPA > Flying dog',
9047
9854
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
9048
9855
 
9049
9856
  var parentLevel = hierarchicalRefinement.split(separator).length - 1;
9050
9857
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
9051
9858
  },
9052
- getSearchForFacetQuery: function getSearchForFacetQuery(facetName, query, maxFacetHits, state) {
9053
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ? state.clearRefinements(facetName) : state;
9859
+
9860
+ getSearchForFacetQuery: function (facetName, query, maxFacetHits, state) {
9861
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
9862
+ ? state.clearRefinements(facetName)
9863
+ : state;
9054
9864
  var searchForFacetSearchParameters = {
9055
9865
  facetQuery: query,
9056
- facetName: facetName
9866
+ facetName: facetName,
9057
9867
  };
9058
9868
  if (typeof maxFacetHits === 'number') {
9059
9869
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
9060
9870
  }
9061
- return sortObject(merge$1({}, requestBuilder._getHitsSearchParams(stateForSearchForFacetValues), searchForFacetSearchParameters));
9062
- }
9871
+ return sortObject(
9872
+ merge_1(
9873
+ {},
9874
+ requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
9875
+ searchForFacetSearchParameters
9876
+ )
9877
+ );
9878
+ },
9063
9879
  };
9880
+
9064
9881
  var requestBuilder_1 = requestBuilder;
9065
9882
 
9066
- var version = '3.13.3';
9883
+ var version = '3.13.5';
9067
9884
 
9068
9885
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
9069
9886
 
@@ -9174,6 +9991,7 @@
9174
9991
  if (typeof client.addAlgoliaAgent === 'function') {
9175
9992
  client.addAlgoliaAgent('JS Helper (' + version + ')');
9176
9993
  }
9994
+
9177
9995
  this.setClient(client);
9178
9996
  var opts = options || {};
9179
9997
  opts.index = index;
@@ -9184,6 +10002,7 @@
9184
10002
  this.derivedHelpers = [];
9185
10003
  this._currentNbQueries = 0;
9186
10004
  }
10005
+
9187
10006
  inherits_1(AlgoliaSearchHelper, events);
9188
10007
 
9189
10008
  /**
@@ -9198,15 +10017,12 @@
9198
10017
  * @chainable
9199
10018
  */
9200
10019
  AlgoliaSearchHelper.prototype.search = function () {
9201
- this._search({
9202
- onlyWithDerivedHelpers: false
9203
- });
10020
+ this._search({ onlyWithDerivedHelpers: false });
9204
10021
  return this;
9205
10022
  };
10023
+
9206
10024
  AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
9207
- this._search({
9208
- onlyWithDerivedHelpers: true
9209
- });
10025
+ this._search({ onlyWithDerivedHelpers: true });
9210
10026
  return this;
9211
10027
  };
9212
10028
 
@@ -9257,43 +10073,58 @@
9257
10073
  * }
9258
10074
  */
9259
10075
  AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
9260
- var tempState = !options ? this.state : this.state.setQueryParameters(options);
10076
+ var tempState = !options
10077
+ ? this.state
10078
+ : this.state.setQueryParameters(options);
9261
10079
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
9262
10080
  // eslint-disable-next-line consistent-this
9263
10081
  var self = this;
10082
+
9264
10083
  this._currentNbQueries++;
10084
+
9265
10085
  this.emit('searchOnce', {
9266
- state: tempState
10086
+ state: tempState,
9267
10087
  });
10088
+
9268
10089
  if (cb) {
9269
- this.client.search(queries).then(function (content) {
9270
- self._currentNbQueries--;
9271
- if (self._currentNbQueries === 0) {
9272
- self.emit('searchQueueEmpty');
9273
- }
9274
- cb(null, new SearchResults_1(tempState, content.results), tempState);
9275
- }).catch(function (err) {
9276
- self._currentNbQueries--;
9277
- if (self._currentNbQueries === 0) {
9278
- self.emit('searchQueueEmpty');
9279
- }
9280
- cb(err, null, tempState);
9281
- });
10090
+ this.client
10091
+ .search(queries)
10092
+ .then(function (content) {
10093
+ self._currentNbQueries--;
10094
+ if (self._currentNbQueries === 0) {
10095
+ self.emit('searchQueueEmpty');
10096
+ }
10097
+
10098
+ cb(null, new SearchResults_1(tempState, content.results), tempState);
10099
+ })
10100
+ .catch(function (err) {
10101
+ self._currentNbQueries--;
10102
+ if (self._currentNbQueries === 0) {
10103
+ self.emit('searchQueueEmpty');
10104
+ }
10105
+
10106
+ cb(err, null, tempState);
10107
+ });
10108
+
9282
10109
  return undefined;
9283
10110
  }
9284
- return this.client.search(queries).then(function (content) {
9285
- self._currentNbQueries--;
9286
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9287
- return {
9288
- content: new SearchResults_1(tempState, content.results),
9289
- state: tempState,
9290
- _originalResponse: content
9291
- };
9292
- }, function (e) {
9293
- self._currentNbQueries--;
9294
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9295
- throw e;
9296
- });
10111
+
10112
+ return this.client.search(queries).then(
10113
+ function (content) {
10114
+ self._currentNbQueries--;
10115
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10116
+ return {
10117
+ content: new SearchResults_1(tempState, content.results),
10118
+ state: tempState,
10119
+ _originalResponse: content,
10120
+ };
10121
+ },
10122
+ function (e) {
10123
+ self._currentNbQueries--;
10124
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10125
+ throw e;
10126
+ }
10127
+ );
9297
10128
  };
9298
10129
 
9299
10130
  /**
@@ -9316,13 +10147,23 @@
9316
10147
  return Promise.resolve([]);
9317
10148
  }
9318
10149
  var derivedState = derivedHelper.getModifiedState(state);
9319
- var data = merge$1({
9320
- attributesForPrediction: options.attributesForPrediction,
9321
- nbHits: options.nbHits
9322
- }, {
9323
- params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), ['attributesToSnippet', 'hitsPerPage', 'restrictSearchableAttributes', 'snippetEllipsisText'])
9324
- });
9325
- var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
10150
+ var data = merge_1(
10151
+ {
10152
+ attributesForPrediction: options.attributesForPrediction,
10153
+ nbHits: options.nbHits,
10154
+ },
10155
+ {
10156
+ params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
10157
+ 'attributesToSnippet',
10158
+ 'hitsPerPage',
10159
+ 'restrictSearchableAttributes',
10160
+ 'snippetEllipsisText',
10161
+ ]),
10162
+ }
10163
+ );
10164
+
10165
+ var errorMessage =
10166
+ 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
9326
10167
  if (typeof this.client.initIndex !== 'function') {
9327
10168
  throw new Error(errorMessage);
9328
10169
  }
@@ -9367,60 +10208,93 @@
9367
10208
  * it in the generated query.
9368
10209
  * @return {promise.<FacetSearchResult>} the results of the search
9369
10210
  */
9370
- AlgoliaSearchHelper.prototype.searchForFacetValues = function (facet, query, maxFacetHits, userState) {
10211
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
10212
+ facet,
10213
+ query,
10214
+ maxFacetHits,
10215
+ userState
10216
+ ) {
9371
10217
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
9372
10218
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
9373
- if (!clientHasSFFV && !clientHasInitIndex && typeof this.client.search !== 'function') {
9374
- throw new Error('search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues');
10219
+ if (
10220
+ !clientHasSFFV &&
10221
+ !clientHasInitIndex &&
10222
+ typeof this.client.search !== 'function'
10223
+ ) {
10224
+ throw new Error(
10225
+ 'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
10226
+ );
9375
10227
  }
10228
+
9376
10229
  var state = this.state.setQueryParameters(userState || {});
9377
10230
  var isDisjunctive = state.isDisjunctiveFacet(facet);
9378
- var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
10231
+ var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
10232
+ facet,
10233
+ query,
10234
+ maxFacetHits,
10235
+ state
10236
+ );
10237
+
9379
10238
  this._currentNbQueries++;
9380
10239
  // eslint-disable-next-line consistent-this
9381
10240
  var self = this;
9382
10241
  var searchForFacetValuesPromise;
9383
10242
  // newer algoliasearch ^3.27.1 - ~4.0.0
9384
10243
  if (clientHasSFFV) {
9385
- searchForFacetValuesPromise = this.client.searchForFacetValues([{
9386
- indexName: state.index,
9387
- params: algoliaQuery
9388
- }]);
10244
+ searchForFacetValuesPromise = this.client.searchForFacetValues([
10245
+ { indexName: state.index, params: algoliaQuery },
10246
+ ]);
9389
10247
  // algoliasearch < 3.27.1
9390
10248
  } else if (clientHasInitIndex) {
9391
- searchForFacetValuesPromise = this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
10249
+ searchForFacetValuesPromise = this.client
10250
+ .initIndex(state.index)
10251
+ .searchForFacetValues(algoliaQuery);
9392
10252
  // algoliasearch ~5.0.0
9393
10253
  } else {
9394
10254
  // @MAJOR only use client.search
9395
10255
  delete algoliaQuery.facetName;
9396
- searchForFacetValuesPromise = this.client.search([{
9397
- type: 'facet',
9398
- facet: facet,
9399
- indexName: state.index,
9400
- params: algoliaQuery
9401
- }]).then(function processResponse(response) {
9402
- return response.results[0];
9403
- });
10256
+ searchForFacetValuesPromise = this.client
10257
+ .search([
10258
+ {
10259
+ type: 'facet',
10260
+ facet: facet,
10261
+ indexName: state.index,
10262
+ params: algoliaQuery,
10263
+ },
10264
+ ])
10265
+ .then(function processResponse(response) {
10266
+ return response.results[0];
10267
+ });
9404
10268
  }
10269
+
9405
10270
  this.emit('searchForFacetValues', {
9406
10271
  state: state,
9407
10272
  facet: facet,
9408
- query: query
9409
- });
9410
- return searchForFacetValuesPromise.then(function addIsRefined(content) {
9411
- self._currentNbQueries--;
9412
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9413
- content = Array.isArray(content) ? content[0] : content;
9414
- content.facetHits.forEach(function (f) {
9415
- f.escapedValue = escapeFacetValue$4(f.value);
9416
- f.isRefined = isDisjunctive ? state.isDisjunctiveFacetRefined(facet, f.escapedValue) : state.isFacetRefined(facet, f.escapedValue);
9417
- });
9418
- return content;
9419
- }, function (e) {
9420
- self._currentNbQueries--;
9421
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9422
- throw e;
10273
+ query: query,
9423
10274
  });
10275
+
10276
+ return searchForFacetValuesPromise.then(
10277
+ function addIsRefined(content) {
10278
+ self._currentNbQueries--;
10279
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10280
+
10281
+ content = Array.isArray(content) ? content[0] : content;
10282
+
10283
+ content.facetHits.forEach(function (f) {
10284
+ f.escapedValue = escapeFacetValue$4(f.value);
10285
+ f.isRefined = isDisjunctive
10286
+ ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
10287
+ : state.isFacetRefined(facet, f.escapedValue);
10288
+ });
10289
+
10290
+ return content;
10291
+ },
10292
+ function (e) {
10293
+ self._currentNbQueries--;
10294
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10295
+ throw e;
10296
+ }
10297
+ );
9424
10298
  };
9425
10299
 
9426
10300
  /**
@@ -9435,8 +10309,9 @@
9435
10309
  AlgoliaSearchHelper.prototype.setQuery = function (q) {
9436
10310
  this._change({
9437
10311
  state: this.state.resetPage().setQuery(q),
9438
- isPageReset: true
10312
+ isPageReset: true,
9439
10313
  });
10314
+
9440
10315
  return this;
9441
10316
  };
9442
10317
 
@@ -9466,8 +10341,9 @@
9466
10341
  AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
9467
10342
  this._change({
9468
10343
  state: this.state.resetPage().clearRefinements(name),
9469
- isPageReset: true
10344
+ isPageReset: true,
9470
10345
  });
10346
+
9471
10347
  return this;
9472
10348
  };
9473
10349
 
@@ -9482,8 +10358,9 @@
9482
10358
  AlgoliaSearchHelper.prototype.clearTags = function () {
9483
10359
  this._change({
9484
10360
  state: this.state.resetPage().clearTags(),
9485
- isPageReset: true
10361
+ isPageReset: true,
9486
10362
  });
10363
+
9487
10364
  return this;
9488
10365
  };
9489
10366
 
@@ -9498,11 +10375,15 @@
9498
10375
  * @fires change
9499
10376
  * @chainable
9500
10377
  */
9501
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (facet, value) {
10378
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
10379
+ facet,
10380
+ value
10381
+ ) {
9502
10382
  this._change({
9503
10383
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
9504
- isPageReset: true
10384
+ isPageReset: true,
9505
10385
  });
10386
+
9506
10387
  return this;
9507
10388
  };
9508
10389
 
@@ -9527,11 +10408,15 @@
9527
10408
  * @chainable
9528
10409
  * @fires change
9529
10410
  */
9530
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (facet, path) {
10411
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
10412
+ facet,
10413
+ path
10414
+ ) {
9531
10415
  this._change({
9532
10416
  state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
9533
- isPageReset: true
10417
+ isPageReset: true,
9534
10418
  });
10419
+
9535
10420
  return this;
9536
10421
  };
9537
10422
 
@@ -9547,11 +10432,18 @@
9547
10432
  * @fires change
9548
10433
  * @chainable
9549
10434
  */
9550
- AlgoliaSearchHelper.prototype.addNumericRefinement = function (attribute, operator, value) {
10435
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (
10436
+ attribute,
10437
+ operator,
10438
+ value
10439
+ ) {
9551
10440
  this._change({
9552
- state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
9553
- isPageReset: true
10441
+ state: this.state
10442
+ .resetPage()
10443
+ .addNumericRefinement(attribute, operator, value),
10444
+ isPageReset: true,
9554
10445
  });
10446
+
9555
10447
  return this;
9556
10448
  };
9557
10449
 
@@ -9569,8 +10461,9 @@
9569
10461
  AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
9570
10462
  this._change({
9571
10463
  state: this.state.resetPage().addFacetRefinement(facet, value),
9572
- isPageReset: true
10464
+ isPageReset: true,
9573
10465
  });
10466
+
9574
10467
  return this;
9575
10468
  };
9576
10469
 
@@ -9596,8 +10489,9 @@
9596
10489
  AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
9597
10490
  this._change({
9598
10491
  state: this.state.resetPage().addExcludeRefinement(facet, value),
9599
- isPageReset: true
10492
+ isPageReset: true,
9600
10493
  });
10494
+
9601
10495
  return this;
9602
10496
  };
9603
10497
 
@@ -9622,8 +10516,9 @@
9622
10516
  AlgoliaSearchHelper.prototype.addTag = function (tag) {
9623
10517
  this._change({
9624
10518
  state: this.state.resetPage().addTagRefinement(tag),
9625
- isPageReset: true
10519
+ isPageReset: true,
9626
10520
  });
10521
+
9627
10522
  return this;
9628
10523
  };
9629
10524
 
@@ -9645,11 +10540,18 @@
9645
10540
  * @fires change
9646
10541
  * @chainable
9647
10542
  */
9648
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function (attribute, operator, value) {
10543
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
10544
+ attribute,
10545
+ operator,
10546
+ value
10547
+ ) {
9649
10548
  this._change({
9650
- state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
9651
- isPageReset: true
10549
+ state: this.state
10550
+ .resetPage()
10551
+ .removeNumericRefinement(attribute, operator, value),
10552
+ isPageReset: true,
9652
10553
  });
10554
+
9653
10555
  return this;
9654
10556
  };
9655
10557
 
@@ -9667,11 +10569,17 @@
9667
10569
  * @fires change
9668
10570
  * @chainable
9669
10571
  */
9670
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (facet, value) {
10572
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
10573
+ facet,
10574
+ value
10575
+ ) {
9671
10576
  this._change({
9672
- state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
9673
- isPageReset: true
10577
+ state: this.state
10578
+ .resetPage()
10579
+ .removeDisjunctiveFacetRefinement(facet, value),
10580
+ isPageReset: true,
9674
10581
  });
10582
+
9675
10583
  return this;
9676
10584
  };
9677
10585
 
@@ -9691,11 +10599,14 @@
9691
10599
  * @fires change
9692
10600
  * @chainable
9693
10601
  */
9694
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (facet) {
10602
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
10603
+ facet
10604
+ ) {
9695
10605
  this._change({
9696
10606
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
9697
- isPageReset: true
10607
+ isPageReset: true,
9698
10608
  });
10609
+
9699
10610
  return this;
9700
10611
  };
9701
10612
 
@@ -9716,8 +10627,9 @@
9716
10627
  AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
9717
10628
  this._change({
9718
10629
  state: this.state.resetPage().removeFacetRefinement(facet, value),
9719
- isPageReset: true
10630
+ isPageReset: true,
9720
10631
  });
10632
+
9721
10633
  return this;
9722
10634
  };
9723
10635
 
@@ -9746,8 +10658,9 @@
9746
10658
  AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
9747
10659
  this._change({
9748
10660
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
9749
- isPageReset: true
10661
+ isPageReset: true,
9750
10662
  });
10663
+
9751
10664
  return this;
9752
10665
  };
9753
10666
 
@@ -9772,8 +10685,9 @@
9772
10685
  AlgoliaSearchHelper.prototype.removeTag = function (tag) {
9773
10686
  this._change({
9774
10687
  state: this.state.resetPage().removeTagRefinement(tag),
9775
- isPageReset: true
10688
+ isPageReset: true,
9776
10689
  });
10690
+
9777
10691
  return this;
9778
10692
  };
9779
10693
 
@@ -9791,8 +10705,9 @@
9791
10705
  AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
9792
10706
  this._change({
9793
10707
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
9794
- isPageReset: true
10708
+ isPageReset: true,
9795
10709
  });
10710
+
9796
10711
  return this;
9797
10712
  };
9798
10713
 
@@ -9840,8 +10755,9 @@
9840
10755
  AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
9841
10756
  this._change({
9842
10757
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
9843
- isPageReset: true
10758
+ isPageReset: true,
9844
10759
  });
10760
+
9845
10761
  return this;
9846
10762
  };
9847
10763
 
@@ -9866,8 +10782,9 @@
9866
10782
  AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
9867
10783
  this._change({
9868
10784
  state: this.state.resetPage().toggleTagRefinement(tag),
9869
- isPageReset: true
10785
+ isPageReset: true,
9870
10786
  });
10787
+
9871
10788
  return this;
9872
10789
  };
9873
10790
 
@@ -9908,10 +10825,12 @@
9908
10825
  */
9909
10826
  function setCurrentPage(page) {
9910
10827
  if (page < 0) throw new Error('Page requested below 0.');
10828
+
9911
10829
  this._change({
9912
10830
  state: this.state.setPage(page),
9913
- isPageReset: false
10831
+ isPageReset: false,
9914
10832
  });
10833
+
9915
10834
  return this;
9916
10835
  }
9917
10836
 
@@ -9947,8 +10866,9 @@
9947
10866
  AlgoliaSearchHelper.prototype.setIndex = function (name) {
9948
10867
  this._change({
9949
10868
  state: this.state.resetPage().setIndex(name),
9950
- isPageReset: true
10869
+ isPageReset: true,
9951
10870
  });
10871
+
9952
10872
  return this;
9953
10873
  };
9954
10874
 
@@ -9972,8 +10892,9 @@
9972
10892
  AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
9973
10893
  this._change({
9974
10894
  state: this.state.resetPage().setQueryParameter(parameter, value),
9975
- isPageReset: true
10895
+ isPageReset: true,
9976
10896
  });
10897
+
9977
10898
  return this;
9978
10899
  };
9979
10900
 
@@ -9987,8 +10908,9 @@
9987
10908
  AlgoliaSearchHelper.prototype.setState = function (newState) {
9988
10909
  this._change({
9989
10910
  state: SearchParameters_1.make(newState),
9990
- isPageReset: false
10911
+ isPageReset: false,
9991
10912
  });
10913
+
9992
10914
  return this;
9993
10915
  };
9994
10916
 
@@ -10009,10 +10931,11 @@
10009
10931
  * }
10010
10932
  * @chainable
10011
10933
  */
10012
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function (newState) {
10013
- this.state = new SearchParameters_1(newState);
10014
- return this;
10015
- };
10934
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
10935
+ function (newState) {
10936
+ this.state = new SearchParameters_1(newState);
10937
+ return this;
10938
+ };
10016
10939
 
10017
10940
  /**
10018
10941
  * Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
@@ -10114,6 +11037,7 @@
10114
11037
  AlgoliaSearchHelper.prototype.getIndex = function () {
10115
11038
  return this.state.index;
10116
11039
  };
11040
+
10117
11041
  function getCurrentPage() {
10118
11042
  return this.state.page;
10119
11043
  }
@@ -10186,39 +11110,49 @@
10186
11110
  */
10187
11111
  AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
10188
11112
  var refinements = [];
11113
+
10189
11114
  if (this.state.isConjunctiveFacet(facetName)) {
10190
11115
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
11116
+
10191
11117
  conjRefinements.forEach(function (r) {
10192
11118
  refinements.push({
10193
11119
  value: r,
10194
- type: 'conjunctive'
11120
+ type: 'conjunctive',
10195
11121
  });
10196
11122
  });
11123
+
10197
11124
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
11125
+
10198
11126
  excludeRefinements.forEach(function (r) {
10199
11127
  refinements.push({
10200
11128
  value: r,
10201
- type: 'exclude'
11129
+ type: 'exclude',
10202
11130
  });
10203
11131
  });
10204
11132
  } else if (this.state.isDisjunctiveFacet(facetName)) {
10205
- var disjunctiveRefinements = this.state.getDisjunctiveRefinements(facetName);
11133
+ var disjunctiveRefinements =
11134
+ this.state.getDisjunctiveRefinements(facetName);
11135
+
10206
11136
  disjunctiveRefinements.forEach(function (r) {
10207
11137
  refinements.push({
10208
11138
  value: r,
10209
- type: 'disjunctive'
11139
+ type: 'disjunctive',
10210
11140
  });
10211
11141
  });
10212
11142
  }
11143
+
10213
11144
  var numericRefinements = this.state.getNumericRefinements(facetName);
11145
+
10214
11146
  Object.keys(numericRefinements).forEach(function (operator) {
10215
11147
  var value = numericRefinements[operator];
11148
+
10216
11149
  refinements.push({
10217
11150
  value: value,
10218
11151
  operator: operator,
10219
- type: 'numeric'
11152
+ type: 'numeric',
10220
11153
  });
10221
11154
  });
11155
+
10222
11156
  return refinements;
10223
11157
  };
10224
11158
 
@@ -10228,7 +11162,10 @@
10228
11162
  * @param {string} operator operator applied on the refined values
10229
11163
  * @return {Array.<number|number[]>} refined values
10230
11164
  */
10231
- AlgoliaSearchHelper.prototype.getNumericRefinement = function (attribute, operator) {
11165
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (
11166
+ attribute,
11167
+ operator
11168
+ ) {
10232
11169
  return this.state.getNumericRefinement(attribute, operator);
10233
11170
  };
10234
11171
 
@@ -10237,7 +11174,9 @@
10237
11174
  * @param {string} facetName Hierarchical facet name
10238
11175
  * @return {array.<string>} the path as an array of string
10239
11176
  */
10240
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (facetName) {
11177
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
11178
+ facetName
11179
+ ) {
10241
11180
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
10242
11181
  };
10243
11182
 
@@ -10257,48 +11196,65 @@
10257
11196
  var state = this.state;
10258
11197
  var states = [];
10259
11198
  var mainQueries = [];
11199
+
10260
11200
  if (!options.onlyWithDerivedHelpers) {
10261
11201
  mainQueries = requestBuilder_1._getQueries(state.index, state);
11202
+
10262
11203
  states.push({
10263
11204
  state: state,
10264
11205
  queriesCount: mainQueries.length,
10265
- helper: this
11206
+ helper: this,
10266
11207
  });
11208
+
10267
11209
  this.emit('search', {
10268
11210
  state: state,
10269
- results: this.lastResults
11211
+ results: this.lastResults,
10270
11212
  });
10271
11213
  }
11214
+
10272
11215
  var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
10273
11216
  var derivedState = derivedHelper.getModifiedState(state);
10274
- var derivedStateQueries = derivedState.index ? requestBuilder_1._getQueries(derivedState.index, derivedState) : [];
11217
+ var derivedStateQueries = derivedState.index
11218
+ ? requestBuilder_1._getQueries(derivedState.index, derivedState)
11219
+ : [];
11220
+
10275
11221
  states.push({
10276
11222
  state: derivedState,
10277
11223
  queriesCount: derivedStateQueries.length,
10278
- helper: derivedHelper
11224
+ helper: derivedHelper,
10279
11225
  });
11226
+
10280
11227
  derivedHelper.emit('search', {
10281
11228
  state: derivedState,
10282
- results: derivedHelper.lastResults
11229
+ results: derivedHelper.lastResults,
10283
11230
  });
11231
+
10284
11232
  return derivedStateQueries;
10285
11233
  });
11234
+
10286
11235
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
11236
+
10287
11237
  var queryId = this._queryId++;
10288
11238
  this._currentNbQueries++;
11239
+
10289
11240
  if (!queries.length) {
10290
- return Promise.resolve({
10291
- results: []
10292
- }).then(this._dispatchAlgoliaResponse.bind(this, states, queryId));
11241
+ return Promise.resolve({ results: [] }).then(
11242
+ this._dispatchAlgoliaResponse.bind(this, states, queryId)
11243
+ );
10293
11244
  }
11245
+
10294
11246
  try {
10295
- this.client.search(queries).then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
11247
+ this.client
11248
+ .search(queries)
11249
+ .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
11250
+ .catch(this._dispatchAlgoliaError.bind(this, queryId));
10296
11251
  } catch (error) {
10297
11252
  // If we reach this part, we're in an internal error state
10298
11253
  this.emit('error', {
10299
- error: error
11254
+ error: error,
10300
11255
  });
10301
11256
  }
11257
+
10302
11258
  return undefined;
10303
11259
  };
10304
11260
 
@@ -10312,50 +11268,79 @@
10312
11268
  * @param {object} content content of the response
10313
11269
  * @return {undefined}
10314
11270
  */
10315
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (states, queryId, content) {
11271
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
11272
+ states,
11273
+ queryId,
11274
+ content
11275
+ ) {
10316
11276
  // @TODO remove the number of outdated queries discarded instead of just one
10317
11277
 
10318
11278
  if (queryId < this._lastQueryIdReceived) {
10319
11279
  // Outdated answer
10320
11280
  return;
10321
11281
  }
11282
+
10322
11283
  this._currentNbQueries -= queryId - this._lastQueryIdReceived;
10323
11284
  this._lastQueryIdReceived = queryId;
11285
+
10324
11286
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
11287
+
10325
11288
  var results = content.results.slice();
11289
+
10326
11290
  states.forEach(function (s) {
10327
11291
  var state = s.state;
10328
11292
  var queriesCount = s.queriesCount;
10329
11293
  var helper = s.helper;
10330
11294
  var specificResults = results.splice(0, queriesCount);
11295
+
10331
11296
  if (!state.index) {
10332
11297
  helper.emit('result', {
10333
11298
  results: null,
10334
- state: state
11299
+ state: state,
10335
11300
  });
10336
11301
  return;
10337
11302
  }
11303
+
10338
11304
  helper.lastResults = new SearchResults_1(state, specificResults);
11305
+
10339
11306
  helper.emit('result', {
10340
11307
  results: helper.lastResults,
10341
- state: state
11308
+ state: state,
10342
11309
  });
10343
11310
  });
10344
11311
  };
10345
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (queryId, error) {
11312
+
11313
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
11314
+ queryId,
11315
+ error
11316
+ ) {
10346
11317
  if (queryId < this._lastQueryIdReceived) {
10347
11318
  // Outdated answer
10348
11319
  return;
10349
11320
  }
11321
+
10350
11322
  this._currentNbQueries -= queryId - this._lastQueryIdReceived;
10351
11323
  this._lastQueryIdReceived = queryId;
11324
+
10352
11325
  this.emit('error', {
10353
- error: error
11326
+ error: error,
10354
11327
  });
11328
+
10355
11329
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
10356
11330
  };
10357
- AlgoliaSearchHelper.prototype.containsRefinement = function (query, facetFilters, numericFilters, tagFilters) {
10358
- return query || facetFilters.length !== 0 || numericFilters.length !== 0 || tagFilters.length !== 0;
11331
+
11332
+ AlgoliaSearchHelper.prototype.containsRefinement = function (
11333
+ query,
11334
+ facetFilters,
11335
+ numericFilters,
11336
+ tagFilters
11337
+ ) {
11338
+ return (
11339
+ query ||
11340
+ facetFilters.length !== 0 ||
11341
+ numericFilters.length !== 0 ||
11342
+ tagFilters.length !== 0
11343
+ );
10359
11344
  };
10360
11345
 
10361
11346
  /**
@@ -10365,17 +11350,23 @@
10365
11350
  * @return {boolean} true if there are refinements on this attribute
10366
11351
  */
10367
11352
  AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
10368
- return this.state.disjunctiveRefinements[facet] && this.state.disjunctiveRefinements[facet].length > 0;
11353
+ return (
11354
+ this.state.disjunctiveRefinements[facet] &&
11355
+ this.state.disjunctiveRefinements[facet].length > 0
11356
+ );
10369
11357
  };
11358
+
10370
11359
  AlgoliaSearchHelper.prototype._change = function (event) {
10371
11360
  var state = event.state;
10372
11361
  var isPageReset = event.isPageReset;
11362
+
10373
11363
  if (state !== this.state) {
10374
11364
  this.state = state;
11365
+
10375
11366
  this.emit('change', {
10376
11367
  state: this.state,
10377
11368
  results: this.lastResults,
10378
- isPageReset: isPageReset
11369
+ isPageReset: isPageReset,
10379
11370
  });
10380
11371
  }
10381
11372
  };
@@ -10397,10 +11388,12 @@
10397
11388
  */
10398
11389
  AlgoliaSearchHelper.prototype.setClient = function (newClient) {
10399
11390
  if (this.client === newClient) return this;
11391
+
10400
11392
  if (typeof newClient.addAlgoliaAgent === 'function') {
10401
11393
  newClient.addAlgoliaAgent('JS Helper (' + version + ')');
10402
11394
  }
10403
11395
  this.client = newClient;
11396
+
10404
11397
  return this;
10405
11398
  };
10406
11399
 
@@ -10539,6 +11532,7 @@
10539
11532
  * @type {SearchResults}
10540
11533
  */
10541
11534
  algoliasearchHelper.SearchResults = SearchResults_1;
11535
+
10542
11536
  var algoliasearchHelper_1 = algoliasearchHelper;
10543
11537
 
10544
11538
  var withUsage$l = createDocumentationMessageGenerator({
@@ -11893,7 +12887,7 @@
11893
12887
  return obj;
11894
12888
  };
11895
12889
 
11896
- var merge$2 = function merge(target, source, options) {
12890
+ var merge$1 = function merge(target, source, options) {
11897
12891
  /* eslint no-param-reassign: 0 */
11898
12892
  if (!source) {
11899
12893
  return target;
@@ -12097,7 +13091,7 @@
12097
13091
  isBuffer: isBuffer,
12098
13092
  isRegExp: isRegExp,
12099
13093
  maybeMap: maybeMap,
12100
- merge: merge$2
13094
+ merge: merge$1
12101
13095
  };
12102
13096
 
12103
13097
  var has$1 = Object.prototype.hasOwnProperty;
@@ -13588,7 +14582,7 @@
13588
14582
  };
13589
14583
  }
13590
14584
 
13591
- var version$1 = '4.56.6';
14585
+ var version$1 = '4.56.7';
13592
14586
 
13593
14587
  var withUsage$r = createDocumentationMessageGenerator({
13594
14588
  name: 'instantsearch'