react-instantsearch-core 6.40.0 → 6.40.2

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.
@@ -873,7 +873,7 @@
873
873
  });
874
874
  }
875
875
 
876
- var version = '6.40.0';
876
+ var version = '6.40.2';
877
877
 
878
878
  function translatable(defaultTranslations) {
879
879
  return function (Composed) {
@@ -1215,45 +1215,32 @@
1215
1215
  });
1216
1216
 
1217
1217
  function clone(value) {
1218
- if (typeof value === 'object' && value !== null) {
1218
+ if (_typeof(value) === 'object' && value !== null) {
1219
1219
  return _merge(Array.isArray(value) ? [] : {}, value);
1220
1220
  }
1221
1221
  return value;
1222
1222
  }
1223
-
1224
1223
  function isObjectOrArrayOrFunction(value) {
1225
- return (
1226
- typeof value === 'function' ||
1227
- Array.isArray(value) ||
1228
- Object.prototype.toString.call(value) === '[object Object]'
1229
- );
1224
+ return typeof value === 'function' || Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]';
1230
1225
  }
1231
-
1232
1226
  function _merge(target, source) {
1233
1227
  if (target === source) {
1234
1228
  return target;
1235
1229
  }
1236
1230
 
1231
+ // eslint-disable-next-line no-restricted-syntax
1237
1232
  for (var key in source) {
1238
- if (
1239
- !Object.prototype.hasOwnProperty.call(source, key) ||
1240
- key === '__proto__' ||
1241
- key === 'constructor'
1242
- ) {
1233
+ if (!Object.prototype.hasOwnProperty.call(source, key) || key === '__proto__' || key === 'constructor') {
1234
+ // eslint-disable-next-line no-continue
1243
1235
  continue;
1244
1236
  }
1245
-
1246
1237
  var sourceVal = source[key];
1247
1238
  var targetVal = target[key];
1248
-
1249
1239
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
1240
+ // eslint-disable-next-line no-continue
1250
1241
  continue;
1251
1242
  }
1252
-
1253
- if (
1254
- isObjectOrArrayOrFunction(targetVal) &&
1255
- isObjectOrArrayOrFunction(sourceVal)
1256
- ) {
1243
+ if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
1257
1244
  target[key] = _merge(targetVal, sourceVal);
1258
1245
  } else {
1259
1246
  target[key] = clone(sourceVal);
@@ -1273,35 +1260,34 @@
1273
1260
  * - treats sparse arrays as sparse
1274
1261
  * - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
1275
1262
  *
1276
- * @param {Object} object The destination object.
1263
+ * @param {Object} target The destination object.
1277
1264
  * @param {...Object} [sources] The source objects.
1278
1265
  * @returns {Object} Returns `object`.
1279
1266
  */
1280
-
1281
1267
  function merge(target) {
1282
1268
  if (!isObjectOrArrayOrFunction(target)) {
1283
1269
  target = {};
1284
1270
  }
1285
-
1286
1271
  for (var i = 1, l = arguments.length; i < l; i++) {
1287
1272
  var source = arguments[i];
1288
-
1289
1273
  if (isObjectOrArrayOrFunction(source)) {
1290
1274
  _merge(target, source);
1291
1275
  }
1292
1276
  }
1293
1277
  return target;
1294
1278
  }
1279
+ module.exports = merge;
1295
1280
 
1296
- var merge_1 = merge;
1281
+ var merge$1 = /*#__PURE__*/Object.freeze({
1282
+ __proto__: null
1283
+ });
1297
1284
 
1298
1285
  // NOTE: this behaves like lodash/defaults, but doesn't mutate the target
1299
1286
  // it also preserve keys order
1300
1287
  var defaultsPure = function defaultsPure() {
1301
1288
  var sources = Array.prototype.slice.call(arguments);
1302
-
1303
- return sources.reduceRight(function(acc, source) {
1304
- Object.keys(Object(source)).forEach(function(key) {
1289
+ return sources.reduceRight(function (acc, source) {
1290
+ Object.keys(Object(source)).forEach(function (key) {
1305
1291
  if (source[key] === undefined) {
1306
1292
  return;
1307
1293
  }
@@ -1316,11 +1302,8 @@
1316
1302
  };
1317
1303
 
1318
1304
  function intersection(arr1, arr2) {
1319
- return arr1.filter(function(value, index) {
1320
- return (
1321
- arr2.indexOf(value) > -1 &&
1322
- arr1.indexOf(value) === index /* skips duplicates */
1323
- );
1305
+ return arr1.filter(function (value, index) {
1306
+ return arr2.indexOf(value) > -1 && arr1.indexOf(value) === index /* skips duplicates */;
1324
1307
  });
1325
1308
  }
1326
1309
 
@@ -1331,12 +1314,12 @@
1331
1314
  if (!Array.isArray(array)) {
1332
1315
  return undefined;
1333
1316
  }
1334
-
1335
1317
  for (var i = 0; i < array.length; i++) {
1336
1318
  if (comparator(array[i])) {
1337
1319
  return array[i];
1338
1320
  }
1339
1321
  }
1322
+ return undefined;
1340
1323
  };
1341
1324
 
1342
1325
  function valToNumber(v) {
@@ -1347,10 +1330,8 @@
1347
1330
  } else if (Array.isArray(v)) {
1348
1331
  return v.map(valToNumber);
1349
1332
  }
1350
-
1351
1333
  throw new Error('The value should be a number, a parsable string or an array of those.');
1352
1334
  }
1353
-
1354
1335
  var valToNumber_1 = valToNumber;
1355
1336
 
1356
1337
  // https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
@@ -1362,18 +1343,17 @@
1362
1343
  var i;
1363
1344
  for (i = 0; i < sourceKeys.length; i++) {
1364
1345
  key = sourceKeys[i];
1346
+ // eslint-disable-next-line no-continue
1365
1347
  if (excluded.indexOf(key) >= 0) continue;
1366
1348
  target[key] = source[key];
1367
1349
  }
1368
1350
  return target;
1369
1351
  }
1370
-
1371
1352
  var omit$1 = _objectWithoutPropertiesLoose$1;
1372
1353
 
1373
1354
  function objectHasKeys$1(obj) {
1374
1355
  return obj && Object.keys(obj).length > 0;
1375
1356
  }
1376
-
1377
1357
  var objectHasKeys_1 = objectHasKeys$1;
1378
1358
 
1379
1359
  var isValidUserToken = function isValidUserToken(userToken) {
@@ -1397,8 +1377,6 @@
1397
1377
 
1398
1378
 
1399
1379
 
1400
-
1401
-
1402
1380
  var lib = {
1403
1381
  /**
1404
1382
  * Adds a refinement to a RefinementList
@@ -1411,17 +1389,10 @@
1411
1389
  if (lib.isRefined(refinementList, attribute, value)) {
1412
1390
  return refinementList;
1413
1391
  }
1414
-
1415
1392
  var valueAsString = '' + value;
1416
-
1417
- var facetRefinement = !refinementList[attribute] ?
1418
- [valueAsString] :
1419
- refinementList[attribute].concat(valueAsString);
1420
-
1393
+ var facetRefinement = !refinementList[attribute] ? [valueAsString] : refinementList[attribute].concat(valueAsString);
1421
1394
  var mod = {};
1422
-
1423
1395
  mod[attribute] = facetRefinement;
1424
-
1425
1396
  return defaultsPure({}, mod, refinementList);
1426
1397
  },
1427
1398
  /**
@@ -1437,14 +1408,12 @@
1437
1408
  if (value === undefined) {
1438
1409
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
1439
1410
  // the form with a string will remove the attribute completely
1440
- return lib.clearRefinement(refinementList, function(v, f) {
1411
+ return lib.clearRefinement(refinementList, function (v, f) {
1441
1412
  return attribute === f;
1442
1413
  });
1443
1414
  }
1444
-
1445
1415
  var valueAsString = '' + value;
1446
-
1447
- return lib.clearRefinement(refinementList, function(v, f) {
1416
+ return lib.clearRefinement(refinementList, function (v, f) {
1448
1417
  return attribute === f && valueAsString === v;
1449
1418
  });
1450
1419
  },
@@ -1457,11 +1426,9 @@
1457
1426
  */
1458
1427
  toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
1459
1428
  if (value === undefined) throw new Error('toggleRefinement should be used with a value');
1460
-
1461
1429
  if (lib.isRefined(refinementList, attribute, value)) {
1462
1430
  return lib.removeRefinement(refinementList, attribute, value);
1463
1431
  }
1464
-
1465
1432
  return lib.addRefinement(refinementList, attribute, value);
1466
1433
  },
1467
1434
  /**
@@ -1477,6 +1444,8 @@
1477
1444
  */
1478
1445
  clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
1479
1446
  if (attribute === undefined) {
1447
+ // return the same object if the list is already empty
1448
+ // this is mainly for tests, as it doesn't have much impact on performance
1480
1449
  if (!objectHasKeys_1(refinementList)) {
1481
1450
  return refinementList;
1482
1451
  }
@@ -1485,24 +1454,24 @@
1485
1454
  return omit$1(refinementList, [attribute]);
1486
1455
  } else if (typeof attribute === 'function') {
1487
1456
  var hasChanged = false;
1488
-
1489
- var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
1457
+ var newRefinementList = Object.keys(refinementList).reduce(function (memo, key) {
1490
1458
  var values = refinementList[key] || [];
1491
- var facetList = values.filter(function(value) {
1459
+ var facetList = values.filter(function (value) {
1492
1460
  return !attribute(value, key, refinementType);
1493
1461
  });
1494
-
1495
1462
  if (facetList.length !== values.length) {
1496
1463
  hasChanged = true;
1497
1464
  }
1498
1465
  memo[key] = facetList;
1499
-
1500
1466
  return memo;
1501
1467
  }, {});
1502
-
1503
1468
  if (hasChanged) return newRefinementList;
1504
1469
  return refinementList;
1505
1470
  }
1471
+
1472
+ // We return nothing if the attribute is not undefined, a string or a function,
1473
+ // as it is not a valid value for a refinement
1474
+ return undefined;
1506
1475
  },
1507
1476
  /**
1508
1477
  * Test if the refinement value is used for the attribute. If no refinement value
@@ -1511,22 +1480,17 @@
1511
1480
  * @param {RefinementList} refinementList the list of refinement
1512
1481
  * @param {string} attribute name of the attribute
1513
1482
  * @param {string} [refinementValue] value of the filter/refinement
1514
- * @return {boolean}
1483
+ * @return {boolean} true if the attribute is refined, false otherwise
1515
1484
  */
1516
1485
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
1517
- var containsRefinements = !!refinementList[attribute] &&
1518
- refinementList[attribute].length > 0;
1519
-
1486
+ var containsRefinements = Boolean(refinementList[attribute]) && refinementList[attribute].length > 0;
1520
1487
  if (refinementValue === undefined || !containsRefinements) {
1521
1488
  return containsRefinements;
1522
1489
  }
1523
-
1524
1490
  var refinementValueAsString = '' + refinementValue;
1525
-
1526
1491
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
1527
1492
  }
1528
1493
  };
1529
-
1530
1494
  var RefinementList = lib;
1531
1495
 
1532
1496
  /**
@@ -1535,15 +1499,15 @@
1535
1499
  * - [5]
1536
1500
  * - [[5]]
1537
1501
  * - [[5,5],[4]]
1502
+ * @param {any} a numeric refinement value
1503
+ * @param {any} b numeric refinement value
1504
+ * @return {boolean} true if the values are equal
1538
1505
  */
1539
1506
  function isEqualNumericRefinement(a, b) {
1540
1507
  if (Array.isArray(a) && Array.isArray(b)) {
1541
- return (
1542
- a.length === b.length &&
1543
- a.every(function(el, i) {
1544
- return isEqualNumericRefinement(b[i], el);
1545
- })
1546
- );
1508
+ return a.length === b.length && a.every(function (el, i) {
1509
+ return isEqualNumericRefinement(b[i], el);
1510
+ });
1547
1511
  }
1548
1512
  return a === b;
1549
1513
  }
@@ -1557,7 +1521,7 @@
1557
1521
  * @return {any} the searched value or undefined
1558
1522
  */
1559
1523
  function findArray(array, searchedValue) {
1560
- return find$1(array, function(currentValue) {
1524
+ return find$1(array, function (currentValue) {
1561
1525
  return isEqualNumericRefinement(currentValue, searchedValue);
1562
1526
  });
1563
1527
  }
@@ -1611,8 +1575,8 @@
1611
1575
  */
1612
1576
  function SearchParameters(newParameters) {
1613
1577
  var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
1614
-
1615
1578
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
1579
+ // eslint-disable-next-line no-console
1616
1580
  console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
1617
1581
  }
1618
1582
  /**
@@ -1715,11 +1679,11 @@
1715
1679
  */
1716
1680
  this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
1717
1681
 
1682
+ // eslint-disable-next-line consistent-this
1718
1683
  var self = this;
1719
- Object.keys(params).forEach(function(paramName) {
1684
+ Object.keys(params).forEach(function (paramName) {
1720
1685
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
1721
1686
  var isValueDefined = params[paramName] !== undefined;
1722
-
1723
1687
  if (!isKeyKnown && isValueDefined) {
1724
1688
  self[paramName] = params[paramName];
1725
1689
  }
@@ -1738,27 +1702,12 @@
1738
1702
  * @param {object} partialState full or part of a state
1739
1703
  * @return {object} a new object with the number keys as number
1740
1704
  */
1741
- SearchParameters._parseNumbers = function(partialState) {
1742
- // Do not reparse numbers in SearchParameters, they ought to be parsed already
1705
+ SearchParameters._parseNumbers = function (partialState) {
1706
+ // Do not parse numbers again in SearchParameters, they ought to be parsed already
1743
1707
  if (partialState instanceof SearchParameters) return partialState;
1744
-
1745
1708
  var numbers = {};
1746
-
1747
- var numberKeys = [
1748
- 'aroundPrecision',
1749
- 'aroundRadius',
1750
- 'getRankingInfo',
1751
- 'minWordSizefor2Typos',
1752
- 'minWordSizefor1Typo',
1753
- 'page',
1754
- 'maxValuesPerFacet',
1755
- 'distinct',
1756
- 'minimumAroundRadius',
1757
- 'hitsPerPage',
1758
- 'minProximity'
1759
- ];
1760
-
1761
- numberKeys.forEach(function(k) {
1709
+ var numberKeys = ['aroundPrecision', 'aroundRadius', 'getRankingInfo', 'minWordSizefor2Typos', 'minWordSizefor1Typo', 'page', 'maxValuesPerFacet', 'distinct', 'minimumAroundRadius', 'hitsPerPage', 'minProximity'];
1710
+ numberKeys.forEach(function (k) {
1762
1711
  var value = partialState[k];
1763
1712
  if (typeof value === 'string') {
1764
1713
  var parsedValue = parseFloat(value);
@@ -1770,26 +1719,25 @@
1770
1719
  // there's two formats of insideBoundingBox, we need to parse
1771
1720
  // the one which is an array of float geo rectangles
1772
1721
  if (Array.isArray(partialState.insideBoundingBox)) {
1773
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
1722
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (geoRect) {
1774
1723
  if (Array.isArray(geoRect)) {
1775
- return geoRect.map(function(value) {
1724
+ return geoRect.map(function (value) {
1776
1725
  return parseFloat(value);
1777
1726
  });
1778
1727
  }
1779
1728
  return geoRect;
1780
1729
  });
1781
1730
  }
1782
-
1783
1731
  if (partialState.numericRefinements) {
1784
1732
  var numericRefinements = {};
1785
- Object.keys(partialState.numericRefinements).forEach(function(attribute) {
1733
+ Object.keys(partialState.numericRefinements).forEach(function (attribute) {
1786
1734
  var operators = partialState.numericRefinements[attribute] || {};
1787
1735
  numericRefinements[attribute] = {};
1788
- Object.keys(operators).forEach(function(operator) {
1736
+ Object.keys(operators).forEach(function (operator) {
1789
1737
  var values = operators[operator];
1790
- var parsedValues = values.map(function(v) {
1738
+ var parsedValues = values.map(function (v) {
1791
1739
  if (Array.isArray(v)) {
1792
- return v.map(function(vPrime) {
1740
+ return v.map(function (vPrime) {
1793
1741
  if (typeof vPrime === 'string') {
1794
1742
  return parseFloat(vPrime);
1795
1743
  }
@@ -1805,8 +1753,7 @@
1805
1753
  });
1806
1754
  numbers.numericRefinements = numericRefinements;
1807
1755
  }
1808
-
1809
- return merge_1({}, partialState, numbers);
1756
+ return merge$1({}, partialState, numbers);
1810
1757
  };
1811
1758
 
1812
1759
  /**
@@ -1817,12 +1764,10 @@
1817
1764
  */
1818
1765
  SearchParameters.make = function makeSearchParameters(newParameters) {
1819
1766
  var instance = new SearchParameters(newParameters);
1820
-
1821
1767
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
1822
- hierarchicalFacets.forEach(function(facet) {
1768
+ hierarchicalFacets.forEach(function (facet) {
1823
1769
  if (facet.rootPath) {
1824
1770
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
1825
-
1826
1771
  if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
1827
1772
  instance = instance.clearRefinements(facet.name);
1828
1773
  }
@@ -1834,7 +1779,6 @@
1834
1779
  }
1835
1780
  }
1836
1781
  });
1837
-
1838
1782
  return instance;
1839
1783
  };
1840
1784
 
@@ -1844,46 +1788,24 @@
1844
1788
  * @param {object|SearchParameters} parameters the new parameters to set
1845
1789
  * @return {Error|null} Error if the modification is invalid, null otherwise
1846
1790
  */
1847
- SearchParameters.validate = function(currentState, parameters) {
1791
+ SearchParameters.validate = function (currentState, parameters) {
1848
1792
  var params = parameters || {};
1849
-
1850
1793
  if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
1851
- return new Error(
1852
- '[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
1853
- 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
1794
+ 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.');
1854
1795
  }
1855
-
1856
1796
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
1857
- return new Error(
1858
- '[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
1859
- 'an error, if it is not, you should first clear the tags with clearTags method.');
1860
- }
1861
-
1862
- if (
1863
- currentState.numericFilters &&
1864
- params.numericRefinements &&
1865
- objectHasKeys_1(params.numericRefinements)
1866
- ) {
1867
- return new Error(
1868
- "[Numeric filters] Can't switch from the advanced to the managed API. It" +
1869
- ' is probably an error, if this is really what you want, you have to first' +
1870
- ' clear the numeric filters.'
1871
- );
1797
+ 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.');
1798
+ }
1799
+ if (currentState.numericFilters && params.numericRefinements && objectHasKeys_1(params.numericRefinements)) {
1800
+ 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.');
1872
1801
  }
1873
-
1874
1802
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
1875
- return new Error(
1876
- "[Numeric filters] Can't switch from the managed API to the advanced. It" +
1877
- ' is probably an error, if this is really what you want, you have to first' +
1878
- ' clear the numeric filters.');
1803
+ 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.');
1879
1804
  }
1880
-
1881
1805
  return null;
1882
1806
  };
1883
-
1884
1807
  SearchParameters.prototype = {
1885
1808
  constructor: SearchParameters,
1886
-
1887
1809
  /**
1888
1810
  * Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
1889
1811
  * @method
@@ -1891,39 +1813,17 @@
1891
1813
  * - If not given, means to clear all the filters.
1892
1814
  * - If `string`, means to clear all refinements for the `attribute` named filter.
1893
1815
  * - If `function`, means to clear all the refinements that return truthy values.
1894
- * @return {SearchParameters}
1816
+ * @return {SearchParameters} new instance with filters cleared
1895
1817
  */
1896
1818
  clearRefinements: function clearRefinements(attribute) {
1897
1819
  var patch = {
1898
1820
  numericRefinements: this._clearNumericRefinements(attribute),
1899
- facetsRefinements: RefinementList.clearRefinement(
1900
- this.facetsRefinements,
1901
- attribute,
1902
- 'conjunctiveFacet'
1903
- ),
1904
- facetsExcludes: RefinementList.clearRefinement(
1905
- this.facetsExcludes,
1906
- attribute,
1907
- 'exclude'
1908
- ),
1909
- disjunctiveFacetsRefinements: RefinementList.clearRefinement(
1910
- this.disjunctiveFacetsRefinements,
1911
- attribute,
1912
- 'disjunctiveFacet'
1913
- ),
1914
- hierarchicalFacetsRefinements: RefinementList.clearRefinement(
1915
- this.hierarchicalFacetsRefinements,
1916
- attribute,
1917
- 'hierarchicalFacet'
1918
- )
1821
+ facetsRefinements: RefinementList.clearRefinement(this.facetsRefinements, attribute, 'conjunctiveFacet'),
1822
+ facetsExcludes: RefinementList.clearRefinement(this.facetsExcludes, attribute, 'exclude'),
1823
+ disjunctiveFacetsRefinements: RefinementList.clearRefinement(this.disjunctiveFacetsRefinements, attribute, 'disjunctiveFacet'),
1824
+ hierarchicalFacetsRefinements: RefinementList.clearRefinement(this.hierarchicalFacetsRefinements, attribute, 'hierarchicalFacet')
1919
1825
  };
1920
- if (
1921
- patch.numericRefinements === this.numericRefinements &&
1922
- patch.facetsRefinements === this.facetsRefinements &&
1923
- patch.facetsExcludes === this.facetsExcludes &&
1924
- patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
1925
- patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
1926
- ) {
1826
+ if (patch.numericRefinements === this.numericRefinements && patch.facetsRefinements === this.facetsRefinements && patch.facetsExcludes === this.facetsExcludes && patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements && patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements) {
1927
1827
  return this;
1928
1828
  }
1929
1829
  return this.setQueryParameters(patch);
@@ -1931,11 +1831,10 @@
1931
1831
  /**
1932
1832
  * Remove all the refined tags from the SearchParameters
1933
1833
  * @method
1934
- * @return {SearchParameters}
1834
+ * @return {SearchParameters} new instance with tags cleared
1935
1835
  */
1936
1836
  clearTags: function clearTags() {
1937
1837
  if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
1938
-
1939
1838
  return this.setQueryParameters({
1940
1839
  tagFilters: undefined,
1941
1840
  tagRefinements: []
@@ -1945,11 +1844,10 @@
1945
1844
  * Set the index.
1946
1845
  * @method
1947
1846
  * @param {string} index the index name
1948
- * @return {SearchParameters}
1847
+ * @return {SearchParameters} new instance
1949
1848
  */
1950
1849
  setIndex: function setIndex(index) {
1951
1850
  if (index === this.index) return this;
1952
-
1953
1851
  return this.setQueryParameters({
1954
1852
  index: index
1955
1853
  });
@@ -1958,11 +1856,10 @@
1958
1856
  * Query setter
1959
1857
  * @method
1960
1858
  * @param {string} newQuery value for the new query
1961
- * @return {SearchParameters}
1859
+ * @return {SearchParameters} new instance
1962
1860
  */
1963
1861
  setQuery: function setQuery(newQuery) {
1964
1862
  if (newQuery === this.query) return this;
1965
-
1966
1863
  return this.setQueryParameters({
1967
1864
  query: newQuery
1968
1865
  });
@@ -1971,11 +1868,10 @@
1971
1868
  * Page setter
1972
1869
  * @method
1973
1870
  * @param {number} newPage new page number
1974
- * @return {SearchParameters}
1871
+ * @return {SearchParameters} new instance
1975
1872
  */
1976
1873
  setPage: function setPage(newPage) {
1977
1874
  if (newPage === this.page) return this;
1978
-
1979
1875
  return this.setQueryParameters({
1980
1876
  page: newPage
1981
1877
  });
@@ -1985,7 +1881,7 @@
1985
1881
  * The facets are the simple facets, used for conjunctive (and) faceting.
1986
1882
  * @method
1987
1883
  * @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
1988
- * @return {SearchParameters}
1884
+ * @return {SearchParameters} new instance
1989
1885
  */
1990
1886
  setFacets: function setFacets(facets) {
1991
1887
  return this.setQueryParameters({
@@ -1997,7 +1893,7 @@
1997
1893
  * Change the list of disjunctive (or) facets the helper chan handle.
1998
1894
  * @method
1999
1895
  * @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
2000
- * @return {SearchParameters}
1896
+ * @return {SearchParameters} new instance
2001
1897
  */
2002
1898
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
2003
1899
  return this.setQueryParameters({
@@ -2009,11 +1905,10 @@
2009
1905
  * Hits per page represents the number of hits retrieved for this query
2010
1906
  * @method
2011
1907
  * @param {number} n number of hits retrieved per page of results
2012
- * @return {SearchParameters}
1908
+ * @return {SearchParameters} new instance
2013
1909
  */
2014
1910
  setHitsPerPage: function setHitsPerPage(n) {
2015
1911
  if (this.hitsPerPage === n) return this;
2016
-
2017
1912
  return this.setQueryParameters({
2018
1913
  hitsPerPage: n
2019
1914
  });
@@ -2023,11 +1918,10 @@
2023
1918
  * Set the value of typoTolerance
2024
1919
  * @method
2025
1920
  * @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
2026
- * @return {SearchParameters}
1921
+ * @return {SearchParameters} new instance
2027
1922
  */
2028
1923
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
2029
1924
  if (this.typoTolerance === typoTolerance) return this;
2030
-
2031
1925
  return this.setQueryParameters({
2032
1926
  typoTolerance: typoTolerance
2033
1927
  });
@@ -2040,33 +1934,28 @@
2040
1934
  * @param {string} attribute attribute to set the filter on
2041
1935
  * @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
2042
1936
  * @param {number | number[]} value value of the filter
2043
- * @return {SearchParameters}
1937
+ * @return {SearchParameters} new instance
2044
1938
  * @example
2045
1939
  * // for price = 50 or 40
2046
- * searchparameter.addNumericRefinement('price', '=', [50, 40]);
1940
+ * state.addNumericRefinement('price', '=', [50, 40]);
2047
1941
  * @example
2048
1942
  * // for size = 38 and 40
2049
- * searchparameter.addNumericRefinement('size', '=', 38);
2050
- * searchparameter.addNumericRefinement('size', '=', 40);
1943
+ * state.addNumericRefinement('size', '=', 38);
1944
+ * state.addNumericRefinement('size', '=', 40);
2051
1945
  */
2052
- addNumericRefinement: function(attribute, operator, v) {
2053
- var value = valToNumber_1(v);
2054
-
2055
- if (this.isNumericRefined(attribute, operator, value)) return this;
2056
-
2057
- var mod = merge_1({}, this.numericRefinements);
2058
-
2059
- mod[attribute] = merge_1({}, mod[attribute]);
2060
-
1946
+ addNumericRefinement: function addNumericRefinement(attribute, operator, value) {
1947
+ var val = valToNumber_1(value);
1948
+ if (this.isNumericRefined(attribute, operator, val)) return this;
1949
+ var mod = merge$1({}, this.numericRefinements);
1950
+ mod[attribute] = merge$1({}, mod[attribute]);
2061
1951
  if (mod[attribute][operator]) {
2062
1952
  // Array copy
2063
1953
  mod[attribute][operator] = mod[attribute][operator].slice();
2064
1954
  // Add the element. Concat can't be used here because value can be an array.
2065
- mod[attribute][operator].push(value);
1955
+ mod[attribute][operator].push(val);
2066
1956
  } else {
2067
- mod[attribute][operator] = [value];
1957
+ mod[attribute][operator] = [val];
2068
1958
  }
2069
-
2070
1959
  return this.setQueryParameters({
2071
1960
  numericRefinements: mod
2072
1961
  });
@@ -2076,7 +1965,7 @@
2076
1965
  * @param {string} facetName name of the attribute used for faceting
2077
1966
  * @return {string[]} list of refinements
2078
1967
  */
2079
- getConjunctiveRefinements: function(facetName) {
1968
+ getConjunctiveRefinements: function getConjunctiveRefinements(facetName) {
2080
1969
  if (!this.isConjunctiveFacet(facetName)) {
2081
1970
  return [];
2082
1971
  }
@@ -2087,7 +1976,7 @@
2087
1976
  * @param {string} facetName name of the attribute used for faceting
2088
1977
  * @return {string[]} list of refinements
2089
1978
  */
2090
- getDisjunctiveRefinements: function(facetName) {
1979
+ getDisjunctiveRefinements: function getDisjunctiveRefinements(facetName) {
2091
1980
  if (!this.isDisjunctiveFacet(facetName)) {
2092
1981
  return [];
2093
1982
  }
@@ -2098,7 +1987,7 @@
2098
1987
  * @param {string} facetName name of the attribute used for faceting
2099
1988
  * @return {string[]} list of refinements
2100
1989
  */
2101
- getHierarchicalRefinement: function(facetName) {
1990
+ getHierarchicalRefinement: function getHierarchicalRefinement(facetName) {
2102
1991
  // we send an array but we currently do not support multiple
2103
1992
  // hierarchicalRefinements for a hierarchicalFacet
2104
1993
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -2108,47 +1997,42 @@
2108
1997
  * @param {string} facetName name of the attribute used for faceting
2109
1998
  * @return {string[]} list of refinements
2110
1999
  */
2111
- getExcludeRefinements: function(facetName) {
2000
+ getExcludeRefinements: function getExcludeRefinements(facetName) {
2112
2001
  if (!this.isConjunctiveFacet(facetName)) {
2113
2002
  return [];
2114
2003
  }
2115
2004
  return this.facetsExcludes[facetName] || [];
2116
2005
  },
2117
-
2118
2006
  /**
2119
2007
  * Remove all the numeric filter for a given (attribute, operator)
2120
2008
  * @method
2121
2009
  * @param {string} attribute attribute to set the filter on
2122
2010
  * @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
2123
2011
  * @param {number} [number] the value to be removed
2124
- * @return {SearchParameters}
2012
+ * @return {SearchParameters} new instance
2125
2013
  */
2126
- removeNumericRefinement: function(attribute, operator, paramValue) {
2014
+ removeNumericRefinement: function removeNumericRefinement(attribute, operator, number) {
2015
+ var paramValue = number;
2127
2016
  if (paramValue !== undefined) {
2128
2017
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
2129
2018
  return this;
2130
2019
  }
2131
2020
  return this.setQueryParameters({
2132
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2133
- return (
2134
- key === attribute &&
2135
- value.op === operator &&
2136
- isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
2137
- );
2021
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2022
+ return key === attribute && value.op === operator && isEqualNumericRefinement(value.val, valToNumber_1(paramValue));
2138
2023
  })
2139
2024
  });
2140
2025
  } else if (operator !== undefined) {
2141
2026
  if (!this.isNumericRefined(attribute, operator)) return this;
2142
2027
  return this.setQueryParameters({
2143
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2028
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2144
2029
  return key === attribute && value.op === operator;
2145
2030
  })
2146
2031
  });
2147
2032
  }
2148
-
2149
2033
  if (!this.isNumericRefined(attribute)) return this;
2150
2034
  return this.setQueryParameters({
2151
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2035
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2152
2036
  return key === attribute;
2153
2037
  })
2154
2038
  });
@@ -2158,7 +2042,7 @@
2158
2042
  * @param {string} facetName name of the attribute used for faceting
2159
2043
  * @return {SearchParameters.OperatorList} list of refinements
2160
2044
  */
2161
- getNumericRefinements: function(facetName) {
2045
+ getNumericRefinements: function getNumericRefinements(facetName) {
2162
2046
  return this.numericRefinements[facetName] || {};
2163
2047
  },
2164
2048
  /**
@@ -2167,7 +2051,7 @@
2167
2051
  * @param {string} operator operator applied on the refined values
2168
2052
  * @return {Array.<number|number[]>} refined values
2169
2053
  */
2170
- getNumericRefinement: function(attribute, operator) {
2054
+ getNumericRefinement: function getNumericRefinement(attribute, operator) {
2171
2055
  return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
2172
2056
  },
2173
2057
  /**
@@ -2178,7 +2062,7 @@
2178
2062
  * - If not given, means to clear all the filters.
2179
2063
  * - If `string`, means to clear all refinements for the `attribute` named filter.
2180
2064
  * - If `function`, means to clear all the refinements that return truthy values.
2181
- * @return {Object.<string, OperatorList>}
2065
+ * @return {Object.<string, OperatorList>} new numeric refinements
2182
2066
  */
2183
2067
  _clearNumericRefinements: function _clearNumericRefinements(attribute) {
2184
2068
  if (attribute === undefined) {
@@ -2191,16 +2075,18 @@
2191
2075
  } else if (typeof attribute === 'function') {
2192
2076
  var hasChanged = false;
2193
2077
  var numericRefinements = this.numericRefinements;
2194
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
2078
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(function (memo, key) {
2195
2079
  var operators = numericRefinements[key];
2196
2080
  var operatorList = {};
2197
-
2198
2081
  operators = operators || {};
2199
- Object.keys(operators).forEach(function(operator) {
2082
+ Object.keys(operators).forEach(function (operator) {
2200
2083
  var values = operators[operator] || [];
2201
2084
  var outValues = [];
2202
- values.forEach(function(value) {
2203
- var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
2085
+ values.forEach(function (value) {
2086
+ var predicateResult = attribute({
2087
+ val: value,
2088
+ op: operator
2089
+ }, key, 'numeric');
2204
2090
  if (!predicateResult) outValues.push(value);
2205
2091
  });
2206
2092
  if (outValues.length !== values.length) {
@@ -2208,28 +2094,28 @@
2208
2094
  }
2209
2095
  operatorList[operator] = outValues;
2210
2096
  });
2211
-
2212
2097
  memo[key] = operatorList;
2213
-
2214
2098
  return memo;
2215
2099
  }, {});
2216
-
2217
2100
  if (hasChanged) return newNumericRefinements;
2218
2101
  return this.numericRefinements;
2219
2102
  }
2103
+
2104
+ // We return nothing if the attribute is not undefined, a string or a function,
2105
+ // as it is not a valid value for a refinement
2106
+ return undefined;
2220
2107
  },
2221
2108
  /**
2222
2109
  * Add a facet to the facets attribute of the helper configuration, if it
2223
2110
  * isn't already present.
2224
2111
  * @method
2225
2112
  * @param {string} facet facet name to add
2226
- * @return {SearchParameters}
2113
+ * @return {SearchParameters} new instance
2227
2114
  */
2228
2115
  addFacet: function addFacet(facet) {
2229
2116
  if (this.isConjunctiveFacet(facet)) {
2230
2117
  return this;
2231
2118
  }
2232
-
2233
2119
  return this.setQueryParameters({
2234
2120
  facets: this.facets.concat([facet])
2235
2121
  });
@@ -2239,13 +2125,12 @@
2239
2125
  * configuration, if it isn't already present.
2240
2126
  * @method
2241
2127
  * @param {string} facet disjunctive facet name to add
2242
- * @return {SearchParameters}
2128
+ * @return {SearchParameters} new instance
2243
2129
  */
2244
2130
  addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
2245
2131
  if (this.isDisjunctiveFacet(facet)) {
2246
2132
  return this;
2247
2133
  }
2248
-
2249
2134
  return this.setQueryParameters({
2250
2135
  disjunctiveFacets: this.disjunctiveFacets.concat([facet])
2251
2136
  });
@@ -2255,15 +2140,13 @@
2255
2140
  * configuration.
2256
2141
  * @method
2257
2142
  * @param {object} hierarchicalFacet hierarchical facet to add
2258
- * @return {SearchParameters}
2143
+ * @return {SearchParameters} new instance
2259
2144
  * @throws will throw an error if a hierarchical facet with the same name was already declared
2260
2145
  */
2261
2146
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
2262
2147
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
2263
- throw new Error(
2264
- 'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
2148
+ throw new Error('Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
2265
2149
  }
2266
-
2267
2150
  return this.setQueryParameters({
2268
2151
  hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
2269
2152
  });
@@ -2273,14 +2156,13 @@
2273
2156
  * @method
2274
2157
  * @param {string} facet attribute to apply the faceting on
2275
2158
  * @param {string} value value of the attribute (will be converted to string)
2276
- * @return {SearchParameters}
2159
+ * @return {SearchParameters} new instance
2277
2160
  */
2278
2161
  addFacetRefinement: function addFacetRefinement(facet, value) {
2279
2162
  if (!this.isConjunctiveFacet(facet)) {
2280
2163
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2281
2164
  }
2282
2165
  if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2283
-
2284
2166
  return this.setQueryParameters({
2285
2167
  facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
2286
2168
  });
@@ -2290,14 +2172,13 @@
2290
2172
  * @method
2291
2173
  * @param {string} facet attribute to apply the exclusion on
2292
2174
  * @param {string} value value of the attribute (will be converted to string)
2293
- * @return {SearchParameters}
2175
+ * @return {SearchParameters} new instance
2294
2176
  */
2295
2177
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
2296
2178
  if (!this.isConjunctiveFacet(facet)) {
2297
2179
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2298
2180
  }
2299
2181
  if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2300
-
2301
2182
  return this.setQueryParameters({
2302
2183
  facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
2303
2184
  });
@@ -2307,33 +2188,27 @@
2307
2188
  * @method
2308
2189
  * @param {string} facet attribute to apply the faceting on
2309
2190
  * @param {string} value value of the attribute (will be converted to string)
2310
- * @return {SearchParameters}
2191
+ * @return {SearchParameters} new instance
2311
2192
  */
2312
2193
  addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
2313
2194
  if (!this.isDisjunctiveFacet(facet)) {
2314
- throw new Error(
2315
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2195
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2316
2196
  }
2317
-
2318
2197
  if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2319
-
2320
2198
  return this.setQueryParameters({
2321
- disjunctiveFacetsRefinements: RefinementList.addRefinement(
2322
- this.disjunctiveFacetsRefinements, facet, value)
2199
+ disjunctiveFacetsRefinements: RefinementList.addRefinement(this.disjunctiveFacetsRefinements, facet, value)
2323
2200
  });
2324
2201
  },
2325
2202
  /**
2326
2203
  * addTagRefinement adds a tag to the list used to filter the results
2327
2204
  * @param {string} tag tag to be added
2328
- * @return {SearchParameters}
2205
+ * @return {SearchParameters} new instance
2329
2206
  */
2330
2207
  addTagRefinement: function addTagRefinement(tag) {
2331
2208
  if (this.isTagRefined(tag)) return this;
2332
-
2333
2209
  var modification = {
2334
2210
  tagRefinements: this.tagRefinements.concat(tag)
2335
2211
  };
2336
-
2337
2212
  return this.setQueryParameters(modification);
2338
2213
  },
2339
2214
  /**
@@ -2341,15 +2216,14 @@
2341
2216
  * is present.
2342
2217
  * @method
2343
2218
  * @param {string} facet facet name to remove
2344
- * @return {SearchParameters}
2219
+ * @return {SearchParameters} new instance
2345
2220
  */
2346
2221
  removeFacet: function removeFacet(facet) {
2347
2222
  if (!this.isConjunctiveFacet(facet)) {
2348
2223
  return this;
2349
2224
  }
2350
-
2351
2225
  return this.clearRefinements(facet).setQueryParameters({
2352
- facets: this.facets.filter(function(f) {
2226
+ facets: this.facets.filter(function (f) {
2353
2227
  return f !== facet;
2354
2228
  })
2355
2229
  });
@@ -2359,15 +2233,14 @@
2359
2233
  * helper configuration, if it is present.
2360
2234
  * @method
2361
2235
  * @param {string} facet disjunctive facet name to remove
2362
- * @return {SearchParameters}
2236
+ * @return {SearchParameters} new instance
2363
2237
  */
2364
2238
  removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
2365
2239
  if (!this.isDisjunctiveFacet(facet)) {
2366
2240
  return this;
2367
2241
  }
2368
-
2369
2242
  return this.clearRefinements(facet).setQueryParameters({
2370
- disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
2243
+ disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
2371
2244
  return f !== facet;
2372
2245
  })
2373
2246
  });
@@ -2377,15 +2250,14 @@
2377
2250
  * helper configuration, if it is present.
2378
2251
  * @method
2379
2252
  * @param {string} facet hierarchical facet name to remove
2380
- * @return {SearchParameters}
2253
+ * @return {SearchParameters} new instance
2381
2254
  */
2382
2255
  removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
2383
2256
  if (!this.isHierarchicalFacet(facet)) {
2384
2257
  return this;
2385
2258
  }
2386
-
2387
2259
  return this.clearRefinements(facet).setQueryParameters({
2388
- hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
2260
+ hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
2389
2261
  return f.name !== facet;
2390
2262
  })
2391
2263
  });
@@ -2397,14 +2269,13 @@
2397
2269
  * @method
2398
2270
  * @param {string} facet name of the attribute used for faceting
2399
2271
  * @param {string} [value] value used to filter
2400
- * @return {SearchParameters}
2272
+ * @return {SearchParameters} new instance
2401
2273
  */
2402
2274
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
2403
2275
  if (!this.isConjunctiveFacet(facet)) {
2404
2276
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2405
2277
  }
2406
2278
  if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2407
-
2408
2279
  return this.setQueryParameters({
2409
2280
  facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
2410
2281
  });
@@ -2414,14 +2285,13 @@
2414
2285
  * @method
2415
2286
  * @param {string} facet name of the attribute used for faceting
2416
2287
  * @param {string} value value used to filter
2417
- * @return {SearchParameters}
2288
+ * @return {SearchParameters} new instance
2418
2289
  */
2419
2290
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
2420
2291
  if (!this.isConjunctiveFacet(facet)) {
2421
2292
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2422
2293
  }
2423
2294
  if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2424
-
2425
2295
  return this.setQueryParameters({
2426
2296
  facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
2427
2297
  });
@@ -2431,35 +2301,30 @@
2431
2301
  * @method
2432
2302
  * @param {string} facet name of the attribute used for faceting
2433
2303
  * @param {string} value value used to filter
2434
- * @return {SearchParameters}
2304
+ * @return {SearchParameters} new instance
2435
2305
  */
2436
2306
  removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
2437
2307
  if (!this.isDisjunctiveFacet(facet)) {
2438
- throw new Error(
2439
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2308
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2440
2309
  }
2441
2310
  if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2442
-
2443
2311
  return this.setQueryParameters({
2444
- disjunctiveFacetsRefinements: RefinementList.removeRefinement(
2445
- this.disjunctiveFacetsRefinements, facet, value)
2312
+ disjunctiveFacetsRefinements: RefinementList.removeRefinement(this.disjunctiveFacetsRefinements, facet, value)
2446
2313
  });
2447
2314
  },
2448
2315
  /**
2449
2316
  * Remove a tag from the list of tag refinements
2450
2317
  * @method
2451
2318
  * @param {string} tag the tag to remove
2452
- * @return {SearchParameters}
2319
+ * @return {SearchParameters} new instance
2453
2320
  */
2454
2321
  removeTagRefinement: function removeTagRefinement(tag) {
2455
2322
  if (!this.isTagRefined(tag)) return this;
2456
-
2457
2323
  var modification = {
2458
- tagRefinements: this.tagRefinements.filter(function(t) {
2324
+ tagRefinements: this.tagRefinements.filter(function (t) {
2459
2325
  return t !== tag;
2460
2326
  })
2461
2327
  };
2462
-
2463
2328
  return this.setQueryParameters(modification);
2464
2329
  },
2465
2330
  /**
@@ -2467,7 +2332,7 @@
2467
2332
  * and hierarchical facets
2468
2333
  * @param {string} facet the facet to refine
2469
2334
  * @param {string} value the associated value
2470
- * @return {SearchParameters}
2335
+ * @return {SearchParameters} new instance
2471
2336
  * @throws will throw an error if the facet is not declared in the settings of the helper
2472
2337
  * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
2473
2338
  */
@@ -2479,7 +2344,7 @@
2479
2344
  * and hierarchical facets
2480
2345
  * @param {string} facet the facet to refine
2481
2346
  * @param {string} value the associated value
2482
- * @return {SearchParameters}
2347
+ * @return {SearchParameters} new instance
2483
2348
  * @throws will throw an error if the facet is not declared in the settings of the helper
2484
2349
  */
2485
2350
  toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
@@ -2490,22 +2355,19 @@
2490
2355
  } else if (this.isDisjunctiveFacet(facet)) {
2491
2356
  return this.toggleDisjunctiveFacetRefinement(facet, value);
2492
2357
  }
2493
-
2494
- throw new Error('Cannot refine the undeclared facet ' + facet +
2495
- '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
2358
+ throw new Error('Cannot refine the undeclared facet ' + facet + '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
2496
2359
  },
2497
2360
  /**
2498
2361
  * Switch the refinement applied over a facet/value
2499
2362
  * @method
2500
2363
  * @param {string} facet name of the attribute used for faceting
2501
2364
  * @param {value} value value used for filtering
2502
- * @return {SearchParameters}
2365
+ * @return {SearchParameters} new instance
2503
2366
  */
2504
2367
  toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
2505
2368
  if (!this.isConjunctiveFacet(facet)) {
2506
2369
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2507
2370
  }
2508
-
2509
2371
  return this.setQueryParameters({
2510
2372
  facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
2511
2373
  });
@@ -2515,13 +2377,12 @@
2515
2377
  * @method
2516
2378
  * @param {string} facet name of the attribute used for faceting
2517
2379
  * @param {value} value value used for filtering
2518
- * @return {SearchParameters}
2380
+ * @return {SearchParameters} new instance
2519
2381
  */
2520
2382
  toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
2521
2383
  if (!this.isConjunctiveFacet(facet)) {
2522
2384
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2523
2385
  }
2524
-
2525
2386
  return this.setQueryParameters({
2526
2387
  facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
2527
2388
  });
@@ -2531,17 +2392,14 @@
2531
2392
  * @method
2532
2393
  * @param {string} facet name of the attribute used for faceting
2533
2394
  * @param {value} value value used for filtering
2534
- * @return {SearchParameters}
2395
+ * @return {SearchParameters} new instance
2535
2396
  */
2536
2397
  toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
2537
2398
  if (!this.isDisjunctiveFacet(facet)) {
2538
- throw new Error(
2539
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2399
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2540
2400
  }
2541
-
2542
2401
  return this.setQueryParameters({
2543
- disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
2544
- this.disjunctiveFacetsRefinements, facet, value)
2402
+ disjunctiveFacetsRefinements: RefinementList.toggleRefinement(this.disjunctiveFacetsRefinements, facet, value)
2545
2403
  });
2546
2404
  },
2547
2405
  /**
@@ -2549,30 +2407,23 @@
2549
2407
  * @method
2550
2408
  * @param {string} facet name of the attribute used for faceting
2551
2409
  * @param {value} value value used for filtering
2552
- * @return {SearchParameters}
2410
+ * @return {SearchParameters} new instance
2553
2411
  */
2554
2412
  toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
2555
2413
  if (!this.isHierarchicalFacet(facet)) {
2556
- throw new Error(
2557
- facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
2414
+ throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
2558
2415
  }
2559
-
2560
2416
  var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
2561
-
2562
2417
  var mod = {};
2563
-
2564
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
2565
- this.hierarchicalFacetsRefinements[facet].length > 0 && (
2566
- // remove current refinement:
2567
- // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
2568
- this.hierarchicalFacetsRefinements[facet][0] === value ||
2569
- // remove a parent refinement of the current refinement:
2570
- // - refinement was 'beer > IPA > Flying dog'
2571
- // - call is toggleRefine('beer > IPA')
2572
- // - refinement should be `beer`
2573
- this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
2574
- );
2575
-
2418
+ var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined && this.hierarchicalFacetsRefinements[facet].length > 0 && (
2419
+ // remove current refinement:
2420
+ // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
2421
+ this.hierarchicalFacetsRefinements[facet][0] === value ||
2422
+ // remove a parent refinement of the current refinement:
2423
+ // - refinement was 'beer > IPA > Flying dog'
2424
+ // - call is toggleRefine('beer > IPA')
2425
+ // - refinement should be `beer`
2426
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0);
2576
2427
  if (upOneOrMultipleLevel) {
2577
2428
  if (value.indexOf(separator) === -1) {
2578
2429
  // go back to root level
@@ -2583,12 +2434,10 @@
2583
2434
  } else {
2584
2435
  mod[facet] = [value];
2585
2436
  }
2586
-
2587
2437
  return this.setQueryParameters({
2588
2438
  hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2589
2439
  });
2590
2440
  },
2591
-
2592
2441
  /**
2593
2442
  * Adds a refinement on a hierarchical facet.
2594
2443
  * @param {string} facet the facet name
@@ -2596,7 +2445,7 @@
2596
2445
  * @return {SearchParameter} the new state
2597
2446
  * @throws Error if the facet is not defined or if the facet is refined
2598
2447
  */
2599
- addHierarchicalFacetRefinement: function(facet, path) {
2448
+ addHierarchicalFacetRefinement: function addHierarchicalFacetRefinement(facet, path) {
2600
2449
  if (this.isHierarchicalFacetRefined(facet)) {
2601
2450
  throw new Error(facet + ' is already refined.');
2602
2451
  }
@@ -2609,14 +2458,13 @@
2609
2458
  hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2610
2459
  });
2611
2460
  },
2612
-
2613
2461
  /**
2614
2462
  * Removes the refinement set on a hierarchical facet.
2615
2463
  * @param {string} facet the facet name
2616
2464
  * @return {SearchParameter} the new state
2617
2465
  * @throws Error if the facet is not defined or if the facet is not refined
2618
2466
  */
2619
- removeHierarchicalFacetRefinement: function(facet) {
2467
+ removeHierarchicalFacetRefinement: function removeHierarchicalFacetRefinement(facet) {
2620
2468
  if (!this.isHierarchicalFacetRefined(facet)) {
2621
2469
  return this;
2622
2470
  }
@@ -2630,40 +2478,39 @@
2630
2478
  * Switch the tag refinement
2631
2479
  * @method
2632
2480
  * @param {string} tag the tag to remove or add
2633
- * @return {SearchParameters}
2481
+ * @return {SearchParameters} new instance
2634
2482
  */
2635
2483
  toggleTagRefinement: function toggleTagRefinement(tag) {
2636
2484
  if (this.isTagRefined(tag)) {
2637
2485
  return this.removeTagRefinement(tag);
2638
2486
  }
2639
-
2640
2487
  return this.addTagRefinement(tag);
2641
2488
  },
2642
2489
  /**
2643
2490
  * Test if the facet name is from one of the disjunctive facets
2644
2491
  * @method
2645
2492
  * @param {string} facet facet name to test
2646
- * @return {boolean}
2493
+ * @return {boolean} true if facet is a disjunctive facet
2647
2494
  */
2648
- isDisjunctiveFacet: function(facet) {
2495
+ isDisjunctiveFacet: function isDisjunctiveFacet(facet) {
2649
2496
  return this.disjunctiveFacets.indexOf(facet) > -1;
2650
2497
  },
2651
2498
  /**
2652
2499
  * Test if the facet name is from one of the hierarchical facets
2653
2500
  * @method
2654
2501
  * @param {string} facetName facet name to test
2655
- * @return {boolean}
2502
+ * @return {boolean} true if facetName is a hierarchical facet
2656
2503
  */
2657
- isHierarchicalFacet: function(facetName) {
2504
+ isHierarchicalFacet: function isHierarchicalFacet(facetName) {
2658
2505
  return this.getHierarchicalFacetByName(facetName) !== undefined;
2659
2506
  },
2660
2507
  /**
2661
2508
  * Test if the facet name is from one of the conjunctive/normal facets
2662
2509
  * @method
2663
2510
  * @param {string} facet facet name to test
2664
- * @return {boolean}
2511
+ * @return {boolean} true if facet is a conjunctive facet
2665
2512
  */
2666
- isConjunctiveFacet: function(facet) {
2513
+ isConjunctiveFacet: function isConjunctiveFacet(facet) {
2667
2514
  return this.facets.indexOf(facet) > -1;
2668
2515
  },
2669
2516
  /**
@@ -2704,7 +2551,7 @@
2704
2551
  * @param {string} facet name of the attribute for used for faceting
2705
2552
  * @param {string} value optional, will test if the value is used for refinement
2706
2553
  * if there is one, otherwise will test if the facet contains any refinement
2707
- * @return {boolean}
2554
+ * @return {boolean} true if the facet is refined
2708
2555
  */
2709
2556
  isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
2710
2557
  if (!this.isDisjunctiveFacet(facet)) {
@@ -2719,19 +2566,16 @@
2719
2566
  * @param {string} facet name of the attribute for used for faceting
2720
2567
  * @param {string} value optional, will test if the value is used for refinement
2721
2568
  * if there is one, otherwise will test if the facet contains any refinement
2722
- * @return {boolean}
2569
+ * @return {boolean} true if the facet is refined
2723
2570
  */
2724
2571
  isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
2725
2572
  if (!this.isHierarchicalFacet(facet)) {
2726
2573
  return false;
2727
2574
  }
2728
-
2729
2575
  var refinements = this.getHierarchicalRefinement(facet);
2730
-
2731
2576
  if (!value) {
2732
2577
  return refinements.length > 0;
2733
2578
  }
2734
-
2735
2579
  return refinements.indexOf(value) !== -1;
2736
2580
  },
2737
2581
  /**
@@ -2746,29 +2590,21 @@
2746
2590
  */
2747
2591
  isNumericRefined: function isNumericRefined(attribute, operator, value) {
2748
2592
  if (value === undefined && operator === undefined) {
2749
- return !!this.numericRefinements[attribute];
2593
+ return Boolean(this.numericRefinements[attribute]);
2750
2594
  }
2751
-
2752
- var isOperatorDefined =
2753
- this.numericRefinements[attribute] &&
2754
- this.numericRefinements[attribute][operator] !== undefined;
2755
-
2595
+ var isOperatorDefined = this.numericRefinements[attribute] && this.numericRefinements[attribute][operator] !== undefined;
2756
2596
  if (value === undefined || !isOperatorDefined) {
2757
2597
  return isOperatorDefined;
2758
2598
  }
2759
-
2760
2599
  var parsedValue = valToNumber_1(value);
2761
- var isAttributeValueDefined =
2762
- findArray(this.numericRefinements[attribute][operator], parsedValue) !==
2763
- undefined;
2764
-
2600
+ var isAttributeValueDefined = findArray(this.numericRefinements[attribute][operator], parsedValue) !== undefined;
2765
2601
  return isOperatorDefined && isAttributeValueDefined;
2766
2602
  },
2767
2603
  /**
2768
2604
  * Returns true if the tag refined, false otherwise
2769
2605
  * @method
2770
2606
  * @param {string} tag the tag to check
2771
- * @return {boolean}
2607
+ * @return {boolean} true if tag is refined
2772
2608
  */
2773
2609
  isTagRefined: function isTagRefined(tag) {
2774
2610
  return this.tagRefinements.indexOf(tag) !== -1;
@@ -2778,83 +2614,63 @@
2778
2614
  * @method
2779
2615
  * @param {string} facet name of the attribute used for faceting
2780
2616
  * @param {value} value value used for filtering
2781
- * @return {string[]}
2617
+ * @return {string[]} returns the list of refinements
2782
2618
  */
2783
2619
  getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
2620
+ // eslint-disable-next-line consistent-this
2784
2621
  var self = this;
2785
2622
 
2786
2623
  // attributes used for numeric filter can also be disjunctive
2787
- var disjunctiveNumericRefinedFacets = intersection_1(
2788
- Object.keys(this.numericRefinements).filter(function(facet) {
2789
- return Object.keys(self.numericRefinements[facet]).length > 0;
2790
- }),
2791
- this.disjunctiveFacets
2792
- );
2793
-
2794
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
2624
+ var disjunctiveNumericRefinedFacets = intersection_1(Object.keys(this.numericRefinements).filter(function (facet) {
2625
+ return Object.keys(self.numericRefinements[facet]).length > 0;
2626
+ }), this.disjunctiveFacets);
2627
+ return Object.keys(this.disjunctiveFacetsRefinements).filter(function (facet) {
2795
2628
  return self.disjunctiveFacetsRefinements[facet].length > 0;
2796
- })
2797
- .concat(disjunctiveNumericRefinedFacets)
2798
- .concat(this.getRefinedHierarchicalFacets());
2629
+ }).concat(disjunctiveNumericRefinedFacets).concat(this.getRefinedHierarchicalFacets());
2799
2630
  },
2800
2631
  /**
2801
2632
  * Returns the list of all disjunctive facets refined
2802
2633
  * @method
2803
2634
  * @param {string} facet name of the attribute used for faceting
2804
2635
  * @param {value} value value used for filtering
2805
- * @return {string[]}
2636
+ * @return {string[]} returns the list of refinements
2806
2637
  */
2807
2638
  getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
2639
+ // eslint-disable-next-line consistent-this
2808
2640
  var self = this;
2809
2641
  return intersection_1(
2810
- // enforce the order between the two arrays,
2811
- // so that refinement name index === hierarchical facet index
2812
- this.hierarchicalFacets.map(function(facet) { return facet.name; }),
2813
- Object.keys(this.hierarchicalFacetsRefinements).filter(function(facet) {
2814
- return self.hierarchicalFacetsRefinements[facet].length > 0;
2815
- })
2816
- );
2642
+ // enforce the order between the two arrays,
2643
+ // so that refinement name index === hierarchical facet index
2644
+ this.hierarchicalFacets.map(function (facet) {
2645
+ return facet.name;
2646
+ }), Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
2647
+ return self.hierarchicalFacetsRefinements[facet].length > 0;
2648
+ }));
2817
2649
  },
2818
2650
  /**
2819
2651
  * Returned the list of all disjunctive facets not refined
2820
2652
  * @method
2821
- * @return {string[]}
2653
+ * @return {string[]} returns the list of facets that are not refined
2822
2654
  */
2823
- getUnrefinedDisjunctiveFacets: function() {
2655
+ getUnrefinedDisjunctiveFacets: function getUnrefinedDisjunctiveFacets() {
2824
2656
  var refinedFacets = this.getRefinedDisjunctiveFacets();
2825
-
2826
- return this.disjunctiveFacets.filter(function(f) {
2657
+ return this.disjunctiveFacets.filter(function (f) {
2827
2658
  return refinedFacets.indexOf(f) === -1;
2828
2659
  });
2829
2660
  },
2830
-
2831
- managedParameters: [
2832
- 'index',
2833
-
2834
- 'facets',
2835
- 'disjunctiveFacets',
2836
- 'facetsRefinements',
2837
- 'hierarchicalFacets',
2838
- 'facetsExcludes',
2839
-
2840
- 'disjunctiveFacetsRefinements',
2841
- 'numericRefinements',
2842
- 'tagRefinements',
2843
- 'hierarchicalFacetsRefinements'
2844
- ],
2661
+ managedParameters: ['index', 'facets', 'disjunctiveFacets', 'facetsRefinements', 'hierarchicalFacets', 'facetsExcludes', 'disjunctiveFacetsRefinements', 'numericRefinements', 'tagRefinements', 'hierarchicalFacetsRefinements'],
2845
2662
  getQueryParams: function getQueryParams() {
2846
2663
  var managedParameters = this.managedParameters;
2847
-
2848
2664
  var queryParams = {};
2849
2665
 
2666
+ // eslint-disable-next-line consistent-this
2850
2667
  var self = this;
2851
- Object.keys(this).forEach(function(paramName) {
2668
+ Object.keys(this).forEach(function (paramName) {
2852
2669
  var paramValue = self[paramName];
2853
2670
  if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
2854
2671
  queryParams[paramName] = paramValue;
2855
2672
  }
2856
2673
  });
2857
-
2858
2674
  return queryParams;
2859
2675
  },
2860
2676
  /**
@@ -2869,11 +2685,8 @@
2869
2685
  */
2870
2686
  setQueryParameter: function setParameter(parameter, value) {
2871
2687
  if (this[parameter] === value) return this;
2872
-
2873
2688
  var modification = {};
2874
-
2875
2689
  modification[parameter] = value;
2876
-
2877
2690
  return this.setQueryParameters(modification);
2878
2691
  },
2879
2692
  /**
@@ -2884,134 +2697,109 @@
2884
2697
  */
2885
2698
  setQueryParameters: function setQueryParameters(params) {
2886
2699
  if (!params) return this;
2887
-
2888
2700
  var error = SearchParameters.validate(this, params);
2889
-
2890
2701
  if (error) {
2891
2702
  throw error;
2892
2703
  }
2893
2704
 
2705
+ // eslint-disable-next-line consistent-this
2894
2706
  var self = this;
2895
2707
  var nextWithNumbers = SearchParameters._parseNumbers(params);
2896
- var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
2708
+ var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
2897
2709
  acc[key] = self[key];
2898
2710
  return acc;
2899
2711
  }, {});
2900
-
2901
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(
2902
- function(previous, key) {
2903
- var isPreviousValueDefined = previous[key] !== undefined;
2904
- var isNextValueDefined = nextWithNumbers[key] !== undefined;
2905
-
2906
- if (isPreviousValueDefined && !isNextValueDefined) {
2907
- return omit$1(previous, [key]);
2908
- }
2909
-
2910
- if (isNextValueDefined) {
2911
- previous[key] = nextWithNumbers[key];
2912
- }
2913
-
2914
- return previous;
2915
- },
2916
- previousPlainObject
2917
- );
2918
-
2712
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (previous, key) {
2713
+ var isPreviousValueDefined = previous[key] !== undefined;
2714
+ var isNextValueDefined = nextWithNumbers[key] !== undefined;
2715
+ if (isPreviousValueDefined && !isNextValueDefined) {
2716
+ return omit$1(previous, [key]);
2717
+ }
2718
+ if (isNextValueDefined) {
2719
+ previous[key] = nextWithNumbers[key];
2720
+ }
2721
+ return previous;
2722
+ }, previousPlainObject);
2919
2723
  return new this.constructor(nextPlainObject);
2920
2724
  },
2921
-
2922
2725
  /**
2923
2726
  * Returns a new instance with the page reset. Two scenarios possible:
2924
2727
  * the page is omitted -> return the given instance
2925
2728
  * the page is set -> return a new instance with a page of 0
2926
2729
  * @return {SearchParameters} a new updated instance
2927
2730
  */
2928
- resetPage: function() {
2731
+ resetPage: function resetPage() {
2929
2732
  if (this.page === undefined) {
2930
2733
  return this;
2931
2734
  }
2932
-
2933
2735
  return this.setPage(0);
2934
2736
  },
2935
-
2936
2737
  /**
2937
2738
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
2938
- * @param {object} hierarchicalFacet
2739
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2939
2740
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
2940
2741
  */
2941
- _getHierarchicalFacetSortBy: function(hierarchicalFacet) {
2742
+ _getHierarchicalFacetSortBy: function _getHierarchicalFacetSortBy(hierarchicalFacet) {
2942
2743
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
2943
2744
  },
2944
-
2945
2745
  /**
2946
2746
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
2947
2747
  * @private
2948
- * @param {object} hierarchicalFacet
2748
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2949
2749
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
2950
2750
  */
2951
- _getHierarchicalFacetSeparator: function(hierarchicalFacet) {
2751
+ _getHierarchicalFacetSeparator: function _getHierarchicalFacetSeparator(hierarchicalFacet) {
2952
2752
  return hierarchicalFacet.separator || ' > ';
2953
2753
  },
2954
-
2955
2754
  /**
2956
2755
  * Helper function to get the hierarchicalFacet prefix path or null
2957
2756
  * @private
2958
- * @param {object} hierarchicalFacet
2757
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2959
2758
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
2960
2759
  */
2961
- _getHierarchicalRootPath: function(hierarchicalFacet) {
2760
+ _getHierarchicalRootPath: function _getHierarchicalRootPath(hierarchicalFacet) {
2962
2761
  return hierarchicalFacet.rootPath || null;
2963
2762
  },
2964
-
2965
2763
  /**
2966
2764
  * Helper function to check if we show the parent level of the hierarchicalFacet
2967
2765
  * @private
2968
- * @param {object} hierarchicalFacet
2766
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2969
2767
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
2970
2768
  */
2971
- _getHierarchicalShowParentLevel: function(hierarchicalFacet) {
2769
+ _getHierarchicalShowParentLevel: function _getHierarchicalShowParentLevel(hierarchicalFacet) {
2972
2770
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
2973
2771
  return hierarchicalFacet.showParentLevel;
2974
2772
  }
2975
2773
  return true;
2976
2774
  },
2977
-
2978
2775
  /**
2979
2776
  * Helper function to get the hierarchicalFacet by it's name
2980
- * @param {string} hierarchicalFacetName
2777
+ * @param {string} hierarchicalFacetName the hierarchicalFacet name
2981
2778
  * @return {object} a hierarchicalFacet
2982
2779
  */
2983
- getHierarchicalFacetByName: function(hierarchicalFacetName) {
2984
- return find$1(
2985
- this.hierarchicalFacets,
2986
- function(f) {
2987
- return f.name === hierarchicalFacetName;
2988
- }
2989
- );
2780
+ getHierarchicalFacetByName: function getHierarchicalFacetByName(hierarchicalFacetName) {
2781
+ return find$1(this.hierarchicalFacets, function (f) {
2782
+ return f.name === hierarchicalFacetName;
2783
+ });
2990
2784
  },
2991
-
2992
2785
  /**
2993
2786
  * Get the current breadcrumb for a hierarchical facet, as an array
2994
2787
  * @param {string} facetName Hierarchical facet name
2995
2788
  * @return {array.<string>} the path as an array of string
2996
2789
  */
2997
- getHierarchicalFacetBreadcrumb: function(facetName) {
2790
+ getHierarchicalFacetBreadcrumb: function getHierarchicalFacetBreadcrumb(facetName) {
2998
2791
  if (!this.isHierarchicalFacet(facetName)) {
2999
2792
  return [];
3000
2793
  }
3001
-
3002
2794
  var refinement = this.getHierarchicalRefinement(facetName)[0];
3003
2795
  if (!refinement) return [];
3004
-
3005
- var separator = this._getHierarchicalFacetSeparator(
3006
- this.getHierarchicalFacetByName(facetName)
3007
- );
2796
+ var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facetName));
3008
2797
  var path = refinement.split(separator);
3009
- return path.map(function(part) {
2798
+ return path.map(function (part) {
3010
2799
  return part.trim();
3011
2800
  });
3012
2801
  },
3013
-
3014
- toString: function() {
2802
+ toString: function toString() {
3015
2803
  return JSON.stringify(this, null, 2);
3016
2804
  }
3017
2805
  };
@@ -3031,22 +2819,12 @@
3031
2819
  if (value !== other) {
3032
2820
  var valIsDefined = value !== undefined;
3033
2821
  var valIsNull = value === null;
3034
-
3035
2822
  var othIsDefined = other !== undefined;
3036
2823
  var othIsNull = other === null;
3037
-
3038
- if (
3039
- (!othIsNull && value > other) ||
3040
- (valIsNull && othIsDefined) ||
3041
- !valIsDefined
3042
- ) {
2824
+ if (!othIsNull && value > other || valIsNull && othIsDefined || !valIsDefined) {
3043
2825
  return 1;
3044
2826
  }
3045
- if (
3046
- (!valIsNull && value < other) ||
3047
- (othIsNull && valIsDefined) ||
3048
- !othIsDefined
3049
- ) {
2827
+ if (!valIsNull && value < other || othIsNull && valIsDefined || !othIsDefined) {
3050
2828
  return -1;
3051
2829
  }
3052
2830
  }
@@ -3057,29 +2835,26 @@
3057
2835
  * @param {Array<object>} collection object with keys in attributes
3058
2836
  * @param {Array<string>} iteratees attributes
3059
2837
  * @param {Array<string>} orders asc | desc
2838
+ * @return {Array<object>} sorted collection
3060
2839
  */
3061
2840
  function orderBy(collection, iteratees, orders) {
3062
2841
  if (!Array.isArray(collection)) {
3063
2842
  return [];
3064
2843
  }
3065
-
3066
2844
  if (!Array.isArray(orders)) {
3067
2845
  orders = [];
3068
2846
  }
3069
-
3070
- var result = collection.map(function(value, index) {
2847
+ var result = collection.map(function (value, index) {
3071
2848
  return {
3072
- criteria: iteratees.map(function(iteratee) {
2849
+ criteria: iteratees.map(function (iteratee) {
3073
2850
  return value[iteratee];
3074
2851
  }),
3075
2852
  index: index,
3076
2853
  value: value
3077
2854
  };
3078
2855
  });
3079
-
3080
2856
  result.sort(function comparer(object, other) {
3081
2857
  var index = -1;
3082
-
3083
2858
  while (++index < object.criteria.length) {
3084
2859
  var res = compareAscending(object.criteria[index], other.criteria[index]);
3085
2860
  if (res) {
@@ -3097,19 +2872,16 @@
3097
2872
  // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
3098
2873
  return object.index - other.index;
3099
2874
  });
3100
-
3101
- return result.map(function(res) {
2875
+ return result.map(function (res) {
3102
2876
  return res.value;
3103
2877
  });
3104
2878
  }
3105
-
3106
2879
  var orderBy_1 = orderBy;
3107
2880
 
3108
2881
  var compact = function compact(array) {
3109
2882
  if (!Array.isArray(array)) {
3110
2883
  return [];
3111
2884
  }
3112
-
3113
2885
  return array.filter(Boolean);
3114
2886
  };
3115
2887
 
@@ -3118,7 +2890,6 @@
3118
2890
  if (!Array.isArray(array)) {
3119
2891
  return -1;
3120
2892
  }
3121
-
3122
2893
  for (var i = 0; i < array.length; i++) {
3123
2894
  if (comparator(array[i])) {
3124
2895
  return i;
@@ -3134,43 +2905,33 @@
3134
2905
  * @return {array.<string[]>} array containing 2 elements : attributes, orders
3135
2906
  */
3136
2907
  var formatSort = function formatSort(sortBy, defaults) {
3137
- var defaultInstructions = (defaults || []).map(function(sort) {
2908
+ var defaultInstructions = (defaults || []).map(function (sort) {
3138
2909
  return sort.split(':');
3139
2910
  });
3140
-
3141
- return sortBy.reduce(
3142
- function preparePredicate(out, sort) {
3143
- var sortInstruction = sort.split(':');
3144
-
3145
- var matchingDefault = find$1(defaultInstructions, function(
3146
- defaultInstruction
3147
- ) {
3148
- return defaultInstruction[0] === sortInstruction[0];
3149
- });
3150
-
3151
- if (sortInstruction.length > 1 || !matchingDefault) {
3152
- out[0].push(sortInstruction[0]);
3153
- out[1].push(sortInstruction[1]);
3154
- return out;
3155
- }
3156
-
3157
- out[0].push(matchingDefault[0]);
3158
- out[1].push(matchingDefault[1]);
2911
+ return sortBy.reduce(function preparePredicate(out, sort) {
2912
+ var sortInstruction = sort.split(':');
2913
+ var matchingDefault = find$1(defaultInstructions, function (defaultInstruction) {
2914
+ return defaultInstruction[0] === sortInstruction[0];
2915
+ });
2916
+ if (sortInstruction.length > 1 || !matchingDefault) {
2917
+ out[0].push(sortInstruction[0]);
2918
+ out[1].push(sortInstruction[1]);
3159
2919
  return out;
3160
- },
3161
- [[], []]
3162
- );
2920
+ }
2921
+ out[0].push(matchingDefault[0]);
2922
+ out[1].push(matchingDefault[1]);
2923
+ return out;
2924
+ }, [[], []]);
3163
2925
  };
3164
2926
 
3165
2927
  /**
3166
2928
  * Replaces a leading - with \-
3167
2929
  * @private
3168
2930
  * @param {any} value the facet value to replace
3169
- * @returns any
2931
+ * @returns {any} the escaped facet value or the value if it was not a string
3170
2932
  */
3171
2933
  function escapeFacetValue(value) {
3172
2934
  if (typeof value !== 'string') return value;
3173
-
3174
2935
  return String(value).replace(/^-/, '\\-');
3175
2936
  }
3176
2937
 
@@ -3178,14 +2939,12 @@
3178
2939
  * Replaces a leading \- with -
3179
2940
  * @private
3180
2941
  * @param {any} value the escaped facet value
3181
- * @returns any
2942
+ * @returns {any} the unescaped facet value or the value if it was not a string
3182
2943
  */
3183
2944
  function unescapeFacetValue$1(value) {
3184
2945
  if (typeof value !== 'string') return value;
3185
-
3186
2946
  return value.replace(/^\\-/, '-');
3187
2947
  }
3188
-
3189
2948
  var escapeFacetValue_1 = {
3190
2949
  escapeFacetValue: escapeFacetValue,
3191
2950
  unescapeFacetValue: unescapeFacetValue$1
@@ -3196,87 +2955,50 @@
3196
2955
 
3197
2956
 
3198
2957
 
3199
-
3200
2958
  var escapeFacetValue$1 = escapeFacetValue_1.escapeFacetValue;
3201
2959
  var unescapeFacetValue$2 = escapeFacetValue_1.unescapeFacetValue;
3202
-
3203
2960
  function generateTrees(state) {
3204
2961
  return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
3205
2962
  var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
3206
- var hierarchicalFacetRefinement =
3207
- (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
3208
- state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
3209
- '';
3210
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(
3211
- hierarchicalFacet
3212
- );
3213
- var hierarchicalRootPath = state._getHierarchicalRootPath(
3214
- hierarchicalFacet
3215
- );
3216
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
3217
- hierarchicalFacet
3218
- );
3219
- var sortBy = formatSort(
3220
- state._getHierarchicalFacetSortBy(hierarchicalFacet)
3221
- );
3222
-
3223
- var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
2963
+ var hierarchicalFacetRefinement = state.hierarchicalFacetsRefinements[hierarchicalFacet.name] && state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0] || '';
2964
+ var hierarchicalSeparator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
2965
+ var hierarchicalRootPath = state._getHierarchicalRootPath(hierarchicalFacet);
2966
+ var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(hierarchicalFacet);
2967
+ var sortBy = formatSort(state._getHierarchicalFacetSortBy(hierarchicalFacet));
2968
+ var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
3224
2969
  return facetResult.exhaustive;
3225
2970
  });
3226
-
3227
- var generateTreeFn = generateHierarchicalTree(
3228
- sortBy,
3229
- hierarchicalSeparator,
3230
- hierarchicalRootPath,
3231
- hierarchicalShowParentLevel,
3232
- hierarchicalFacetRefinement
3233
- );
3234
-
2971
+ var generateTreeFn = generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, hierarchicalFacetRefinement);
3235
2972
  var results = hierarchicalFacetResult;
3236
-
3237
2973
  if (hierarchicalRootPath) {
3238
- results = hierarchicalFacetResult.slice(
3239
- hierarchicalRootPath.split(hierarchicalSeparator).length
3240
- );
2974
+ results = hierarchicalFacetResult.slice(hierarchicalRootPath.split(hierarchicalSeparator).length);
3241
2975
  }
3242
-
3243
2976
  return results.reduce(generateTreeFn, {
3244
2977
  name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
3245
- count: null, // root level, no count
3246
- isRefined: true, // root level, always refined
3247
- path: null, // root level, no path
2978
+ count: null,
2979
+ // root level, no count
2980
+ isRefined: true,
2981
+ // root level, always refined
2982
+ path: null,
2983
+ // root level, no path
3248
2984
  escapedValue: null,
3249
2985
  exhaustive: rootExhaustive,
3250
2986
  data: null
3251
2987
  });
3252
2988
  };
3253
2989
  }
3254
-
3255
- function generateHierarchicalTree(
3256
- sortBy,
3257
- hierarchicalSeparator,
3258
- hierarchicalRootPath,
3259
- hierarchicalShowParentLevel,
3260
- currentRefinement
3261
- ) {
3262
- return function generateTree(
3263
- hierarchicalTree,
3264
- hierarchicalFacetResult,
3265
- currentHierarchicalLevel
3266
- ) {
2990
+ function generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, currentRefinement) {
2991
+ return function generateTree(hierarchicalTree, hierarchicalFacetResult, currentHierarchicalLevel) {
3267
2992
  var parent = hierarchicalTree;
3268
-
3269
2993
  if (currentHierarchicalLevel > 0) {
3270
2994
  var level = 0;
3271
-
3272
2995
  parent = hierarchicalTree;
3273
-
3274
2996
  while (level < currentHierarchicalLevel) {
3275
2997
  /**
3276
2998
  * @type {object[]]} hierarchical data
3277
2999
  */
3278
3000
  var data = parent && Array.isArray(parent.data) ? parent.data : [];
3279
- parent = find$1(data, function(subtree) {
3001
+ parent = find$1(data, function (subtree) {
3280
3002
  return subtree.isRefined;
3281
3003
  });
3282
3004
  level++;
@@ -3296,99 +3018,49 @@
3296
3018
  // If parent refinement is `beers`, then we do not want to have `bières > Belges`
3297
3019
  // showing up
3298
3020
 
3299
- var picked = Object.keys(hierarchicalFacetResult.data)
3300
- .map(function(facetValue) {
3301
- return [facetValue, hierarchicalFacetResult.data[facetValue]];
3302
- })
3303
- .filter(function(tuple) {
3304
- var facetValue = tuple[0];
3305
- return onlyMatchingTree(
3306
- facetValue,
3307
- parent.path || hierarchicalRootPath,
3308
- currentRefinement,
3309
- hierarchicalSeparator,
3310
- hierarchicalRootPath,
3311
- hierarchicalShowParentLevel
3312
- );
3313
- });
3314
-
3315
- parent.data = orderBy_1(
3316
- picked.map(function(tuple) {
3317
- var facetValue = tuple[0];
3318
- var facetCount = tuple[1];
3319
-
3320
- return format(
3321
- facetCount,
3322
- facetValue,
3323
- hierarchicalSeparator,
3324
- unescapeFacetValue$2(currentRefinement),
3325
- hierarchicalFacetResult.exhaustive
3326
- );
3327
- }),
3328
- sortBy[0],
3329
- sortBy[1]
3330
- );
3021
+ var picked = Object.keys(hierarchicalFacetResult.data).map(function (facetValue) {
3022
+ return [facetValue, hierarchicalFacetResult.data[facetValue]];
3023
+ }).filter(function (tuple) {
3024
+ var facetValue = tuple[0];
3025
+ return onlyMatchingTree(facetValue, parent.path || hierarchicalRootPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel);
3026
+ });
3027
+ parent.data = orderBy_1(picked.map(function (tuple) {
3028
+ var facetValue = tuple[0];
3029
+ var facetCount = tuple[1];
3030
+ return format(facetCount, facetValue, hierarchicalSeparator, unescapeFacetValue$2(currentRefinement), hierarchicalFacetResult.exhaustive);
3031
+ }), sortBy[0], sortBy[1]);
3331
3032
  }
3332
-
3333
3033
  return hierarchicalTree;
3334
3034
  };
3335
3035
  }
3336
3036
 
3337
- function onlyMatchingTree(
3338
- facetValue,
3339
- parentPath,
3340
- currentRefinement,
3341
- hierarchicalSeparator,
3342
- hierarchicalRootPath,
3343
- hierarchicalShowParentLevel
3344
- ) {
3037
+ // eslint-disable-next-line max-params
3038
+ function onlyMatchingTree(facetValue, parentPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel) {
3345
3039
  // we want the facetValue is a child of hierarchicalRootPath
3346
- if (
3347
- hierarchicalRootPath &&
3348
- (facetValue.indexOf(hierarchicalRootPath) !== 0 ||
3349
- hierarchicalRootPath === facetValue)
3350
- ) {
3040
+ if (hierarchicalRootPath && (facetValue.indexOf(hierarchicalRootPath) !== 0 || hierarchicalRootPath === facetValue)) {
3351
3041
  return false;
3352
3042
  }
3353
3043
 
3354
3044
  // we always want root levels (only when there is no prefix path)
3355
- return (
3356
- (!hierarchicalRootPath &&
3357
- facetValue.indexOf(hierarchicalSeparator) === -1) ||
3358
- // if there is a rootPath, being root level mean 1 level under rootPath
3359
- (hierarchicalRootPath &&
3360
- facetValue.split(hierarchicalSeparator).length -
3361
- hierarchicalRootPath.split(hierarchicalSeparator).length ===
3362
- 1) ||
3363
- // if current refinement is a root level and current facetValue is a root level,
3364
- // keep the facetValue
3365
- (facetValue.indexOf(hierarchicalSeparator) === -1 &&
3366
- currentRefinement.indexOf(hierarchicalSeparator) === -1) ||
3367
- // currentRefinement is a child of the facet value
3368
- currentRefinement.indexOf(facetValue) === 0 ||
3369
- // facetValue is a child of the current parent, add it
3370
- (facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
3371
- (hierarchicalShowParentLevel ||
3372
- facetValue.indexOf(currentRefinement) === 0))
3373
- );
3374
- }
3375
-
3376
- function format(
3377
- facetCount,
3378
- facetValue,
3379
- hierarchicalSeparator,
3380
- currentRefinement,
3381
- exhaustive
3382
- ) {
3045
+ return !hierarchicalRootPath && facetValue.indexOf(hierarchicalSeparator) === -1 ||
3046
+ // if there is a rootPath, being root level mean 1 level under rootPath
3047
+ hierarchicalRootPath && facetValue.split(hierarchicalSeparator).length - hierarchicalRootPath.split(hierarchicalSeparator).length === 1 ||
3048
+ // if current refinement is a root level and current facetValue is a root level,
3049
+ // keep the facetValue
3050
+ facetValue.indexOf(hierarchicalSeparator) === -1 && currentRefinement.indexOf(hierarchicalSeparator) === -1 ||
3051
+ // currentRefinement is a child of the facet value
3052
+ currentRefinement.indexOf(facetValue) === 0 ||
3053
+ // facetValue is a child of the current parent, add it
3054
+ facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 && (hierarchicalShowParentLevel || facetValue.indexOf(currentRefinement) === 0);
3055
+ }
3056
+ function format(facetCount, facetValue, hierarchicalSeparator, currentRefinement, exhaustive) {
3383
3057
  var parts = facetValue.split(hierarchicalSeparator);
3384
3058
  return {
3385
3059
  name: parts[parts.length - 1].trim(),
3386
3060
  path: facetValue,
3387
3061
  escapedValue: escapeFacetValue$1(facetValue),
3388
3062
  count: facetCount,
3389
- isRefined:
3390
- currentRefinement === facetValue ||
3391
- currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
3063
+ isRefined: currentRefinement === facetValue || currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
3392
3064
  exhaustive: exhaustive,
3393
3065
  data: null
3394
3066
  };
@@ -3398,7 +3070,6 @@
3398
3070
  var unescapeFacetValue$3 = escapeFacetValue_1.unescapeFacetValue;
3399
3071
 
3400
3072
 
3401
-
3402
3073
  /**
3403
3074
  * @typedef SearchResults.Facet
3404
3075
  * @type {object}
@@ -3441,18 +3112,17 @@
3441
3112
  */
3442
3113
 
3443
3114
  /**
3444
- * @param {string[]} attributes
3115
+ * Turn an array of attributes in an object of attributes with their position in the array as value
3116
+ * @param {string[]} attributes the list of attributes in the record
3117
+ * @return {object} the list of attributes indexed by attribute name
3445
3118
  */
3446
3119
  function getIndices(attributes) {
3447
3120
  var indices = {};
3448
-
3449
- attributes.forEach(function(val, idx) {
3121
+ attributes.forEach(function (val, idx) {
3450
3122
  indices[val] = idx;
3451
3123
  });
3452
-
3453
3124
  return indices;
3454
3125
  }
3455
-
3456
3126
  function assignFacetStats(dest, facetStats, key) {
3457
3127
  if (facetStats && facetStats[key]) {
3458
3128
  dest.stats = facetStats[key];
@@ -3466,22 +3136,18 @@
3466
3136
  */
3467
3137
 
3468
3138
  /**
3469
- * @param {HierarchicalFacet[]} hierarchicalFacets
3470
- * @param {string} hierarchicalAttributeName
3139
+ * @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
3140
+ * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
3141
+ * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
3471
3142
  */
3472
- function findMatchingHierarchicalFacetFromAttributeName(
3473
- hierarchicalFacets,
3474
- hierarchicalAttributeName
3475
- ) {
3476
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
3477
- hierarchicalFacet
3478
- ) {
3143
+ function findMatchingHierarchicalFacetFromAttributeName(hierarchicalFacets, hierarchicalAttributeName) {
3144
+ return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(hierarchicalFacet) {
3479
3145
  var facetNames = hierarchicalFacet.attributes || [];
3480
3146
  return facetNames.indexOf(hierarchicalAttributeName) > -1;
3481
3147
  });
3482
3148
  }
3483
3149
 
3484
- /*eslint-disable */
3150
+ // eslint-disable-next-line valid-jsdoc
3485
3151
  /**
3486
3152
  * Constructor for SearchResults
3487
3153
  * @class
@@ -3612,21 +3278,20 @@
3612
3278
  "index": "bestbuy"
3613
3279
  }
3614
3280
  **/
3615
- /*eslint-enable */
3616
3281
  function SearchResults(state, results, options) {
3617
3282
  var mainSubResponse = results[0];
3618
-
3619
3283
  this._rawResults = results;
3620
3284
 
3285
+ // eslint-disable-next-line consistent-this
3621
3286
  var self = this;
3622
3287
 
3623
3288
  // https://www.algolia.com/doc/api-reference/api-methods/search/#response
3624
- Object.keys(mainSubResponse).forEach(function(key) {
3289
+ Object.keys(mainSubResponse).forEach(function (key) {
3625
3290
  self[key] = mainSubResponse[key];
3626
3291
  });
3627
3292
 
3628
3293
  // Make every key of the result options reachable from the instance
3629
- Object.keys(options || {}).forEach(function(key) {
3294
+ Object.keys(options || {}).forEach(function (key) {
3630
3295
  self[key] = options[key];
3631
3296
  });
3632
3297
 
@@ -3648,8 +3313,8 @@
3648
3313
  * all the records that match the search parameters. Each record is
3649
3314
  * augmented with a new attribute `_highlightResult`
3650
3315
  * which is an object keyed by attribute and with the following properties:
3651
- * - `value` : the value of the facet highlighted (html)
3652
- * - `matchLevel`: full, partial or none depending on how the query terms match
3316
+ * - `value` : the value of the facet highlighted (html)
3317
+ * - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
3653
3318
  * @name hits
3654
3319
  * @member {object[]}
3655
3320
  * @memberof SearchResults
@@ -3765,12 +3430,13 @@
3765
3430
 
3766
3431
  /**
3767
3432
  * sum of the processing time of all the queries
3433
+ * @name processingTimeMS
3768
3434
  * @member {number}
3435
+ * @memberof SearchResults
3436
+ * @instance
3769
3437
  */
3770
- this.processingTimeMS = results.reduce(function(sum, result) {
3771
- return result.processingTimeMS === undefined
3772
- ? sum
3773
- : sum + result.processingTimeMS;
3438
+ this.processingTimeMS = results.reduce(function (sum, result) {
3439
+ return result.processingTimeMS === undefined ? sum : sum + result.processingTimeMS;
3774
3440
  }, 0);
3775
3441
 
3776
3442
  /**
@@ -3790,9 +3456,7 @@
3790
3456
  * @member {SearchResults.Facet[]}
3791
3457
  */
3792
3458
  this.facets = [];
3793
-
3794
3459
  var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
3795
-
3796
3460
  var facetsIndices = getIndices(state.facets);
3797
3461
  var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
3798
3462
  var nextDisjunctiveResult = 1;
@@ -3801,20 +3465,14 @@
3801
3465
  // we get the facets information from the first, general, response.
3802
3466
 
3803
3467
  var mainFacets = mainSubResponse.facets || {};
3804
-
3805
- Object.keys(mainFacets).forEach(function(facetKey) {
3468
+ Object.keys(mainFacets).forEach(function (facetKey) {
3806
3469
  var facetValueObject = mainFacets[facetKey];
3807
-
3808
- var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
3809
- state.hierarchicalFacets,
3810
- facetKey
3811
- );
3812
-
3470
+ var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(state.hierarchicalFacets, facetKey);
3813
3471
  if (hierarchicalFacet) {
3814
3472
  // Place the hierarchicalFacet data at the correct index depending on
3815
3473
  // the attributes order that was defined at the helper initialization
3816
3474
  var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
3817
- var idxAttributeName = findIndex(state.hierarchicalFacets, function(f) {
3475
+ var idxAttributeName = findIndex(state.hierarchicalFacets, function (f) {
3818
3476
  return f.name === hierarchicalFacet.name;
3819
3477
  });
3820
3478
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
@@ -3826,7 +3484,6 @@
3826
3484
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
3827
3485
  var isFacetConjunctive = state.facets.indexOf(facetKey) !== -1;
3828
3486
  var position;
3829
-
3830
3487
  if (isFacetDisjunctive) {
3831
3488
  position = disjunctiveFacetsIndices[facetKey];
3832
3489
  self.disjunctiveFacets[position] = {
@@ -3852,22 +3509,20 @@
3852
3509
  this.hierarchicalFacets = compact(this.hierarchicalFacets);
3853
3510
 
3854
3511
  // aggregate the refined disjunctive facets
3855
- disjunctiveFacets.forEach(function(disjunctiveFacet) {
3512
+ disjunctiveFacets.forEach(function (disjunctiveFacet) {
3856
3513
  var result = results[nextDisjunctiveResult];
3857
3514
  var facets = result && result.facets ? result.facets : {};
3858
3515
  var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
3859
3516
 
3860
3517
  // There should be only item in facets.
3861
- Object.keys(facets).forEach(function(dfacet) {
3518
+ Object.keys(facets).forEach(function (dfacet) {
3862
3519
  var facetResults = facets[dfacet];
3863
-
3864
3520
  var position;
3865
-
3866
3521
  if (hierarchicalFacet) {
3867
- position = findIndex(state.hierarchicalFacets, function(f) {
3522
+ position = findIndex(state.hierarchicalFacets, function (f) {
3868
3523
  return f.name === hierarchicalFacet.name;
3869
3524
  });
3870
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3525
+ var attributeIndex = findIndex(self.hierarchicalFacets[position], function (f) {
3871
3526
  return f.attribute === dfacet;
3872
3527
  });
3873
3528
 
@@ -3875,29 +3530,20 @@
3875
3530
  if (attributeIndex === -1) {
3876
3531
  return;
3877
3532
  }
3878
-
3879
- self.hierarchicalFacets[position][attributeIndex].data = merge_1(
3880
- {},
3881
- self.hierarchicalFacets[position][attributeIndex].data,
3882
- facetResults
3883
- );
3533
+ self.hierarchicalFacets[position][attributeIndex].data = merge$1({}, self.hierarchicalFacets[position][attributeIndex].data, facetResults);
3884
3534
  } else {
3885
3535
  position = disjunctiveFacetsIndices[dfacet];
3886
-
3887
3536
  var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
3888
-
3889
3537
  self.disjunctiveFacets[position] = {
3890
3538
  name: dfacet,
3891
3539
  data: defaultsPure({}, facetResults, dataFromMainRequest),
3892
3540
  exhaustive: result.exhaustiveFacetsCount
3893
3541
  };
3894
3542
  assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
3895
-
3896
3543
  if (state.disjunctiveFacetsRefinements[dfacet]) {
3897
- state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
3544
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (refinementValue) {
3898
3545
  // add the disjunctive refinements if it is no more retrieved
3899
- if (!self.disjunctiveFacets[position].data[refinementValue] &&
3900
- state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
3546
+ if (!self.disjunctiveFacets[position].data[refinementValue] && state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
3901
3547
  self.disjunctiveFacets[position].data[refinementValue] = 0;
3902
3548
  }
3903
3549
  });
@@ -3908,28 +3554,23 @@
3908
3554
  });
3909
3555
 
3910
3556
  // if we have some parent level values for hierarchical facets, merge them
3911
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
3557
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
3912
3558
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
3913
3559
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
3914
-
3915
3560
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
3916
3561
  // if we are already at a root refinement (or no refinement at all), there is no
3917
3562
  // root level values request
3918
3563
  if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
3919
3564
  return;
3920
3565
  }
3921
-
3922
- results.slice(nextDisjunctiveResult).forEach(function(result) {
3923
- var facets = result && result.facets
3924
- ? result.facets
3925
- : {};
3926
-
3927
- Object.keys(facets).forEach(function(dfacet) {
3566
+ results.slice(nextDisjunctiveResult).forEach(function (result) {
3567
+ var facets = result && result.facets ? result.facets : {};
3568
+ Object.keys(facets).forEach(function (dfacet) {
3928
3569
  var facetResults = facets[dfacet];
3929
- var position = findIndex(state.hierarchicalFacets, function(f) {
3570
+ var position = findIndex(state.hierarchicalFacets, function (f) {
3930
3571
  return f.name === hierarchicalFacet.name;
3931
3572
  });
3932
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3573
+ var attributeIndex = findIndex(self.hierarchicalFacets[position], function (f) {
3933
3574
  return f.attribute === dfacet;
3934
3575
  });
3935
3576
 
@@ -3947,35 +3588,29 @@
3947
3588
  // | beers (5)
3948
3589
  // > IPA (5)
3949
3590
  var defaultData = {};
3950
-
3951
3591
  if (currentRefinement.length > 0) {
3952
3592
  var root = currentRefinement[0].split(separator)[0];
3953
3593
  defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
3954
3594
  }
3955
-
3956
- self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
3957
- defaultData,
3958
- facetResults,
3959
- self.hierarchicalFacets[position][attributeIndex].data
3960
- );
3595
+ self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(defaultData, facetResults, self.hierarchicalFacets[position][attributeIndex].data);
3961
3596
  });
3962
-
3963
3597
  nextDisjunctiveResult++;
3964
3598
  });
3965
3599
  });
3966
3600
 
3967
3601
  // add the excludes
3968
- Object.keys(state.facetsExcludes).forEach(function(facetName) {
3602
+ Object.keys(state.facetsExcludes).forEach(function (facetName) {
3969
3603
  var excludes = state.facetsExcludes[facetName];
3970
3604
  var position = facetsIndices[facetName];
3971
-
3972
3605
  self.facets[position] = {
3973
3606
  name: facetName,
3974
- data: mainSubResponse.facets[facetName],
3607
+ data: mainFacets[facetName],
3975
3608
  exhaustive: mainSubResponse.exhaustiveFacetsCount
3976
3609
  };
3977
- excludes.forEach(function(facetValue) {
3978
- self.facets[position] = self.facets[position] || {name: facetName};
3610
+ excludes.forEach(function (facetValue) {
3611
+ self.facets[position] = self.facets[position] || {
3612
+ name: facetName
3613
+ };
3979
3614
  self.facets[position].data = self.facets[position].data || {};
3980
3615
  self.facets[position].data[facetValue] = 0;
3981
3616
  });
@@ -3994,7 +3629,6 @@
3994
3629
  * @type {Array}
3995
3630
  */
3996
3631
  this.disjunctiveFacets = compact(this.disjunctiveFacets);
3997
-
3998
3632
  this._state = state;
3999
3633
  }
4000
3634
 
@@ -4004,14 +3638,11 @@
4004
3638
  * @param {string} name name of the faceted attribute
4005
3639
  * @return {SearchResults.Facet} the facet object
4006
3640
  */
4007
- SearchResults.prototype.getFacetByName = function(name) {
3641
+ SearchResults.prototype.getFacetByName = function (name) {
4008
3642
  function predicate(facet) {
4009
3643
  return facet.name === name;
4010
3644
  }
4011
-
4012
- return find$1(this.facets, predicate) ||
4013
- find$1(this.disjunctiveFacets, predicate) ||
4014
- find$1(this.hierarchicalFacets, predicate);
3645
+ return find$1(this.facets, predicate) || find$1(this.disjunctiveFacets, predicate) || find$1(this.hierarchicalFacets, predicate);
4015
3646
  };
4016
3647
 
4017
3648
  /**
@@ -4025,12 +3656,10 @@
4025
3656
  function predicate(facet) {
4026
3657
  return facet.name === attribute;
4027
3658
  }
4028
-
4029
3659
  if (results._state.isConjunctiveFacet(attribute)) {
4030
3660
  var facet = find$1(results.facets, predicate);
4031
3661
  if (!facet) return [];
4032
-
4033
- return Object.keys(facet.data).map(function(name) {
3662
+ return Object.keys(facet.data).map(function (name) {
4034
3663
  var value = escapeFacetValue$2(name);
4035
3664
  return {
4036
3665
  name: name,
@@ -4043,8 +3672,7 @@
4043
3672
  } else if (results._state.isDisjunctiveFacet(attribute)) {
4044
3673
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
4045
3674
  if (!disjunctiveFacet) return [];
4046
-
4047
- return Object.keys(disjunctiveFacet.data).map(function(name) {
3675
+ return Object.keys(disjunctiveFacet.data).map(function (name) {
4048
3676
  var value = escapeFacetValue$2(name);
4049
3677
  return {
4050
3678
  name: name,
@@ -4056,29 +3684,31 @@
4056
3684
  } else if (results._state.isHierarchicalFacet(attribute)) {
4057
3685
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
4058
3686
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
4059
-
4060
3687
  var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
4061
- var currentRefinementSplit = unescapeFacetValue$3(
4062
- results._state.getHierarchicalRefinement(attribute)[0] || ''
4063
- ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
3688
+ var separator = results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
3689
+ var currentRefinement = unescapeFacetValue$3(results._state.getHierarchicalRefinement(attribute)[0] || '');
3690
+ if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
3691
+ currentRefinement = currentRefinement.replace(hierarchicalFacet.rootPath + separator, '');
3692
+ }
3693
+ var currentRefinementSplit = currentRefinement.split(separator);
4064
3694
  currentRefinementSplit.unshift(attribute);
4065
-
4066
3695
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
4067
-
4068
3696
  return hierarchicalFacetValues;
4069
3697
  }
3698
+ return undefined;
4070
3699
  }
4071
3700
 
4072
3701
  /**
4073
3702
  * Set the isRefined of a hierarchical facet result based on the current state.
4074
3703
  * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
4075
- * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
3704
+ * @param {string[]} currentRefinement array of parts of the current hierarchical refinement
4076
3705
  * @param {number} depth recursion depth in the currentRefinement
3706
+ * @return {undefined} function mutates the item
4077
3707
  */
4078
3708
  function setIsRefined(item, currentRefinement, depth) {
4079
3709
  item.isRefined = item.name === currentRefinement[depth];
4080
3710
  if (item.data) {
4081
- item.data.forEach(function(child) {
3711
+ item.data.forEach(function (child) {
4082
3712
  setIsRefined(child, currentRefinement, depth + 1);
4083
3713
  });
4084
3714
  }
@@ -4087,32 +3717,30 @@
4087
3717
  /**
4088
3718
  * Sort nodes of a hierarchical or disjunctive facet results
4089
3719
  * @private
4090
- * @param {function} sortFn
3720
+ * @param {function} sortFn sort function to apply
4091
3721
  * @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
4092
3722
  * @param {string[]} names attribute names
4093
3723
  * @param {number} [level=0] current index in the names array
3724
+ * @return {HierarchicalFacet|Array} sorted node
4094
3725
  */
4095
3726
  function recSort(sortFn, node, names, level) {
4096
3727
  level = level || 0;
4097
-
4098
3728
  if (Array.isArray(node)) {
4099
3729
  return sortFn(node, names[level]);
4100
3730
  }
4101
-
4102
3731
  if (!node.data || node.data.length === 0) {
4103
3732
  return node;
4104
3733
  }
4105
-
4106
- var children = node.data.map(function(childNode) {
3734
+ var children = node.data.map(function (childNode) {
4107
3735
  return recSort(sortFn, childNode, names, level + 1);
4108
3736
  });
4109
3737
  var sortedChildren = sortFn(children, names[level]);
4110
- var newNode = defaultsPure({data: sortedChildren}, node);
3738
+ var newNode = defaultsPure({
3739
+ data: sortedChildren
3740
+ }, node);
4111
3741
  return newNode;
4112
3742
  }
4113
-
4114
3743
  SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
4115
-
4116
3744
  function vanillaSortFn(order, data) {
4117
3745
  return data.sort(order);
4118
3746
  }
@@ -4128,23 +3756,21 @@
4128
3756
  * Sorts facet arrays via their facet ordering
4129
3757
  * @param {Array} facetValues the values
4130
3758
  * @param {FacetOrdering} facetOrdering the ordering
4131
- * @returns {Array}
3759
+ * @returns {Array} the sorted facet values
4132
3760
  */
4133
3761
  function sortViaFacetOrdering(facetValues, facetOrdering) {
4134
3762
  var orderedFacets = [];
4135
3763
  var remainingFacets = [];
4136
-
4137
3764
  var order = facetOrdering.order || [];
4138
3765
  /**
4139
3766
  * an object with the keys being the values in order, the values their index:
4140
3767
  * ['one', 'two'] -> { one: 0, two: 1 }
4141
3768
  */
4142
- var reverseOrder = order.reduce(function(acc, name, i) {
3769
+ var reverseOrder = order.reduce(function (acc, name, i) {
4143
3770
  acc[name] = i;
4144
3771
  return acc;
4145
3772
  }, {});
4146
-
4147
- facetValues.forEach(function(item) {
3773
+ facetValues.forEach(function (item) {
4148
3774
  // hierarchical facets get sorted using their raw name
4149
3775
  var name = item.path || item.name;
4150
3776
  if (reverseOrder[name] !== undefined) {
@@ -4153,11 +3779,9 @@
4153
3779
  remainingFacets.push(item);
4154
3780
  }
4155
3781
  });
4156
-
4157
- orderedFacets = orderedFacets.filter(function(facet) {
3782
+ orderedFacets = orderedFacets.filter(function (facet) {
4158
3783
  return facet;
4159
3784
  });
4160
-
4161
3785
  var sortRemainingBy = facetOrdering.sortRemainingBy;
4162
3786
  var ordering;
4163
3787
  if (sortRemainingBy === 'hidden') {
@@ -4167,24 +3791,16 @@
4167
3791
  } else {
4168
3792
  ordering = [['count'], ['desc']];
4169
3793
  }
4170
-
4171
- return orderedFacets.concat(
4172
- orderBy_1(remainingFacets, ordering[0], ordering[1])
4173
- );
3794
+ return orderedFacets.concat(orderBy_1(remainingFacets, ordering[0], ordering[1]));
4174
3795
  }
4175
3796
 
4176
3797
  /**
4177
3798
  * @param {SearchResults} results the search results class
4178
3799
  * @param {string} attribute the attribute to retrieve ordering of
4179
- * @returns {FacetOrdering=}
3800
+ * @returns {FacetOrdering | undefined} the facet ordering
4180
3801
  */
4181
3802
  function getFacetOrdering(results, attribute) {
4182
- return (
4183
- results.renderingContent &&
4184
- results.renderingContent.facetOrdering &&
4185
- results.renderingContent.facetOrdering.values &&
4186
- results.renderingContent.facetOrdering.values[attribute]
4187
- );
3803
+ return results.renderingContent && results.renderingContent.facetOrdering && results.renderingContent.facetOrdering.values && results.renderingContent.facetOrdering.values[attribute];
4188
3804
  }
4189
3805
 
4190
3806
  /**
@@ -4235,12 +3851,11 @@
4235
3851
  * });
4236
3852
  * });
4237
3853
  */
4238
- SearchResults.prototype.getFacetValues = function(attribute, opts) {
3854
+ SearchResults.prototype.getFacetValues = function (attribute, opts) {
4239
3855
  var facetValues = extractNormalizedFacetValues(this, attribute);
4240
3856
  if (!facetValues) {
4241
3857
  return undefined;
4242
3858
  }
4243
-
4244
3859
  var options = defaultsPure({}, opts, {
4245
3860
  sortBy: SearchResults.DEFAULT_SORT,
4246
3861
  // if no sortBy is given, attempt to sort based on facetOrdering
@@ -4248,6 +3863,7 @@
4248
3863
  facetOrdering: !(opts && opts.sortBy)
4249
3864
  });
4250
3865
 
3866
+ // eslint-disable-next-line consistent-this
4251
3867
  var results = this;
4252
3868
  var attributes;
4253
3869
  if (Array.isArray(facetValues)) {
@@ -4256,25 +3872,20 @@
4256
3872
  var config = results._state.getHierarchicalFacetByName(facetValues.name);
4257
3873
  attributes = config.attributes;
4258
3874
  }
4259
-
4260
- return recSort(function(data, facetName) {
3875
+ return recSort(function (data, facetName) {
4261
3876
  if (options.facetOrdering) {
4262
3877
  var facetOrdering = getFacetOrdering(results, facetName);
4263
- if (Boolean(facetOrdering)) {
3878
+ if (facetOrdering) {
4264
3879
  return sortViaFacetOrdering(data, facetOrdering);
4265
3880
  }
4266
3881
  }
4267
-
4268
3882
  if (Array.isArray(options.sortBy)) {
4269
3883
  var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
4270
3884
  return orderBy_1(data, order[0], order[1]);
4271
3885
  } else if (typeof options.sortBy === 'function') {
4272
3886
  return vanillaSortFn(options.sortBy, data);
4273
3887
  }
4274
- throw new Error(
4275
- 'options.sortBy is optional but if defined it must be ' +
4276
- 'either an array of string (predicates) or a sorting function'
4277
- );
3888
+ throw new Error('options.sortBy is optional but if defined it must be ' + 'either an array of string (predicates) or a sorting function');
4278
3889
  }, facetValues, attributes);
4279
3890
  };
4280
3891
 
@@ -4284,13 +3895,12 @@
4284
3895
  * @param {string} attribute name of the faceted attribute
4285
3896
  * @return {object} The stats of the facet
4286
3897
  */
4287
- SearchResults.prototype.getFacetStats = function(attribute) {
3898
+ SearchResults.prototype.getFacetStats = function (attribute) {
4288
3899
  if (this._state.isConjunctiveFacet(attribute)) {
4289
3900
  return getFacetStatsIfAvailable(this.facets, attribute);
4290
3901
  } else if (this._state.isDisjunctiveFacet(attribute)) {
4291
3902
  return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
4292
3903
  }
4293
-
4294
3904
  return undefined;
4295
3905
  };
4296
3906
 
@@ -4301,10 +3911,11 @@
4301
3911
 
4302
3912
  /**
4303
3913
  * @param {FacetListItem[]} facetList (has more items, but enough for here)
4304
- * @param {string} facetName
3914
+ * @param {string} facetName The attribute to look for
3915
+ * @return {object|undefined} The stats of the facet
4305
3916
  */
4306
3917
  function getFacetStatsIfAvailable(facetList, facetName) {
4307
- var data = find$1(facetList, function(facet) {
3918
+ var data = find$1(facetList, function (facet) {
4308
3919
  return facet.name === facetName;
4309
3920
  });
4310
3921
  return data && data.stats;
@@ -4322,40 +3933,35 @@
4322
3933
  *
4323
3934
  * @return {Array.<Refinement>} all the refinements
4324
3935
  */
4325
- SearchResults.prototype.getRefinements = function() {
3936
+ SearchResults.prototype.getRefinements = function () {
4326
3937
  var state = this._state;
3938
+ // eslint-disable-next-line consistent-this
4327
3939
  var results = this;
4328
3940
  var res = [];
4329
-
4330
- Object.keys(state.facetsRefinements).forEach(function(attributeName) {
4331
- state.facetsRefinements[attributeName].forEach(function(name) {
3941
+ Object.keys(state.facetsRefinements).forEach(function (attributeName) {
3942
+ state.facetsRefinements[attributeName].forEach(function (name) {
4332
3943
  res.push(getRefinement(state, 'facet', attributeName, name, results.facets));
4333
3944
  });
4334
3945
  });
4335
-
4336
- Object.keys(state.facetsExcludes).forEach(function(attributeName) {
4337
- state.facetsExcludes[attributeName].forEach(function(name) {
3946
+ Object.keys(state.facetsExcludes).forEach(function (attributeName) {
3947
+ state.facetsExcludes[attributeName].forEach(function (name) {
4338
3948
  res.push(getRefinement(state, 'exclude', attributeName, name, results.facets));
4339
3949
  });
4340
3950
  });
4341
-
4342
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function(attributeName) {
4343
- state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
3951
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (attributeName) {
3952
+ state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
4344
3953
  res.push(getRefinement(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
4345
3954
  });
4346
3955
  });
4347
-
4348
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function(attributeName) {
4349
- state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
3956
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (attributeName) {
3957
+ state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
4350
3958
  res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
4351
3959
  });
4352
3960
  });
4353
-
4354
-
4355
- Object.keys(state.numericRefinements).forEach(function(attributeName) {
3961
+ Object.keys(state.numericRefinements).forEach(function (attributeName) {
4356
3962
  var operators = state.numericRefinements[attributeName];
4357
- Object.keys(operators).forEach(function(operator) {
4358
- operators[operator].forEach(function(value) {
3963
+ Object.keys(operators).forEach(function (operator) {
3964
+ operators[operator].forEach(function (value) {
4359
3965
  res.push({
4360
3966
  type: 'numeric',
4361
3967
  attributeName: attributeName,
@@ -4366,11 +3972,13 @@
4366
3972
  });
4367
3973
  });
4368
3974
  });
4369
-
4370
- state.tagRefinements.forEach(function(name) {
4371
- res.push({type: 'tag', attributeName: '_tags', name: name});
3975
+ state.tagRefinements.forEach(function (name) {
3976
+ res.push({
3977
+ type: 'tag',
3978
+ attributeName: '_tags',
3979
+ name: name
3980
+ });
4372
3981
  });
4373
-
4374
3982
  return res;
4375
3983
  };
4376
3984
 
@@ -4382,19 +3990,19 @@
4382
3990
  */
4383
3991
 
4384
3992
  /**
4385
- * @param {*} state
4386
- * @param {*} type
4387
- * @param {string} attributeName
4388
- * @param {*} name
4389
- * @param {Facet[]} resultsFacets
3993
+ * @param {SearchParameters} state the current state
3994
+ * @param {string} type the type of the refinement
3995
+ * @param {string} attributeName The attribute of the facet
3996
+ * @param {*} name The name of the facet
3997
+ * @param {Facet[]} resultsFacets facets from the results
3998
+ * @return {Refinement} the refinement
4390
3999
  */
4391
4000
  function getRefinement(state, type, attributeName, name, resultsFacets) {
4392
- var facet = find$1(resultsFacets, function(f) {
4001
+ var facet = find$1(resultsFacets, function (f) {
4393
4002
  return f.name === attributeName;
4394
4003
  });
4395
4004
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
4396
- var exhaustive = (facet && facet.exhaustive) || false;
4397
-
4005
+ var exhaustive = facet && facet.exhaustive || false;
4398
4006
  return {
4399
4007
  type: type,
4400
4008
  attributeName: attributeName,
@@ -4405,31 +4013,28 @@
4405
4013
  }
4406
4014
 
4407
4015
  /**
4408
- * @param {*} state
4409
- * @param {string} attributeName
4410
- * @param {*} name
4411
- * @param {Facet[]} resultsFacets
4016
+ * @param {SearchParameters} state the current state
4017
+ * @param {string} attributeName the attribute of the hierarchical facet
4018
+ * @param {string} name the name of the facet
4019
+ * @param {Facet[]} resultsFacets facets from the results
4020
+ * @return {HierarchicalFacet} the hierarchical facet
4412
4021
  */
4413
4022
  function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
4414
4023
  var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
4415
4024
  var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
4416
4025
  var split = name.split(separator);
4417
- var rootFacet = find$1(resultsFacets, function(facet) {
4026
+ var rootFacet = find$1(resultsFacets, function (facet) {
4418
4027
  return facet.name === attributeName;
4419
4028
  });
4420
-
4421
- var facet = split.reduce(function(intermediateFacet, part) {
4422
- var newFacet =
4423
- intermediateFacet && find$1(intermediateFacet.data, function(f) {
4424
- return f.name === part;
4425
- });
4029
+ var facet = split.reduce(function (intermediateFacet, part) {
4030
+ var newFacet = intermediateFacet && find$1(intermediateFacet.data, function (f) {
4031
+ return f.name === part;
4032
+ });
4426
4033
  return newFacet !== undefined ? newFacet : intermediateFacet;
4427
4034
  }, rootFacet);
4428
-
4429
- var count = (facet && facet.count) || 0;
4430
- var exhaustive = (facet && facet.exhaustive) || false;
4431
- var path = (facet && facet.path) || '';
4432
-
4035
+ var count = facet && facet.count || 0;
4036
+ var exhaustive = facet && facet.exhaustive || false;
4037
+ var path = facet && facet.path || '';
4433
4038
  return {
4434
4039
  type: 'hierarchical',
4435
4040
  attributeName: attributeName,
@@ -4438,7 +4043,6 @@
4438
4043
  exhaustive: exhaustive
4439
4044
  };
4440
4045
  }
4441
-
4442
4046
  var SearchResults_1 = SearchResults;
4443
4047
 
4444
4048
  // Copyright Joyent, Inc. and other Node contributors.
@@ -4754,7 +4358,6 @@
4754
4358
  }
4755
4359
  });
4756
4360
  }
4757
-
4758
4361
  var inherits_1 = inherits;
4759
4362
 
4760
4363
  /**
@@ -4766,13 +4369,14 @@
4766
4369
  * - result: when the response is retrieved from Algolia and is processed.
4767
4370
  * This event contains a {@link SearchResults} object and the
4768
4371
  * {@link SearchParameters} corresponding to this answer.
4372
+ * @param {AlgoliaSearchHelper} mainHelper the main helper
4373
+ * @param {function} fn the function to create the derived state
4769
4374
  */
4770
4375
  function DerivedHelper(mainHelper, fn) {
4771
4376
  this.main = mainHelper;
4772
4377
  this.fn = fn;
4773
4378
  this.lastResults = null;
4774
4379
  }
4775
-
4776
4380
  inherits_1(DerivedHelper, events);
4777
4381
 
4778
4382
  /**
@@ -4780,33 +4384,30 @@
4780
4384
  * @return {undefined}
4781
4385
  * @throws Error if the derived helper is already detached
4782
4386
  */
4783
- DerivedHelper.prototype.detach = function() {
4387
+ DerivedHelper.prototype.detach = function () {
4784
4388
  this.removeAllListeners();
4785
4389
  this.main.detachDerivedHelper(this);
4786
4390
  };
4787
-
4788
- DerivedHelper.prototype.getModifiedState = function(parameters) {
4391
+ DerivedHelper.prototype.getModifiedState = function (parameters) {
4789
4392
  return this.fn(parameters);
4790
4393
  };
4791
-
4792
4394
  var DerivedHelper_1 = DerivedHelper;
4793
4395
 
4794
4396
  function sortObject(obj) {
4795
- return Object.keys(obj)
4796
- .sort(function(a, b) {
4797
- return a.localeCompare(b);
4798
- })
4799
- .reduce(function(acc, curr) {
4800
- acc[curr] = obj[curr];
4801
- return acc;
4802
- }, {});
4397
+ return Object.keys(obj).sort(function (a, b) {
4398
+ return a.localeCompare(b);
4399
+ }).reduce(function (acc, curr) {
4400
+ acc[curr] = obj[curr];
4401
+ return acc;
4402
+ }, {});
4803
4403
  }
4804
-
4805
4404
  var requestBuilder = {
4806
4405
  /**
4807
4406
  * Get all the queries to send to the client, those queries can used directly
4808
4407
  * with the Algolia client.
4809
4408
  * @private
4409
+ * @param {string} index The name of the index
4410
+ * @param {SearchParameters} state The state from which to get the queries
4810
4411
  * @return {object[]} The queries
4811
4412
  */
4812
4413
  _getQueries: function getQueries(index, state) {
@@ -4819,7 +4420,7 @@
4819
4420
  });
4820
4421
 
4821
4422
  // One for each disjunctive facets
4822
- state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
4423
+ state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
4823
4424
  queries.push({
4824
4425
  indexName: index,
4825
4426
  params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
@@ -4827,7 +4428,7 @@
4827
4428
  });
4828
4429
 
4829
4430
  // More to get the parent levels of the hierarchical facets when refined
4830
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
4431
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
4831
4432
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
4832
4433
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
4833
4434
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
@@ -4836,75 +4437,58 @@
4836
4437
  // we want to get all parent values
4837
4438
  if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
4838
4439
  // We generate a map of the filters we will use for our facet values queries
4839
- var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
4840
- function createFiltersMap(map, segment, level) {
4841
- return map.concat({
4842
- attribute: hierarchicalFacet.attributes[level],
4843
- value: level === 0
4844
- ? segment
4845
- : [map[map.length - 1].value, segment].join(separator)
4846
- });
4847
- }
4848
- , []);
4849
-
4850
- filtersMap.forEach(function(filter, level) {
4851
- var params = requestBuilder._getDisjunctiveFacetSearchParams(
4852
- state,
4853
- filter.attribute,
4854
- level === 0
4855
- );
4440
+ var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(function createFiltersMap(map, segment, level) {
4441
+ return map.concat({
4442
+ attribute: hierarchicalFacet.attributes[level],
4443
+ value: level === 0 ? segment : [map[map.length - 1].value, segment].join(separator)
4444
+ });
4445
+ }, []);
4446
+ filtersMap.forEach(function (filter, level) {
4447
+ var params = requestBuilder._getDisjunctiveFacetSearchParams(state, filter.attribute, level === 0);
4856
4448
 
4857
4449
  // Keep facet filters unrelated to current hierarchical attributes
4858
4450
  function hasHierarchicalFacetFilter(value) {
4859
- return hierarchicalFacet.attributes.some(function(attribute) {
4451
+ return hierarchicalFacet.attributes.some(function (attribute) {
4860
4452
  return attribute === value.split(':')[0];
4861
4453
  });
4862
4454
  }
4863
-
4864
- var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
4455
+ var filteredFacetFilters = (params.facetFilters || []).reduce(function (acc, facetFilter) {
4865
4456
  if (Array.isArray(facetFilter)) {
4866
- var filtered = facetFilter.filter(function(filterValue) {
4457
+ var filtered = facetFilter.filter(function (filterValue) {
4867
4458
  return !hasHierarchicalFacetFilter(filterValue);
4868
4459
  });
4869
-
4870
4460
  if (filtered.length > 0) {
4871
4461
  acc.push(filtered);
4872
4462
  }
4873
4463
  }
4874
-
4875
4464
  if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
4876
4465
  acc.push(facetFilter);
4877
4466
  }
4878
-
4879
4467
  return acc;
4880
4468
  }, []);
4881
-
4882
4469
  var parent = filtersMap[level - 1];
4883
4470
  if (level > 0) {
4884
4471
  params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
4885
4472
  } else {
4886
4473
  params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
4887
4474
  }
4888
-
4889
- queries.push({indexName: index, params: params});
4475
+ queries.push({
4476
+ indexName: index,
4477
+ params: params
4478
+ });
4890
4479
  });
4891
4480
  }
4892
4481
  });
4893
-
4894
4482
  return queries;
4895
4483
  },
4896
-
4897
4484
  /**
4898
4485
  * Build search parameters used to fetch hits
4899
4486
  * @private
4900
- * @return {object.<string, any>}
4487
+ * @param {SearchParameters} state The state from which to get the queries
4488
+ * @return {object.<string, any>} The search parameters for hits
4901
4489
  */
4902
- _getHitsSearchParams: function(state) {
4903
- var facets = state.facets
4904
- .concat(state.disjunctiveFacets)
4905
- .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
4906
-
4907
-
4490
+ _getHitsSearchParams: function _getHitsSearchParams(state) {
4491
+ var facets = state.facets.concat(state.disjunctiveFacets).concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
4908
4492
  var facetFilters = requestBuilder._getFacetFilters(state);
4909
4493
  var numericFilters = requestBuilder._getNumericFilters(state);
4910
4494
  var tagFilters = requestBuilder._getTagFilters(state);
@@ -4912,26 +4496,23 @@
4912
4496
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
4913
4497
  tagFilters: tagFilters
4914
4498
  };
4915
-
4916
4499
  if (facetFilters.length > 0) {
4917
4500
  additionalParams.facetFilters = facetFilters;
4918
4501
  }
4919
-
4920
4502
  if (numericFilters.length > 0) {
4921
4503
  additionalParams.numericFilters = numericFilters;
4922
4504
  }
4923
-
4924
- return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
4505
+ return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
4925
4506
  },
4926
-
4927
4507
  /**
4928
4508
  * Build search parameters used to fetch a disjunctive facet
4929
4509
  * @private
4510
+ * @param {SearchParameters} state The state from which to get the queries
4930
4511
  * @param {string} facet the associated facet name
4931
4512
  * @param {boolean} hierarchicalRootLevel ?? FIXME
4932
- * @return {object}
4513
+ * @return {object} The search parameters for a disjunctive facet
4933
4514
  */
4934
- _getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
4515
+ _getDisjunctiveFacetSearchParams: function _getDisjunctiveFacetSearchParams(state, facet, hierarchicalRootLevel) {
4935
4516
  var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
4936
4517
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
4937
4518
  var tagFilters = requestBuilder._getTagFilters(state);
@@ -4941,55 +4522,43 @@
4941
4522
  analytics: false,
4942
4523
  clickAnalytics: false
4943
4524
  };
4944
-
4945
4525
  if (tagFilters.length > 0) {
4946
4526
  additionalParams.tagFilters = tagFilters;
4947
4527
  }
4948
-
4949
4528
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
4950
-
4951
4529
  if (hierarchicalFacet) {
4952
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
4953
- state,
4954
- hierarchicalFacet,
4955
- hierarchicalRootLevel
4956
- );
4530
+ additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, hierarchicalRootLevel);
4957
4531
  } else {
4958
4532
  additionalParams.facets = facet;
4959
4533
  }
4960
-
4961
4534
  if (numericFilters.length > 0) {
4962
4535
  additionalParams.numericFilters = numericFilters;
4963
4536
  }
4964
-
4965
4537
  if (facetFilters.length > 0) {
4966
4538
  additionalParams.facetFilters = facetFilters;
4967
4539
  }
4968
-
4969
- return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
4540
+ return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
4970
4541
  },
4971
-
4972
4542
  /**
4973
4543
  * Return the numeric filters in an algolia request fashion
4974
4544
  * @private
4545
+ * @param {SearchParameters} state the state from which to get the filters
4975
4546
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
4976
4547
  * @return {string[]} the numeric filters in the algolia format
4977
4548
  */
4978
- _getNumericFilters: function(state, facetName) {
4549
+ _getNumericFilters: function _getNumericFilters(state, facetName) {
4979
4550
  if (state.numericFilters) {
4980
4551
  return state.numericFilters;
4981
4552
  }
4982
-
4983
4553
  var numericFilters = [];
4984
-
4985
- Object.keys(state.numericRefinements).forEach(function(attribute) {
4554
+ Object.keys(state.numericRefinements).forEach(function (attribute) {
4986
4555
  var operators = state.numericRefinements[attribute] || {};
4987
- Object.keys(operators).forEach(function(operator) {
4556
+ Object.keys(operators).forEach(function (operator) {
4988
4557
  var values = operators[operator] || [];
4989
4558
  if (facetName !== attribute) {
4990
- values.forEach(function(value) {
4559
+ values.forEach(function (value) {
4991
4560
  if (Array.isArray(value)) {
4992
- var vs = value.map(function(v) {
4561
+ var vs = value.map(function (v) {
4993
4562
  return attribute + operator + v;
4994
4563
  });
4995
4564
  numericFilters.push(vs);
@@ -5000,74 +4569,64 @@
5000
4569
  }
5001
4570
  });
5002
4571
  });
5003
-
5004
4572
  return numericFilters;
5005
4573
  },
5006
-
5007
4574
  /**
5008
- * Return the tags filters depending
4575
+ * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
5009
4576
  * @private
5010
- * @return {string}
4577
+ * @param {SearchParameters} state the state from which to get the filters
4578
+ * @return {string} Tag filters in a single string
5011
4579
  */
5012
- _getTagFilters: function(state) {
4580
+ _getTagFilters: function _getTagFilters(state) {
5013
4581
  if (state.tagFilters) {
5014
4582
  return state.tagFilters;
5015
4583
  }
5016
-
5017
4584
  return state.tagRefinements.join(',');
5018
4585
  },
5019
-
5020
-
5021
4586
  /**
5022
4587
  * Build facetFilters parameter based on current refinements. The array returned
5023
4588
  * contains strings representing the facet filters in the algolia format.
5024
4589
  * @private
4590
+ * @param {SearchParameters} state The state from which to get the queries
5025
4591
  * @param {string} [facet] if set, the current disjunctive facet
5026
- * @return {array.<string>}
4592
+ * @param {boolean} [hierarchicalRootLevel] ?? FIXME
4593
+ * @return {array.<string>} The facet filters in the algolia format
5027
4594
  */
5028
- _getFacetFilters: function(state, facet, hierarchicalRootLevel) {
4595
+ _getFacetFilters: function _getFacetFilters(state, facet, hierarchicalRootLevel) {
5029
4596
  var facetFilters = [];
5030
-
5031
4597
  var facetsRefinements = state.facetsRefinements || {};
5032
- Object.keys(facetsRefinements).forEach(function(facetName) {
4598
+ Object.keys(facetsRefinements).forEach(function (facetName) {
5033
4599
  var facetValues = facetsRefinements[facetName] || [];
5034
- facetValues.forEach(function(facetValue) {
4600
+ facetValues.forEach(function (facetValue) {
5035
4601
  facetFilters.push(facetName + ':' + facetValue);
5036
4602
  });
5037
4603
  });
5038
-
5039
4604
  var facetsExcludes = state.facetsExcludes || {};
5040
- Object.keys(facetsExcludes).forEach(function(facetName) {
4605
+ Object.keys(facetsExcludes).forEach(function (facetName) {
5041
4606
  var facetValues = facetsExcludes[facetName] || [];
5042
- facetValues.forEach(function(facetValue) {
4607
+ facetValues.forEach(function (facetValue) {
5043
4608
  facetFilters.push(facetName + ':-' + facetValue);
5044
4609
  });
5045
4610
  });
5046
-
5047
4611
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
5048
- Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
4612
+ Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
5049
4613
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
5050
4614
  if (facetName === facet || !facetValues || facetValues.length === 0) {
5051
4615
  return;
5052
4616
  }
5053
4617
  var orFilters = [];
5054
-
5055
- facetValues.forEach(function(facetValue) {
4618
+ facetValues.forEach(function (facetValue) {
5056
4619
  orFilters.push(facetName + ':' + facetValue);
5057
4620
  });
5058
-
5059
4621
  facetFilters.push(orFilters);
5060
4622
  });
5061
-
5062
4623
  var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
5063
- Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
4624
+ Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
5064
4625
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
5065
4626
  var facetValue = facetValues[0];
5066
-
5067
4627
  if (facetValue === undefined) {
5068
4628
  return;
5069
4629
  }
5070
-
5071
4630
  var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
5072
4631
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5073
4632
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -5078,11 +4637,9 @@
5078
4637
  if (facet === facetName) {
5079
4638
  // if we are at the root level already, no need to ask for facet values, we get them from
5080
4639
  // the hits query
5081
- if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
5082
- (rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
4640
+ if (facetValue.indexOf(separator) === -1 || !rootPath && hierarchicalRootLevel === true || rootPath && rootPath.split(separator).length === facetValue.split(separator).length) {
5083
4641
  return;
5084
4642
  }
5085
-
5086
4643
  if (!rootPath) {
5087
4644
  attributesIndex = facetValue.split(separator).length - 2;
5088
4645
  facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
@@ -5090,56 +4647,45 @@
5090
4647
  attributesIndex = rootPath.split(separator).length - 1;
5091
4648
  facetValue = rootPath;
5092
4649
  }
5093
-
5094
4650
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
5095
4651
  } else {
5096
4652
  attributesIndex = facetValue.split(separator).length - 1;
5097
-
5098
4653
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
5099
4654
  }
5100
-
5101
4655
  if (attributeToRefine) {
5102
4656
  facetFilters.push([attributeToRefine + ':' + facetValue]);
5103
4657
  }
5104
4658
  });
5105
-
5106
4659
  return facetFilters;
5107
4660
  },
5108
-
5109
- _getHitsHierarchicalFacetsAttributes: function(state) {
4661
+ _getHitsHierarchicalFacetsAttributes: function _getHitsHierarchicalFacetsAttributes(state) {
5110
4662
  var out = [];
5111
-
5112
4663
  return state.hierarchicalFacets.reduce(
5113
- // ask for as much levels as there's hierarchical refinements
5114
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
5115
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
5116
-
5117
- // if no refinement, ask for root level
5118
- if (!hierarchicalRefinement) {
5119
- allAttributes.push(hierarchicalFacet.attributes[0]);
5120
- return allAttributes;
5121
- }
5122
-
5123
- var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5124
- var level = hierarchicalRefinement.split(separator).length;
5125
- var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
5126
-
5127
- return allAttributes.concat(newAttributes);
5128
- }, out);
4664
+ // ask for as much levels as there's hierarchical refinements
4665
+ function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
4666
+ var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
4667
+
4668
+ // if no refinement, ask for root level
4669
+ if (!hierarchicalRefinement) {
4670
+ allAttributes.push(hierarchicalFacet.attributes[0]);
4671
+ return allAttributes;
4672
+ }
4673
+ var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
4674
+ var level = hierarchicalRefinement.split(separator).length;
4675
+ var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
4676
+ return allAttributes.concat(newAttributes);
4677
+ }, out);
5129
4678
  },
5130
-
5131
- _getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
4679
+ _getDisjunctiveHierarchicalFacetAttribute: function _getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, rootLevel) {
5132
4680
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5133
4681
  if (rootLevel === true) {
5134
4682
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
5135
4683
  var attributeIndex = 0;
5136
-
5137
4684
  if (rootPath) {
5138
4685
  attributeIndex = rootPath.split(separator).length;
5139
4686
  }
5140
4687
  return [hierarchicalFacet.attributes[attributeIndex]];
5141
4688
  }
5142
-
5143
4689
  var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
5144
4690
  // if refinement is 'beers > IPA > Flying dog',
5145
4691
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
@@ -5147,11 +4693,8 @@
5147
4693
  var parentLevel = hierarchicalRefinement.split(separator).length - 1;
5148
4694
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
5149
4695
  },
5150
-
5151
- getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
5152
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
5153
- state.clearRefinements(facetName) :
5154
- state;
4696
+ getSearchForFacetQuery: function getSearchForFacetQuery(facetName, query, maxFacetHits, state) {
4697
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ? state.clearRefinements(facetName) : state;
5155
4698
  var searchForFacetSearchParameters = {
5156
4699
  facetQuery: query,
5157
4700
  facetName: facetName
@@ -5159,17 +4702,12 @@
5159
4702
  if (typeof maxFacetHits === 'number') {
5160
4703
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
5161
4704
  }
5162
- return sortObject(merge_1(
5163
- {},
5164
- requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
5165
- searchForFacetSearchParameters
5166
- ));
4705
+ return sortObject(merge$1({}, requestBuilder._getHitsSearchParams(stateForSearchForFacetValues), searchForFacetSearchParameters));
5167
4706
  }
5168
4707
  };
5169
-
5170
4708
  var requestBuilder_1 = requestBuilder;
5171
4709
 
5172
- var version$1 = '3.13.0';
4710
+ var version$1 = '3.13.3';
5173
4711
 
5174
4712
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
5175
4713
 
@@ -5280,7 +4818,6 @@
5280
4818
  if (typeof client.addAlgoliaAgent === 'function') {
5281
4819
  client.addAlgoliaAgent('JS Helper (' + version$1 + ')');
5282
4820
  }
5283
-
5284
4821
  this.setClient(client);
5285
4822
  var opts = options || {};
5286
4823
  opts.index = index;
@@ -5291,7 +4828,6 @@
5291
4828
  this.derivedHelpers = [];
5292
4829
  this._currentNbQueries = 0;
5293
4830
  }
5294
-
5295
4831
  inherits_1(AlgoliaSearchHelper, events);
5296
4832
 
5297
4833
  /**
@@ -5299,19 +4835,22 @@
5299
4835
  * method is called, it triggers a `search` event. The results will
5300
4836
  * be available through the `result` event. If an error occurs, an
5301
4837
  * `error` will be fired instead.
5302
- * @return {AlgoliaSearchHelper}
4838
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5303
4839
  * @fires search
5304
4840
  * @fires result
5305
4841
  * @fires error
5306
4842
  * @chainable
5307
4843
  */
5308
- AlgoliaSearchHelper.prototype.search = function() {
5309
- this._search({onlyWithDerivedHelpers: false});
4844
+ AlgoliaSearchHelper.prototype.search = function () {
4845
+ this._search({
4846
+ onlyWithDerivedHelpers: false
4847
+ });
5310
4848
  return this;
5311
4849
  };
5312
-
5313
- AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
5314
- this._search({onlyWithDerivedHelpers: true});
4850
+ AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
4851
+ this._search({
4852
+ onlyWithDerivedHelpers: true
4853
+ });
5315
4854
  return this;
5316
4855
  };
5317
4856
 
@@ -5320,7 +4859,7 @@
5320
4859
  * for the hits
5321
4860
  * @return {object} Query Parameters
5322
4861
  */
5323
- AlgoliaSearchHelper.prototype.getQuery = function() {
4862
+ AlgoliaSearchHelper.prototype.getQuery = function () {
5324
4863
  var state = this.state;
5325
4864
  return requestBuilder_1._getHitsSearchParams(state);
5326
4865
  };
@@ -5332,7 +4871,7 @@
5332
4871
  * same as a search call before calling searchOnce.
5333
4872
  * @param {object} options can contain all the parameters that can be set to SearchParameters
5334
4873
  * plus the index
5335
- * @param {function} [callback] optional callback executed when the response from the
4874
+ * @param {function} [cb] optional callback executed when the response from the
5336
4875
  * server is back.
5337
4876
  * @return {promise|undefined} if a callback is passed the method returns undefined
5338
4877
  * otherwise it returns a promise containing an object with two keys :
@@ -5361,41 +4900,32 @@
5361
4900
  * // }
5362
4901
  * }
5363
4902
  */
5364
- AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
4903
+ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
5365
4904
  var tempState = !options ? this.state : this.state.setQueryParameters(options);
5366
4905
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
4906
+ // eslint-disable-next-line consistent-this
5367
4907
  var self = this;
5368
-
5369
4908
  this._currentNbQueries++;
5370
-
5371
4909
  this.emit('searchOnce', {
5372
4910
  state: tempState
5373
4911
  });
5374
-
5375
4912
  if (cb) {
5376
- this.client
5377
- .search(queries)
5378
- .then(function(content) {
5379
- self._currentNbQueries--;
5380
- if (self._currentNbQueries === 0) {
5381
- self.emit('searchQueueEmpty');
5382
- }
5383
-
5384
- cb(null, new SearchResults_1(tempState, content.results), tempState);
5385
- })
5386
- .catch(function(err) {
5387
- self._currentNbQueries--;
5388
- if (self._currentNbQueries === 0) {
5389
- self.emit('searchQueueEmpty');
5390
- }
5391
-
5392
- cb(err, null, tempState);
5393
- });
5394
-
4913
+ this.client.search(queries).then(function (content) {
4914
+ self._currentNbQueries--;
4915
+ if (self._currentNbQueries === 0) {
4916
+ self.emit('searchQueueEmpty');
4917
+ }
4918
+ cb(null, new SearchResults_1(tempState, content.results), tempState);
4919
+ }).catch(function (err) {
4920
+ self._currentNbQueries--;
4921
+ if (self._currentNbQueries === 0) {
4922
+ self.emit('searchQueueEmpty');
4923
+ }
4924
+ cb(err, null, tempState);
4925
+ });
5395
4926
  return undefined;
5396
4927
  }
5397
-
5398
- return this.client.search(queries).then(function(content) {
4928
+ return this.client.search(queries).then(function (content) {
5399
4929
  self._currentNbQueries--;
5400
4930
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5401
4931
  return {
@@ -5403,14 +4933,14 @@
5403
4933
  state: tempState,
5404
4934
  _originalResponse: content
5405
4935
  };
5406
- }, function(e) {
4936
+ }, function (e) {
5407
4937
  self._currentNbQueries--;
5408
4938
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5409
4939
  throw e;
5410
4940
  });
5411
4941
  };
5412
4942
 
5413
- /**
4943
+ /**
5414
4944
  * Start the search for answers with the parameters set in the state.
5415
4945
  * This method returns a promise.
5416
4946
  * @param {Object} options - the options for answers API call
@@ -5421,7 +4951,8 @@
5421
4951
  * @return {promise} the answer results
5422
4952
  * @deprecated answers is deprecated and will be replaced with new initiatives
5423
4953
  */
5424
- AlgoliaSearchHelper.prototype.findAnswers = function(options) {
4954
+ AlgoliaSearchHelper.prototype.findAnswers = function (options) {
4955
+ // eslint-disable-next-line no-console
5425
4956
  console.warn('[algoliasearch-helper] answers is no longer supported');
5426
4957
  var state = this.state;
5427
4958
  var derivedHelper = this.derivedHelpers[0];
@@ -5429,21 +4960,12 @@
5429
4960
  return Promise.resolve([]);
5430
4961
  }
5431
4962
  var derivedState = derivedHelper.getModifiedState(state);
5432
- var data = merge_1(
5433
- {
5434
- attributesForPrediction: options.attributesForPrediction,
5435
- nbHits: options.nbHits
5436
- },
5437
- {
5438
- params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
5439
- 'attributesToSnippet',
5440
- 'hitsPerPage',
5441
- 'restrictSearchableAttributes',
5442
- 'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
5443
- ])
5444
- }
5445
- );
5446
-
4963
+ var data = merge$1({
4964
+ attributesForPrediction: options.attributesForPrediction,
4965
+ nbHits: options.nbHits
4966
+ }, {
4967
+ params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), ['attributesToSnippet', 'hitsPerPage', 'restrictSearchableAttributes', 'snippetEllipsisText'])
4968
+ });
5447
4969
  var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
5448
4970
  if (typeof this.client.initIndex !== 'function') {
5449
4971
  throw new Error(errorMessage);
@@ -5489,75 +5011,56 @@
5489
5011
  * it in the generated query.
5490
5012
  * @return {promise.<FacetSearchResult>} the results of the search
5491
5013
  */
5492
- AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
5014
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (facet, query, maxFacetHits, userState) {
5493
5015
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
5494
5016
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
5495
- if (
5496
- !clientHasSFFV &&
5497
- !clientHasInitIndex &&
5498
- typeof this.client.search !== 'function'
5499
- ) {
5500
- throw new Error(
5501
- 'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
5502
- );
5017
+ if (!clientHasSFFV && !clientHasInitIndex && typeof this.client.search !== 'function') {
5018
+ 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');
5503
5019
  }
5504
-
5505
5020
  var state = this.state.setQueryParameters(userState || {});
5506
5021
  var isDisjunctive = state.isDisjunctiveFacet(facet);
5507
5022
  var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
5508
-
5509
5023
  this._currentNbQueries++;
5024
+ // eslint-disable-next-line consistent-this
5510
5025
  var self = this;
5511
5026
  var searchForFacetValuesPromise;
5512
5027
  // newer algoliasearch ^3.27.1 - ~4.0.0
5513
5028
  if (clientHasSFFV) {
5514
- searchForFacetValuesPromise = this.client.searchForFacetValues([
5515
- {indexName: state.index, params: algoliaQuery}
5516
- ]);
5029
+ searchForFacetValuesPromise = this.client.searchForFacetValues([{
5030
+ indexName: state.index,
5031
+ params: algoliaQuery
5032
+ }]);
5517
5033
  // algoliasearch < 3.27.1
5518
5034
  } else if (clientHasInitIndex) {
5519
- searchForFacetValuesPromise = this.client
5520
- .initIndex(state.index)
5521
- .searchForFacetValues(algoliaQuery);
5035
+ searchForFacetValuesPromise = this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
5522
5036
  // algoliasearch ~5.0.0
5523
5037
  } else {
5524
5038
  // @MAJOR only use client.search
5525
5039
  delete algoliaQuery.facetName;
5526
- searchForFacetValuesPromise = this.client
5527
- .search([
5528
- {
5529
- type: 'facet',
5530
- facet: facet,
5531
- indexName: state.index,
5532
- params: algoliaQuery
5533
- }
5534
- ])
5535
- .then(function processResponse(response) {
5536
- return response.results[0];
5537
- });
5040
+ searchForFacetValuesPromise = this.client.search([{
5041
+ type: 'facet',
5042
+ facet: facet,
5043
+ indexName: state.index,
5044
+ params: algoliaQuery
5045
+ }]).then(function processResponse(response) {
5046
+ return response.results[0];
5047
+ });
5538
5048
  }
5539
-
5540
5049
  this.emit('searchForFacetValues', {
5541
5050
  state: state,
5542
5051
  facet: facet,
5543
5052
  query: query
5544
5053
  });
5545
-
5546
5054
  return searchForFacetValuesPromise.then(function addIsRefined(content) {
5547
5055
  self._currentNbQueries--;
5548
5056
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5549
-
5550
5057
  content = Array.isArray(content) ? content[0] : content;
5551
-
5552
- content.facetHits.forEach(function(f) {
5058
+ content.facetHits.forEach(function (f) {
5553
5059
  f.escapedValue = escapeFacetValue$3(f.value);
5554
- f.isRefined = isDisjunctive
5555
- ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
5556
- : state.isFacetRefined(facet, f.escapedValue);
5060
+ f.isRefined = isDisjunctive ? state.isDisjunctiveFacetRefined(facet, f.escapedValue) : state.isFacetRefined(facet, f.escapedValue);
5557
5061
  });
5558
-
5559
5062
  return content;
5560
- }, function(e) {
5063
+ }, function (e) {
5561
5064
  self._currentNbQueries--;
5562
5065
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5563
5066
  throw e;
@@ -5569,16 +5072,15 @@
5569
5072
  *
5570
5073
  * This method resets the current page to 0.
5571
5074
  * @param {string} q the user query
5572
- * @return {AlgoliaSearchHelper}
5075
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5573
5076
  * @fires change
5574
5077
  * @chainable
5575
5078
  */
5576
- AlgoliaSearchHelper.prototype.setQuery = function(q) {
5079
+ AlgoliaSearchHelper.prototype.setQuery = function (q) {
5577
5080
  this._change({
5578
5081
  state: this.state.resetPage().setQuery(q),
5579
5082
  isPageReset: true
5580
5083
  });
5581
-
5582
5084
  return this;
5583
5085
  };
5584
5086
 
@@ -5590,7 +5092,7 @@
5590
5092
  *
5591
5093
  * This method resets the current page to 0.
5592
5094
  * @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
5593
- * @return {AlgoliaSearchHelper}
5095
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5594
5096
  * @fires change
5595
5097
  * @chainable
5596
5098
  * @example
@@ -5605,12 +5107,11 @@
5605
5107
  * return type === 'exclude' && attribute === 'category';
5606
5108
  * }).search();
5607
5109
  */
5608
- AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
5110
+ AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
5609
5111
  this._change({
5610
5112
  state: this.state.resetPage().clearRefinements(name),
5611
5113
  isPageReset: true
5612
5114
  });
5613
-
5614
5115
  return this;
5615
5116
  };
5616
5117
 
@@ -5618,16 +5119,15 @@
5618
5119
  * Remove all the tag filters.
5619
5120
  *
5620
5121
  * This method resets the current page to 0.
5621
- * @return {AlgoliaSearchHelper}
5122
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5622
5123
  * @fires change
5623
5124
  * @chainable
5624
5125
  */
5625
- AlgoliaSearchHelper.prototype.clearTags = function() {
5126
+ AlgoliaSearchHelper.prototype.clearTags = function () {
5626
5127
  this._change({
5627
5128
  state: this.state.resetPage().clearTags(),
5628
5129
  isPageReset: true
5629
5130
  });
5630
-
5631
5131
  return this;
5632
5132
  };
5633
5133
 
@@ -5638,23 +5138,23 @@
5638
5138
  * This method resets the current page to 0.
5639
5139
  * @param {string} facet the facet to refine
5640
5140
  * @param {string} value the associated value (will be converted to string)
5641
- * @return {AlgoliaSearchHelper}
5141
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5642
5142
  * @fires change
5643
5143
  * @chainable
5644
5144
  */
5645
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
5145
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (facet, value) {
5646
5146
  this._change({
5647
5147
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
5648
5148
  isPageReset: true
5649
5149
  });
5650
-
5651
5150
  return this;
5652
5151
  };
5653
5152
 
5153
+ // eslint-disable-next-line valid-jsdoc
5654
5154
  /**
5655
5155
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
5656
5156
  */
5657
- AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
5157
+ AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
5658
5158
  return this.addDisjunctiveFacetRefinement.apply(this, arguments);
5659
5159
  };
5660
5160
 
@@ -5666,17 +5166,16 @@
5666
5166
  * This method resets the current page to 0.
5667
5167
  * @param {string} facet the facet name
5668
5168
  * @param {string} path the hierarchical facet path
5669
- * @return {AlgoliaSearchHelper}
5169
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5670
5170
  * @throws Error if the facet is not defined or if the facet is refined
5671
5171
  * @chainable
5672
5172
  * @fires change
5673
5173
  */
5674
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
5174
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (facet, path) {
5675
5175
  this._change({
5676
- state: this.state.resetPage().addHierarchicalFacetRefinement(facet, value),
5176
+ state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
5677
5177
  isPageReset: true
5678
5178
  });
5679
-
5680
5179
  return this;
5681
5180
  };
5682
5181
 
@@ -5688,16 +5187,15 @@
5688
5187
  * @param {string} attribute the attribute on which the numeric filter applies
5689
5188
  * @param {string} operator the operator of the filter
5690
5189
  * @param {number} value the value of the filter
5691
- * @return {AlgoliaSearchHelper}
5190
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5692
5191
  * @fires change
5693
5192
  * @chainable
5694
5193
  */
5695
- AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
5194
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (attribute, operator, value) {
5696
5195
  this._change({
5697
5196
  state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
5698
5197
  isPageReset: true
5699
5198
  });
5700
-
5701
5199
  return this;
5702
5200
  };
5703
5201
 
@@ -5708,27 +5206,26 @@
5708
5206
  * This method resets the current page to 0.
5709
5207
  * @param {string} facet the facet to refine
5710
5208
  * @param {string} value the associated value (will be converted to string)
5711
- * @return {AlgoliaSearchHelper}
5209
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5712
5210
  * @fires change
5713
5211
  * @chainable
5714
5212
  */
5715
- AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
5213
+ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
5716
5214
  this._change({
5717
5215
  state: this.state.resetPage().addFacetRefinement(facet, value),
5718
5216
  isPageReset: true
5719
5217
  });
5720
-
5721
5218
  return this;
5722
5219
  };
5723
5220
 
5221
+ // eslint-disable-next-line valid-jsdoc
5724
5222
  /**
5725
5223
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
5726
5224
  */
5727
- AlgoliaSearchHelper.prototype.addRefine = function() {
5225
+ AlgoliaSearchHelper.prototype.addRefine = function () {
5728
5226
  return this.addFacetRefinement.apply(this, arguments);
5729
5227
  };
5730
5228
 
5731
-
5732
5229
  /**
5733
5230
  * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
5734
5231
  * filter is already set, it doesn't change the filters.
@@ -5736,23 +5233,23 @@
5736
5233
  * This method resets the current page to 0.
5737
5234
  * @param {string} facet the facet to refine
5738
5235
  * @param {string} value the associated value (will be converted to string)
5739
- * @return {AlgoliaSearchHelper}
5236
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5740
5237
  * @fires change
5741
5238
  * @chainable
5742
5239
  */
5743
- AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
5240
+ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
5744
5241
  this._change({
5745
5242
  state: this.state.resetPage().addExcludeRefinement(facet, value),
5746
5243
  isPageReset: true
5747
5244
  });
5748
-
5749
5245
  return this;
5750
5246
  };
5751
5247
 
5248
+ // eslint-disable-next-line valid-jsdoc
5752
5249
  /**
5753
5250
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
5754
5251
  */
5755
- AlgoliaSearchHelper.prototype.addExclude = function() {
5252
+ AlgoliaSearchHelper.prototype.addExclude = function () {
5756
5253
  return this.addFacetExclusion.apply(this, arguments);
5757
5254
  };
5758
5255
 
@@ -5762,16 +5259,15 @@
5762
5259
  *
5763
5260
  * This method resets the current page to 0.
5764
5261
  * @param {string} tag the tag to add to the filter
5765
- * @return {AlgoliaSearchHelper}
5262
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5766
5263
  * @fires change
5767
5264
  * @chainable
5768
5265
  */
5769
- AlgoliaSearchHelper.prototype.addTag = function(tag) {
5266
+ AlgoliaSearchHelper.prototype.addTag = function (tag) {
5770
5267
  this._change({
5771
5268
  state: this.state.resetPage().addTagRefinement(tag),
5772
5269
  isPageReset: true
5773
5270
  });
5774
-
5775
5271
  return this;
5776
5272
  };
5777
5273
 
@@ -5789,16 +5285,15 @@
5789
5285
  * @param {string} attribute the attribute on which the numeric filter applies
5790
5286
  * @param {string} [operator] the operator of the filter
5791
5287
  * @param {number} [value] the value of the filter
5792
- * @return {AlgoliaSearchHelper}
5288
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5793
5289
  * @fires change
5794
5290
  * @chainable
5795
5291
  */
5796
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
5292
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (attribute, operator, value) {
5797
5293
  this._change({
5798
5294
  state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
5799
5295
  isPageReset: true
5800
5296
  });
5801
-
5802
5297
  return this;
5803
5298
  };
5804
5299
 
@@ -5812,40 +5307,39 @@
5812
5307
  * This method resets the current page to 0.
5813
5308
  * @param {string} facet the facet to refine
5814
5309
  * @param {string} [value] the associated value
5815
- * @return {AlgoliaSearchHelper}
5310
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5816
5311
  * @fires change
5817
5312
  * @chainable
5818
5313
  */
5819
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
5314
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (facet, value) {
5820
5315
  this._change({
5821
5316
  state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
5822
5317
  isPageReset: true
5823
5318
  });
5824
-
5825
5319
  return this;
5826
5320
  };
5827
5321
 
5322
+ // eslint-disable-next-line valid-jsdoc
5828
5323
  /**
5829
5324
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
5830
5325
  */
5831
- AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
5326
+ AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
5832
5327
  return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
5833
5328
  };
5834
5329
 
5835
5330
  /**
5836
5331
  * Removes the refinement set on a hierarchical facet.
5837
5332
  * @param {string} facet the facet name
5838
- * @return {AlgoliaSearchHelper}
5333
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5839
5334
  * @throws Error if the facet is not defined or if the facet is not refined
5840
5335
  * @fires change
5841
5336
  * @chainable
5842
5337
  */
5843
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
5338
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (facet) {
5844
5339
  this._change({
5845
5340
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
5846
5341
  isPageReset: true
5847
5342
  });
5848
-
5849
5343
  return this;
5850
5344
  };
5851
5345
 
@@ -5859,23 +5353,23 @@
5859
5353
  * This method resets the current page to 0.
5860
5354
  * @param {string} facet the facet to refine
5861
5355
  * @param {string} [value] the associated value
5862
- * @return {AlgoliaSearchHelper}
5356
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5863
5357
  * @fires change
5864
5358
  * @chainable
5865
5359
  */
5866
- AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
5360
+ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
5867
5361
  this._change({
5868
5362
  state: this.state.resetPage().removeFacetRefinement(facet, value),
5869
5363
  isPageReset: true
5870
5364
  });
5871
-
5872
5365
  return this;
5873
5366
  };
5874
5367
 
5368
+ // eslint-disable-next-line valid-jsdoc
5875
5369
  /**
5876
5370
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
5877
5371
  */
5878
- AlgoliaSearchHelper.prototype.removeRefine = function() {
5372
+ AlgoliaSearchHelper.prototype.removeRefine = function () {
5879
5373
  return this.removeFacetRefinement.apply(this, arguments);
5880
5374
  };
5881
5375
 
@@ -5889,23 +5383,23 @@
5889
5383
  * This method resets the current page to 0.
5890
5384
  * @param {string} facet the facet to refine
5891
5385
  * @param {string} [value] the associated value
5892
- * @return {AlgoliaSearchHelper}
5386
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5893
5387
  * @fires change
5894
5388
  * @chainable
5895
5389
  */
5896
- AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
5390
+ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
5897
5391
  this._change({
5898
5392
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
5899
5393
  isPageReset: true
5900
5394
  });
5901
-
5902
5395
  return this;
5903
5396
  };
5904
5397
 
5398
+ // eslint-disable-next-line valid-jsdoc
5905
5399
  /**
5906
5400
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
5907
5401
  */
5908
- AlgoliaSearchHelper.prototype.removeExclude = function() {
5402
+ AlgoliaSearchHelper.prototype.removeExclude = function () {
5909
5403
  return this.removeFacetExclusion.apply(this, arguments);
5910
5404
  };
5911
5405
 
@@ -5915,16 +5409,15 @@
5915
5409
  *
5916
5410
  * This method resets the current page to 0.
5917
5411
  * @param {string} tag tag to remove from the filter
5918
- * @return {AlgoliaSearchHelper}
5412
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5919
5413
  * @fires change
5920
5414
  * @chainable
5921
5415
  */
5922
- AlgoliaSearchHelper.prototype.removeTag = function(tag) {
5416
+ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
5923
5417
  this._change({
5924
5418
  state: this.state.resetPage().removeTagRefinement(tag),
5925
5419
  isPageReset: true
5926
5420
  });
5927
-
5928
5421
  return this;
5929
5422
  };
5930
5423
 
@@ -5935,23 +5428,23 @@
5935
5428
  * This method resets the current page to 0.
5936
5429
  * @param {string} facet the facet to refine
5937
5430
  * @param {string} value the associated value
5938
- * @return {AlgoliaSearchHelper}
5431
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5939
5432
  * @fires change
5940
5433
  * @chainable
5941
5434
  */
5942
- AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
5435
+ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
5943
5436
  this._change({
5944
5437
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
5945
5438
  isPageReset: true
5946
5439
  });
5947
-
5948
5440
  return this;
5949
5441
  };
5950
5442
 
5443
+ // eslint-disable-next-line valid-jsdoc
5951
5444
  /**
5952
5445
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
5953
5446
  */
5954
- AlgoliaSearchHelper.prototype.toggleExclude = function() {
5447
+ AlgoliaSearchHelper.prototype.toggleExclude = function () {
5955
5448
  return this.toggleFacetExclusion.apply(this, arguments);
5956
5449
  };
5957
5450
 
@@ -5964,13 +5457,13 @@
5964
5457
  * This method resets the current page to 0.
5965
5458
  * @param {string} facet the facet to refine
5966
5459
  * @param {string} value the associated value
5967
- * @return {AlgoliaSearchHelper}
5460
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5968
5461
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
5969
5462
  * @fires change
5970
5463
  * @chainable
5971
5464
  * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
5972
5465
  */
5973
- AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
5466
+ AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
5974
5467
  return this.toggleFacetRefinement(facet, value);
5975
5468
  };
5976
5469
 
@@ -5983,24 +5476,24 @@
5983
5476
  * This method resets the current page to 0.
5984
5477
  * @param {string} facet the facet to refine
5985
5478
  * @param {string} value the associated value
5986
- * @return {AlgoliaSearchHelper}
5479
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5987
5480
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
5988
5481
  * @fires change
5989
5482
  * @chainable
5990
5483
  */
5991
- AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
5484
+ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
5992
5485
  this._change({
5993
5486
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
5994
5487
  isPageReset: true
5995
5488
  });
5996
-
5997
5489
  return this;
5998
5490
  };
5999
5491
 
5492
+ // eslint-disable-next-line valid-jsdoc
6000
5493
  /**
6001
5494
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
6002
5495
  */
6003
- AlgoliaSearchHelper.prototype.toggleRefine = function() {
5496
+ AlgoliaSearchHelper.prototype.toggleRefine = function () {
6004
5497
  return this.toggleFacetRefinement.apply(this, arguments);
6005
5498
  };
6006
5499
 
@@ -6010,29 +5503,28 @@
6010
5503
  *
6011
5504
  * This method resets the current page to 0.
6012
5505
  * @param {string} tag tag to remove or add
6013
- * @return {AlgoliaSearchHelper}
5506
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6014
5507
  * @fires change
6015
5508
  * @chainable
6016
5509
  */
6017
- AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
5510
+ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
6018
5511
  this._change({
6019
5512
  state: this.state.resetPage().toggleTagRefinement(tag),
6020
5513
  isPageReset: true
6021
5514
  });
6022
-
6023
5515
  return this;
6024
5516
  };
6025
5517
 
6026
5518
  /**
6027
5519
  * Increments the page number by one.
6028
- * @return {AlgoliaSearchHelper}
5520
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6029
5521
  * @fires change
6030
5522
  * @chainable
6031
5523
  * @example
6032
5524
  * helper.setPage(0).nextPage().getPage();
6033
5525
  * // returns 1
6034
5526
  */
6035
- AlgoliaSearchHelper.prototype.nextPage = function() {
5527
+ AlgoliaSearchHelper.prototype.nextPage = function () {
6036
5528
  var page = this.state.page || 0;
6037
5529
  return this.setPage(page + 1);
6038
5530
  };
@@ -6040,28 +5532,30 @@
6040
5532
  /**
6041
5533
  * Decrements the page number by one.
6042
5534
  * @fires change
6043
- * @return {AlgoliaSearchHelper}
5535
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6044
5536
  * @chainable
6045
5537
  * @example
6046
5538
  * helper.setPage(1).previousPage().getPage();
6047
5539
  * // returns 0
6048
5540
  */
6049
- AlgoliaSearchHelper.prototype.previousPage = function() {
5541
+ AlgoliaSearchHelper.prototype.previousPage = function () {
6050
5542
  var page = this.state.page || 0;
6051
5543
  return this.setPage(page - 1);
6052
5544
  };
6053
5545
 
6054
5546
  /**
6055
5547
  * @private
5548
+ * @param {number} page The page number
5549
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5550
+ * @chainable
5551
+ * @fires change
6056
5552
  */
6057
5553
  function setCurrentPage(page) {
6058
5554
  if (page < 0) throw new Error('Page requested below 0.');
6059
-
6060
5555
  this._change({
6061
5556
  state: this.state.setPage(page),
6062
5557
  isPageReset: false
6063
5558
  });
6064
-
6065
5559
  return this;
6066
5560
  }
6067
5561
 
@@ -6069,7 +5563,7 @@
6069
5563
  * Change the current page
6070
5564
  * @deprecated
6071
5565
  * @param {number} page The page number
6072
- * @return {AlgoliaSearchHelper}
5566
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6073
5567
  * @fires change
6074
5568
  * @chainable
6075
5569
  */
@@ -6079,7 +5573,7 @@
6079
5573
  * Updates the current page.
6080
5574
  * @function
6081
5575
  * @param {number} page The page number
6082
- * @return {AlgoliaSearchHelper}
5576
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6083
5577
  * @fires change
6084
5578
  * @chainable
6085
5579
  */
@@ -6090,16 +5584,15 @@
6090
5584
  *
6091
5585
  * This method resets the current page to 0.
6092
5586
  * @param {string} name the index name
6093
- * @return {AlgoliaSearchHelper}
5587
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6094
5588
  * @fires change
6095
5589
  * @chainable
6096
5590
  */
6097
- AlgoliaSearchHelper.prototype.setIndex = function(name) {
5591
+ AlgoliaSearchHelper.prototype.setIndex = function (name) {
6098
5592
  this._change({
6099
5593
  state: this.state.resetPage().setIndex(name),
6100
5594
  isPageReset: true
6101
5595
  });
6102
-
6103
5596
  return this;
6104
5597
  };
6105
5598
 
@@ -6114,34 +5607,32 @@
6114
5607
  * This method resets the current page to 0.
6115
5608
  * @param {string} parameter name of the parameter to update
6116
5609
  * @param {any} value new value of the parameter
6117
- * @return {AlgoliaSearchHelper}
5610
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6118
5611
  * @fires change
6119
5612
  * @chainable
6120
5613
  * @example
6121
5614
  * helper.setQueryParameter('hitsPerPage', 20).search();
6122
5615
  */
6123
- AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
5616
+ AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
6124
5617
  this._change({
6125
5618
  state: this.state.resetPage().setQueryParameter(parameter, value),
6126
5619
  isPageReset: true
6127
5620
  });
6128
-
6129
5621
  return this;
6130
5622
  };
6131
5623
 
6132
5624
  /**
6133
5625
  * Set the whole state (warning: will erase previous state)
6134
5626
  * @param {SearchParameters} newState the whole new state
6135
- * @return {AlgoliaSearchHelper}
5627
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6136
5628
  * @fires change
6137
5629
  * @chainable
6138
5630
  */
6139
- AlgoliaSearchHelper.prototype.setState = function(newState) {
5631
+ AlgoliaSearchHelper.prototype.setState = function (newState) {
6140
5632
  this._change({
6141
5633
  state: SearchParameters_1.make(newState),
6142
5634
  isPageReset: false
6143
5635
  });
6144
-
6145
5636
  return this;
6146
5637
  };
6147
5638
 
@@ -6150,7 +5641,7 @@
6150
5641
  * Do not use this method unless you know what you are doing. (see the example
6151
5642
  * for a legit use case)
6152
5643
  * @param {SearchParameters} newState the whole new state
6153
- * @return {AlgoliaSearchHelper}
5644
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6154
5645
  * @example
6155
5646
  * helper.on('change', function(state){
6156
5647
  * // In this function you might want to find a way to store the state in the url/history
@@ -6162,7 +5653,7 @@
6162
5653
  * }
6163
5654
  * @chainable
6164
5655
  */
6165
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
5656
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function (newState) {
6166
5657
  this.state = new SearchParameters_1(newState);
6167
5658
  return this;
6168
5659
  };
@@ -6190,7 +5681,7 @@
6190
5681
  * helper.hasRefinements('categories'); // true
6191
5682
  *
6192
5683
  */
6193
- AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
5684
+ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
6194
5685
  if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
6195
5686
  return true;
6196
5687
  } else if (this.state.isConjunctiveFacet(attribute)) {
@@ -6215,7 +5706,7 @@
6215
5706
  *
6216
5707
  * @param {string} facet name of the attribute for used for faceting
6217
5708
  * @param {string} [value] optional value. If passed will test that this value
6218
- * is filtering the given facet.
5709
+ * is filtering the given facet.
6219
5710
  * @return {boolean} true if refined
6220
5711
  * @example
6221
5712
  * helper.isExcludeRefined('color'); // false
@@ -6228,45 +5719,45 @@
6228
5719
  * helper.isExcludeRefined('color', 'blue') // false
6229
5720
  * helper.isExcludeRefined('color', 'red') // true
6230
5721
  */
6231
- AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
5722
+ AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
6232
5723
  return this.state.isExcludeRefined(facet, value);
6233
5724
  };
6234
5725
 
5726
+ // eslint-disable-next-line valid-jsdoc
6235
5727
  /**
6236
5728
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
6237
5729
  */
6238
- AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
5730
+ AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
6239
5731
  return this.state.isDisjunctiveFacetRefined(facet, value);
6240
5732
  };
6241
5733
 
6242
5734
  /**
6243
5735
  * Check if the string is a currently filtering tag.
6244
5736
  * @param {string} tag tag to check
6245
- * @return {boolean}
5737
+ * @return {boolean} true if the tag is currently refined
6246
5738
  */
6247
- AlgoliaSearchHelper.prototype.hasTag = function(tag) {
5739
+ AlgoliaSearchHelper.prototype.hasTag = function (tag) {
6248
5740
  return this.state.isTagRefined(tag);
6249
5741
  };
6250
5742
 
5743
+ // eslint-disable-next-line valid-jsdoc
6251
5744
  /**
6252
5745
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
6253
5746
  */
6254
- AlgoliaSearchHelper.prototype.isTagRefined = function() {
5747
+ AlgoliaSearchHelper.prototype.isTagRefined = function () {
6255
5748
  return this.hasTagRefinements.apply(this, arguments);
6256
5749
  };
6257
5750
 
6258
-
6259
5751
  /**
6260
5752
  * Get the name of the currently used index.
6261
- * @return {string}
5753
+ * @return {string} name of the index
6262
5754
  * @example
6263
5755
  * helper.setIndex('highestPrice_products').getIndex();
6264
5756
  * // returns 'highestPrice_products'
6265
5757
  */
6266
- AlgoliaSearchHelper.prototype.getIndex = function() {
5758
+ AlgoliaSearchHelper.prototype.getIndex = function () {
6267
5759
  return this.state.index;
6268
5760
  };
6269
-
6270
5761
  function getCurrentPage() {
6271
5762
  return this.state.page;
6272
5763
  }
@@ -6289,7 +5780,7 @@
6289
5780
  *
6290
5781
  * @return {string[]} The list of tags currently set.
6291
5782
  */
6292
- AlgoliaSearchHelper.prototype.getTags = function() {
5783
+ AlgoliaSearchHelper.prototype.getTags = function () {
6293
5784
  return this.state.tagRefinements;
6294
5785
  };
6295
5786
 
@@ -6337,50 +5828,41 @@
6337
5828
  * // }
6338
5829
  * // ]
6339
5830
  */
6340
- AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
5831
+ AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
6341
5832
  var refinements = [];
6342
-
6343
5833
  if (this.state.isConjunctiveFacet(facetName)) {
6344
5834
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
6345
-
6346
- conjRefinements.forEach(function(r) {
5835
+ conjRefinements.forEach(function (r) {
6347
5836
  refinements.push({
6348
5837
  value: r,
6349
5838
  type: 'conjunctive'
6350
5839
  });
6351
5840
  });
6352
-
6353
5841
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
6354
-
6355
- excludeRefinements.forEach(function(r) {
5842
+ excludeRefinements.forEach(function (r) {
6356
5843
  refinements.push({
6357
5844
  value: r,
6358
5845
  type: 'exclude'
6359
5846
  });
6360
5847
  });
6361
5848
  } else if (this.state.isDisjunctiveFacet(facetName)) {
6362
- var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
6363
-
6364
- disjRefinements.forEach(function(r) {
5849
+ var disjunctiveRefinements = this.state.getDisjunctiveRefinements(facetName);
5850
+ disjunctiveRefinements.forEach(function (r) {
6365
5851
  refinements.push({
6366
5852
  value: r,
6367
5853
  type: 'disjunctive'
6368
5854
  });
6369
5855
  });
6370
5856
  }
6371
-
6372
5857
  var numericRefinements = this.state.getNumericRefinements(facetName);
6373
-
6374
- Object.keys(numericRefinements).forEach(function(operator) {
5858
+ Object.keys(numericRefinements).forEach(function (operator) {
6375
5859
  var value = numericRefinements[operator];
6376
-
6377
5860
  refinements.push({
6378
5861
  value: value,
6379
5862
  operator: operator,
6380
5863
  type: 'numeric'
6381
5864
  });
6382
5865
  });
6383
-
6384
5866
  return refinements;
6385
5867
  };
6386
5868
 
@@ -6390,7 +5872,7 @@
6390
5872
  * @param {string} operator operator applied on the refined values
6391
5873
  * @return {Array.<number|number[]>} refined values
6392
5874
  */
6393
- AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
5875
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (attribute, operator) {
6394
5876
  return this.state.getNumericRefinement(attribute, operator);
6395
5877
  };
6396
5878
 
@@ -6399,7 +5881,7 @@
6399
5881
  * @param {string} facetName Hierarchical facet name
6400
5882
  * @return {array.<string>} the path as an array of string
6401
5883
  */
6402
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
5884
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (facetName) {
6403
5885
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
6404
5886
  };
6405
5887
 
@@ -6408,72 +5890,60 @@
6408
5890
  /**
6409
5891
  * Perform the underlying queries
6410
5892
  * @private
6411
- * @return {undefined}
5893
+ * @param {object} options options for the query
5894
+ * @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
5895
+ * @return {undefined} does not return anything
6412
5896
  * @fires search
6413
5897
  * @fires result
6414
5898
  * @fires error
6415
5899
  */
6416
- AlgoliaSearchHelper.prototype._search = function(options) {
5900
+ AlgoliaSearchHelper.prototype._search = function (options) {
6417
5901
  var state = this.state;
6418
5902
  var states = [];
6419
5903
  var mainQueries = [];
6420
-
6421
5904
  if (!options.onlyWithDerivedHelpers) {
6422
5905
  mainQueries = requestBuilder_1._getQueries(state.index, state);
6423
-
6424
5906
  states.push({
6425
5907
  state: state,
6426
5908
  queriesCount: mainQueries.length,
6427
5909
  helper: this
6428
5910
  });
6429
-
6430
5911
  this.emit('search', {
6431
5912
  state: state,
6432
5913
  results: this.lastResults
6433
5914
  });
6434
5915
  }
6435
-
6436
- var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
5916
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
6437
5917
  var derivedState = derivedHelper.getModifiedState(state);
6438
- var derivedStateQueries = derivedState.index
6439
- ? requestBuilder_1._getQueries(derivedState.index, derivedState)
6440
- : [];
6441
-
5918
+ var derivedStateQueries = derivedState.index ? requestBuilder_1._getQueries(derivedState.index, derivedState) : [];
6442
5919
  states.push({
6443
5920
  state: derivedState,
6444
5921
  queriesCount: derivedStateQueries.length,
6445
5922
  helper: derivedHelper
6446
5923
  });
6447
-
6448
5924
  derivedHelper.emit('search', {
6449
5925
  state: derivedState,
6450
5926
  results: derivedHelper.lastResults
6451
5927
  });
6452
-
6453
5928
  return derivedStateQueries;
6454
5929
  });
6455
-
6456
5930
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
6457
-
6458
5931
  var queryId = this._queryId++;
6459
5932
  this._currentNbQueries++;
6460
-
6461
5933
  if (!queries.length) {
6462
- return Promise.resolve({results: []}).then(
6463
- this._dispatchAlgoliaResponse.bind(this, states, queryId)
6464
- );
5934
+ return Promise.resolve({
5935
+ results: []
5936
+ }).then(this._dispatchAlgoliaResponse.bind(this, states, queryId));
6465
5937
  }
6466
-
6467
5938
  try {
6468
- this.client.search(queries)
6469
- .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
6470
- .catch(this._dispatchAlgoliaError.bind(this, queryId));
5939
+ this.client.search(queries).then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
6471
5940
  } catch (error) {
6472
5941
  // If we reach this part, we're in an internal error state
6473
5942
  this.emit('error', {
6474
5943
  error: error
6475
5944
  });
6476
5945
  }
5946
+ return undefined;
6477
5947
  };
6478
5948
 
6479
5949
  /**
@@ -6481,33 +5951,27 @@
6481
5951
  * usable object that merge the results of all the batch requests. It will dispatch
6482
5952
  * over the different helper + derived helpers (when there are some).
6483
5953
  * @private
6484
- * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
6485
- * state state used for to generate the request
5954
+ * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
6486
5955
  * @param {number} queryId id of the current request
6487
5956
  * @param {object} content content of the response
6488
5957
  * @return {undefined}
6489
5958
  */
6490
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
6491
- // FIXME remove the number of outdated queries discarded instead of just one
5959
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (states, queryId, content) {
5960
+ // @TODO remove the number of outdated queries discarded instead of just one
6492
5961
 
6493
5962
  if (queryId < this._lastQueryIdReceived) {
6494
5963
  // Outdated answer
6495
5964
  return;
6496
5965
  }
6497
-
6498
- this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
5966
+ this._currentNbQueries -= queryId - this._lastQueryIdReceived;
6499
5967
  this._lastQueryIdReceived = queryId;
6500
-
6501
5968
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6502
-
6503
5969
  var results = content.results.slice();
6504
-
6505
- states.forEach(function(s) {
5970
+ states.forEach(function (s) {
6506
5971
  var state = s.state;
6507
5972
  var queriesCount = s.queriesCount;
6508
5973
  var helper = s.helper;
6509
5974
  var specificResults = results.splice(0, queriesCount);
6510
-
6511
5975
  if (!state.index) {
6512
5976
  helper.emit('result', {
6513
5977
  results: null,
@@ -6515,57 +5979,43 @@
6515
5979
  });
6516
5980
  return;
6517
5981
  }
6518
-
6519
- var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
6520
-
5982
+ helper.lastResults = new SearchResults_1(state, specificResults);
6521
5983
  helper.emit('result', {
6522
- results: formattedResponse,
5984
+ results: helper.lastResults,
6523
5985
  state: state
6524
5986
  });
6525
5987
  });
6526
5988
  };
6527
-
6528
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
5989
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (queryId, error) {
6529
5990
  if (queryId < this._lastQueryIdReceived) {
6530
5991
  // Outdated answer
6531
5992
  return;
6532
5993
  }
6533
-
6534
5994
  this._currentNbQueries -= queryId - this._lastQueryIdReceived;
6535
5995
  this._lastQueryIdReceived = queryId;
6536
-
6537
5996
  this.emit('error', {
6538
5997
  error: error
6539
5998
  });
6540
-
6541
5999
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6542
6000
  };
6543
-
6544
- AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
6545
- return query ||
6546
- facetFilters.length !== 0 ||
6547
- numericFilters.length !== 0 ||
6548
- tagFilters.length !== 0;
6001
+ AlgoliaSearchHelper.prototype.containsRefinement = function (query, facetFilters, numericFilters, tagFilters) {
6002
+ return query || facetFilters.length !== 0 || numericFilters.length !== 0 || tagFilters.length !== 0;
6549
6003
  };
6550
6004
 
6551
6005
  /**
6552
6006
  * Test if there are some disjunctive refinements on the facet
6553
6007
  * @private
6554
6008
  * @param {string} facet the attribute to test
6555
- * @return {boolean}
6009
+ * @return {boolean} true if there are refinements on this attribute
6556
6010
  */
6557
- AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
6558
- return this.state.disjunctiveRefinements[facet] &&
6559
- this.state.disjunctiveRefinements[facet].length > 0;
6011
+ AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
6012
+ return this.state.disjunctiveRefinements[facet] && this.state.disjunctiveRefinements[facet].length > 0;
6560
6013
  };
6561
-
6562
- AlgoliaSearchHelper.prototype._change = function(event) {
6014
+ AlgoliaSearchHelper.prototype._change = function (event) {
6563
6015
  var state = event.state;
6564
6016
  var isPageReset = event.isPageReset;
6565
-
6566
6017
  if (state !== this.state) {
6567
6018
  this.state = state;
6568
-
6569
6019
  this.emit('change', {
6570
6020
  state: this.state,
6571
6021
  results: this.lastResults,
@@ -6576,10 +6026,10 @@
6576
6026
 
6577
6027
  /**
6578
6028
  * Clears the cache of the underlying Algolia client.
6579
- * @return {AlgoliaSearchHelper}
6029
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6580
6030
  */
6581
- AlgoliaSearchHelper.prototype.clearCache = function() {
6582
- this.client.clearCache && this.client.clearCache();
6031
+ AlgoliaSearchHelper.prototype.clearCache = function () {
6032
+ if (this.client.clearCache) this.client.clearCache();
6583
6033
  return this;
6584
6034
  };
6585
6035
 
@@ -6587,24 +6037,22 @@
6587
6037
  * Updates the internal client instance. If the reference of the clients
6588
6038
  * are equal then no update is actually done.
6589
6039
  * @param {AlgoliaSearch} newClient an AlgoliaSearch client
6590
- * @return {AlgoliaSearchHelper}
6040
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6591
6041
  */
6592
- AlgoliaSearchHelper.prototype.setClient = function(newClient) {
6042
+ AlgoliaSearchHelper.prototype.setClient = function (newClient) {
6593
6043
  if (this.client === newClient) return this;
6594
-
6595
6044
  if (typeof newClient.addAlgoliaAgent === 'function') {
6596
6045
  newClient.addAlgoliaAgent('JS Helper (' + version$1 + ')');
6597
6046
  }
6598
6047
  this.client = newClient;
6599
-
6600
6048
  return this;
6601
6049
  };
6602
6050
 
6603
6051
  /**
6604
6052
  * Gets the instance of the currently used client.
6605
- * @return {AlgoliaSearch}
6053
+ * @return {AlgoliaSearch} the currently used client
6606
6054
  */
6607
- AlgoliaSearchHelper.prototype.getClient = function() {
6055
+ AlgoliaSearchHelper.prototype.getClient = function () {
6608
6056
  return this.client;
6609
6057
  };
6610
6058
 
@@ -6625,9 +6073,9 @@
6625
6073
  * and the SearchParameters that is returned by the call of the
6626
6074
  * parameter function.
6627
6075
  * @param {function} fn SearchParameters -> SearchParameters
6628
- * @return {DerivedHelper}
6076
+ * @return {DerivedHelper} a new DerivedHelper
6629
6077
  */
6630
- AlgoliaSearchHelper.prototype.derive = function(fn) {
6078
+ AlgoliaSearchHelper.prototype.derive = function (fn) {
6631
6079
  var derivedHelper = new DerivedHelper_1(this, fn);
6632
6080
  this.derivedHelpers.push(derivedHelper);
6633
6081
  return derivedHelper;
@@ -6637,10 +6085,11 @@
6637
6085
  * This method detaches a derived Helper from the main one. Prefer using the one from the
6638
6086
  * derived helper itself, to remove the event listeners too.
6639
6087
  * @private
6640
- * @return {undefined}
6088
+ * @param {DerivedHelper} derivedHelper the derived helper to detach
6089
+ * @return {undefined} nothing is returned
6641
6090
  * @throws Error
6642
6091
  */
6643
- AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
6092
+ AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
6644
6093
  var pos = this.derivedHelpers.indexOf(derivedHelper);
6645
6094
  if (pos === -1) throw new Error('Derived helper already detached');
6646
6095
  this.derivedHelpers.splice(pos, 1);
@@ -6650,7 +6099,7 @@
6650
6099
  * This method returns true if there is currently at least one on-going search.
6651
6100
  * @return {boolean} true if there is a search pending
6652
6101
  */
6653
- AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
6102
+ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
6654
6103
  return this._currentNbQueries > 0;
6655
6104
  };
6656
6105
 
@@ -6701,7 +6150,7 @@
6701
6150
  * @param {AlgoliaSearch} client an AlgoliaSearch client
6702
6151
  * @param {string} index the name of the index to query
6703
6152
  * @param {SearchParameters|object} opts an object defining the initial config of the search. It doesn't have to be a {SearchParameters}, just an object containing the properties you need from it.
6704
- * @return {AlgoliaSearchHelper}
6153
+ * @return {AlgoliaSearchHelper} The helper instance
6705
6154
  */
6706
6155
  function algoliasearchHelper(client, index, opts) {
6707
6156
  return new algoliasearch_helper(client, index, opts);
@@ -6734,7 +6183,6 @@
6734
6183
  * @type {SearchResults}
6735
6184
  */
6736
6185
  algoliasearchHelper.SearchResults = SearchResults_1;
6737
-
6738
6186
  var algoliasearchHelper_1 = algoliasearchHelper;
6739
6187
 
6740
6188
  function createOptionalFilter(_ref) {