react-instantsearch-core 6.40.1 → 6.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/version.js +1 -1
- package/dist/es/core/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +1157 -718
- package/dist/umd/ReactInstantSearchCore.js.map +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
- package/package.json +3 -3
|
@@ -873,7 +873,7 @@
|
|
|
873
873
|
});
|
|
874
874
|
}
|
|
875
875
|
|
|
876
|
-
var version = '6.40.
|
|
876
|
+
var version = '6.40.3';
|
|
877
877
|
|
|
878
878
|
function translatable(defaultTranslations) {
|
|
879
879
|
return function (Composed) {
|
|
@@ -1234,12 +1234,14 @@
|
|
|
1234
1234
|
return target;
|
|
1235
1235
|
}
|
|
1236
1236
|
|
|
1237
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
1237
1238
|
for (var key in source) {
|
|
1238
1239
|
if (
|
|
1239
1240
|
!Object.prototype.hasOwnProperty.call(source, key) ||
|
|
1240
1241
|
key === '__proto__' ||
|
|
1241
1242
|
key === 'constructor'
|
|
1242
1243
|
) {
|
|
1244
|
+
// eslint-disable-next-line no-continue
|
|
1243
1245
|
continue;
|
|
1244
1246
|
}
|
|
1245
1247
|
|
|
@@ -1247,6 +1249,7 @@
|
|
|
1247
1249
|
var targetVal = target[key];
|
|
1248
1250
|
|
|
1249
1251
|
if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
|
|
1252
|
+
// eslint-disable-next-line no-continue
|
|
1250
1253
|
continue;
|
|
1251
1254
|
}
|
|
1252
1255
|
|
|
@@ -1273,11 +1276,10 @@
|
|
|
1273
1276
|
* - treats sparse arrays as sparse
|
|
1274
1277
|
* - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
|
|
1275
1278
|
*
|
|
1276
|
-
* @param {Object}
|
|
1279
|
+
* @param {Object} target The destination object.
|
|
1277
1280
|
* @param {...Object} [sources] The source objects.
|
|
1278
1281
|
* @returns {Object} Returns `object`.
|
|
1279
1282
|
*/
|
|
1280
|
-
|
|
1281
1283
|
function merge(target) {
|
|
1282
1284
|
if (!isObjectOrArrayOrFunction(target)) {
|
|
1283
1285
|
target = {};
|
|
@@ -1300,8 +1302,8 @@
|
|
|
1300
1302
|
var defaultsPure = function defaultsPure() {
|
|
1301
1303
|
var sources = Array.prototype.slice.call(arguments);
|
|
1302
1304
|
|
|
1303
|
-
return sources.reduceRight(function(acc, source) {
|
|
1304
|
-
Object.keys(Object(source)).forEach(function(key) {
|
|
1305
|
+
return sources.reduceRight(function (acc, source) {
|
|
1306
|
+
Object.keys(Object(source)).forEach(function (key) {
|
|
1305
1307
|
if (source[key] === undefined) {
|
|
1306
1308
|
return;
|
|
1307
1309
|
}
|
|
@@ -1316,7 +1318,7 @@
|
|
|
1316
1318
|
};
|
|
1317
1319
|
|
|
1318
1320
|
function intersection(arr1, arr2) {
|
|
1319
|
-
return arr1.filter(function(value, index) {
|
|
1321
|
+
return arr1.filter(function (value, index) {
|
|
1320
1322
|
return (
|
|
1321
1323
|
arr2.indexOf(value) > -1 &&
|
|
1322
1324
|
arr1.indexOf(value) === index /* skips duplicates */
|
|
@@ -1337,6 +1339,8 @@
|
|
|
1337
1339
|
return array[i];
|
|
1338
1340
|
}
|
|
1339
1341
|
}
|
|
1342
|
+
|
|
1343
|
+
return undefined;
|
|
1340
1344
|
};
|
|
1341
1345
|
|
|
1342
1346
|
function valToNumber(v) {
|
|
@@ -1348,7 +1352,9 @@
|
|
|
1348
1352
|
return v.map(valToNumber);
|
|
1349
1353
|
}
|
|
1350
1354
|
|
|
1351
|
-
throw new Error(
|
|
1355
|
+
throw new Error(
|
|
1356
|
+
'The value should be a number, a parsable string or an array of those.'
|
|
1357
|
+
);
|
|
1352
1358
|
}
|
|
1353
1359
|
|
|
1354
1360
|
var valToNumber_1 = valToNumber;
|
|
@@ -1362,6 +1368,7 @@
|
|
|
1362
1368
|
var i;
|
|
1363
1369
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
1364
1370
|
key = sourceKeys[i];
|
|
1371
|
+
// eslint-disable-next-line no-continue
|
|
1365
1372
|
if (excluded.indexOf(key) >= 0) continue;
|
|
1366
1373
|
target[key] = source[key];
|
|
1367
1374
|
}
|
|
@@ -1414,9 +1421,9 @@
|
|
|
1414
1421
|
|
|
1415
1422
|
var valueAsString = '' + value;
|
|
1416
1423
|
|
|
1417
|
-
var facetRefinement = !refinementList[attribute]
|
|
1418
|
-
[valueAsString]
|
|
1419
|
-
refinementList[attribute].concat(valueAsString);
|
|
1424
|
+
var facetRefinement = !refinementList[attribute]
|
|
1425
|
+
? [valueAsString]
|
|
1426
|
+
: refinementList[attribute].concat(valueAsString);
|
|
1420
1427
|
|
|
1421
1428
|
var mod = {};
|
|
1422
1429
|
|
|
@@ -1433,18 +1440,22 @@
|
|
|
1433
1440
|
* @param {string} [value] the value of the refinement
|
|
1434
1441
|
* @return {RefinementList} a new and updated refinement lst
|
|
1435
1442
|
*/
|
|
1436
|
-
removeRefinement: function removeRefinement(
|
|
1443
|
+
removeRefinement: function removeRefinement(
|
|
1444
|
+
refinementList,
|
|
1445
|
+
attribute,
|
|
1446
|
+
value
|
|
1447
|
+
) {
|
|
1437
1448
|
if (value === undefined) {
|
|
1438
1449
|
// we use the "filter" form of clearRefinement, since it leaves empty values as-is
|
|
1439
1450
|
// the form with a string will remove the attribute completely
|
|
1440
|
-
return lib.clearRefinement(refinementList, function(v, f) {
|
|
1451
|
+
return lib.clearRefinement(refinementList, function (v, f) {
|
|
1441
1452
|
return attribute === f;
|
|
1442
1453
|
});
|
|
1443
1454
|
}
|
|
1444
1455
|
|
|
1445
1456
|
var valueAsString = '' + value;
|
|
1446
1457
|
|
|
1447
|
-
return lib.clearRefinement(refinementList, function(v, f) {
|
|
1458
|
+
return lib.clearRefinement(refinementList, function (v, f) {
|
|
1448
1459
|
return attribute === f && valueAsString === v;
|
|
1449
1460
|
});
|
|
1450
1461
|
},
|
|
@@ -1455,8 +1466,13 @@
|
|
|
1455
1466
|
* @param {string} value the value of the refinement
|
|
1456
1467
|
* @return {RefinementList} a new and updated list
|
|
1457
1468
|
*/
|
|
1458
|
-
toggleRefinement: function toggleRefinement(
|
|
1459
|
-
|
|
1469
|
+
toggleRefinement: function toggleRefinement(
|
|
1470
|
+
refinementList,
|
|
1471
|
+
attribute,
|
|
1472
|
+
value
|
|
1473
|
+
) {
|
|
1474
|
+
if (value === undefined)
|
|
1475
|
+
throw new Error('toggleRefinement should be used with a value');
|
|
1460
1476
|
|
|
1461
1477
|
if (lib.isRefined(refinementList, attribute, value)) {
|
|
1462
1478
|
return lib.removeRefinement(refinementList, attribute, value);
|
|
@@ -1475,8 +1491,14 @@
|
|
|
1475
1491
|
* @param {string} [refinementType] optional parameter to give more context to the attribute function
|
|
1476
1492
|
* @return {RefinementList} a new and updated refinement list
|
|
1477
1493
|
*/
|
|
1478
|
-
clearRefinement: function clearRefinement(
|
|
1494
|
+
clearRefinement: function clearRefinement(
|
|
1495
|
+
refinementList,
|
|
1496
|
+
attribute,
|
|
1497
|
+
refinementType
|
|
1498
|
+
) {
|
|
1479
1499
|
if (attribute === undefined) {
|
|
1500
|
+
// return the same object if the list is already empty
|
|
1501
|
+
// this is mainly for tests, as it doesn't have much impact on performance
|
|
1480
1502
|
if (!objectHasKeys_1(refinementList)) {
|
|
1481
1503
|
return refinementList;
|
|
1482
1504
|
}
|
|
@@ -1486,23 +1508,32 @@
|
|
|
1486
1508
|
} else if (typeof attribute === 'function') {
|
|
1487
1509
|
var hasChanged = false;
|
|
1488
1510
|
|
|
1489
|
-
var newRefinementList = Object.keys(refinementList).reduce(function(
|
|
1511
|
+
var newRefinementList = Object.keys(refinementList).reduce(function (
|
|
1512
|
+
memo,
|
|
1513
|
+
key
|
|
1514
|
+
) {
|
|
1490
1515
|
var values = refinementList[key] || [];
|
|
1491
|
-
var facetList = values.filter(function(value) {
|
|
1516
|
+
var facetList = values.filter(function (value) {
|
|
1492
1517
|
return !attribute(value, key, refinementType);
|
|
1493
1518
|
});
|
|
1494
1519
|
|
|
1495
1520
|
if (facetList.length !== values.length) {
|
|
1496
1521
|
hasChanged = true;
|
|
1497
1522
|
}
|
|
1523
|
+
|
|
1498
1524
|
memo[key] = facetList;
|
|
1499
1525
|
|
|
1500
1526
|
return memo;
|
|
1501
|
-
},
|
|
1527
|
+
},
|
|
1528
|
+
{});
|
|
1502
1529
|
|
|
1503
1530
|
if (hasChanged) return newRefinementList;
|
|
1504
1531
|
return refinementList;
|
|
1505
1532
|
}
|
|
1533
|
+
|
|
1534
|
+
// We return nothing if the attribute is not undefined, a string or a function,
|
|
1535
|
+
// as it is not a valid value for a refinement
|
|
1536
|
+
return undefined;
|
|
1506
1537
|
},
|
|
1507
1538
|
/**
|
|
1508
1539
|
* Test if the refinement value is used for the attribute. If no refinement value
|
|
@@ -1511,10 +1542,11 @@
|
|
|
1511
1542
|
* @param {RefinementList} refinementList the list of refinement
|
|
1512
1543
|
* @param {string} attribute name of the attribute
|
|
1513
1544
|
* @param {string} [refinementValue] value of the filter/refinement
|
|
1514
|
-
* @return {boolean}
|
|
1545
|
+
* @return {boolean} true if the attribute is refined, false otherwise
|
|
1515
1546
|
*/
|
|
1516
1547
|
isRefined: function isRefined(refinementList, attribute, refinementValue) {
|
|
1517
|
-
var containsRefinements =
|
|
1548
|
+
var containsRefinements =
|
|
1549
|
+
Boolean(refinementList[attribute]) &&
|
|
1518
1550
|
refinementList[attribute].length > 0;
|
|
1519
1551
|
|
|
1520
1552
|
if (refinementValue === undefined || !containsRefinements) {
|
|
@@ -1524,7 +1556,7 @@
|
|
|
1524
1556
|
var refinementValueAsString = '' + refinementValue;
|
|
1525
1557
|
|
|
1526
1558
|
return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
|
|
1527
|
-
}
|
|
1559
|
+
},
|
|
1528
1560
|
};
|
|
1529
1561
|
|
|
1530
1562
|
var RefinementList = lib;
|
|
@@ -1535,12 +1567,15 @@
|
|
|
1535
1567
|
* - [5]
|
|
1536
1568
|
* - [[5]]
|
|
1537
1569
|
* - [[5,5],[4]]
|
|
1570
|
+
* @param {any} a numeric refinement value
|
|
1571
|
+
* @param {any} b numeric refinement value
|
|
1572
|
+
* @return {boolean} true if the values are equal
|
|
1538
1573
|
*/
|
|
1539
1574
|
function isEqualNumericRefinement(a, b) {
|
|
1540
1575
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1541
1576
|
return (
|
|
1542
1577
|
a.length === b.length &&
|
|
1543
|
-
a.every(function(el, i) {
|
|
1578
|
+
a.every(function (el, i) {
|
|
1544
1579
|
return isEqualNumericRefinement(b[i], el);
|
|
1545
1580
|
})
|
|
1546
1581
|
);
|
|
@@ -1557,7 +1592,7 @@
|
|
|
1557
1592
|
* @return {any} the searched value or undefined
|
|
1558
1593
|
*/
|
|
1559
1594
|
function findArray(array, searchedValue) {
|
|
1560
|
-
return find$1(array, function(currentValue) {
|
|
1595
|
+
return find$1(array, function (currentValue) {
|
|
1561
1596
|
return isEqualNumericRefinement(currentValue, searchedValue);
|
|
1562
1597
|
});
|
|
1563
1598
|
}
|
|
@@ -1610,10 +1645,15 @@
|
|
|
1610
1645
|
}
|
|
1611
1646
|
*/
|
|
1612
1647
|
function SearchParameters(newParameters) {
|
|
1613
|
-
var params = newParameters
|
|
1648
|
+
var params = newParameters
|
|
1649
|
+
? SearchParameters._parseNumbers(newParameters)
|
|
1650
|
+
: {};
|
|
1614
1651
|
|
|
1615
1652
|
if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
|
|
1616
|
-
|
|
1653
|
+
// eslint-disable-next-line no-console
|
|
1654
|
+
console.warn(
|
|
1655
|
+
'[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}'
|
|
1656
|
+
);
|
|
1617
1657
|
}
|
|
1618
1658
|
/**
|
|
1619
1659
|
* This attribute contains the list of all the conjunctive facets
|
|
@@ -1713,10 +1753,12 @@
|
|
|
1713
1753
|
* be translated into the `facetFilters` attribute.
|
|
1714
1754
|
* @member {Object.<string, SearchParameters.FacetList>}
|
|
1715
1755
|
*/
|
|
1716
|
-
this.hierarchicalFacetsRefinements =
|
|
1756
|
+
this.hierarchicalFacetsRefinements =
|
|
1757
|
+
params.hierarchicalFacetsRefinements || {};
|
|
1717
1758
|
|
|
1759
|
+
// eslint-disable-next-line consistent-this
|
|
1718
1760
|
var self = this;
|
|
1719
|
-
Object.keys(params).forEach(function(paramName) {
|
|
1761
|
+
Object.keys(params).forEach(function (paramName) {
|
|
1720
1762
|
var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
|
|
1721
1763
|
var isValueDefined = params[paramName] !== undefined;
|
|
1722
1764
|
|
|
@@ -1738,8 +1780,8 @@
|
|
|
1738
1780
|
* @param {object} partialState full or part of a state
|
|
1739
1781
|
* @return {object} a new object with the number keys as number
|
|
1740
1782
|
*/
|
|
1741
|
-
SearchParameters._parseNumbers = function(partialState) {
|
|
1742
|
-
// Do not
|
|
1783
|
+
SearchParameters._parseNumbers = function (partialState) {
|
|
1784
|
+
// Do not parse numbers again in SearchParameters, they ought to be parsed already
|
|
1743
1785
|
if (partialState instanceof SearchParameters) return partialState;
|
|
1744
1786
|
|
|
1745
1787
|
var numbers = {};
|
|
@@ -1755,10 +1797,10 @@
|
|
|
1755
1797
|
'distinct',
|
|
1756
1798
|
'minimumAroundRadius',
|
|
1757
1799
|
'hitsPerPage',
|
|
1758
|
-
'minProximity'
|
|
1800
|
+
'minProximity',
|
|
1759
1801
|
];
|
|
1760
1802
|
|
|
1761
|
-
numberKeys.forEach(function(k) {
|
|
1803
|
+
numberKeys.forEach(function (k) {
|
|
1762
1804
|
var value = partialState[k];
|
|
1763
1805
|
if (typeof value === 'string') {
|
|
1764
1806
|
var parsedValue = parseFloat(value);
|
|
@@ -1770,9 +1812,11 @@
|
|
|
1770
1812
|
// there's two formats of insideBoundingBox, we need to parse
|
|
1771
1813
|
// the one which is an array of float geo rectangles
|
|
1772
1814
|
if (Array.isArray(partialState.insideBoundingBox)) {
|
|
1773
|
-
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(
|
|
1815
|
+
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
|
|
1816
|
+
geoRect
|
|
1817
|
+
) {
|
|
1774
1818
|
if (Array.isArray(geoRect)) {
|
|
1775
|
-
return geoRect.map(function(value) {
|
|
1819
|
+
return geoRect.map(function (value) {
|
|
1776
1820
|
return parseFloat(value);
|
|
1777
1821
|
});
|
|
1778
1822
|
}
|
|
@@ -1782,14 +1826,14 @@
|
|
|
1782
1826
|
|
|
1783
1827
|
if (partialState.numericRefinements) {
|
|
1784
1828
|
var numericRefinements = {};
|
|
1785
|
-
Object.keys(partialState.numericRefinements).forEach(function(attribute) {
|
|
1829
|
+
Object.keys(partialState.numericRefinements).forEach(function (attribute) {
|
|
1786
1830
|
var operators = partialState.numericRefinements[attribute] || {};
|
|
1787
1831
|
numericRefinements[attribute] = {};
|
|
1788
|
-
Object.keys(operators).forEach(function(operator) {
|
|
1832
|
+
Object.keys(operators).forEach(function (operator) {
|
|
1789
1833
|
var values = operators[operator];
|
|
1790
|
-
var parsedValues = values.map(function(v) {
|
|
1834
|
+
var parsedValues = values.map(function (v) {
|
|
1791
1835
|
if (Array.isArray(v)) {
|
|
1792
|
-
return v.map(function(vPrime) {
|
|
1836
|
+
return v.map(function (vPrime) {
|
|
1793
1837
|
if (typeof vPrime === 'string') {
|
|
1794
1838
|
return parseFloat(vPrime);
|
|
1795
1839
|
}
|
|
@@ -1819,18 +1863,24 @@
|
|
|
1819
1863
|
var instance = new SearchParameters(newParameters);
|
|
1820
1864
|
|
|
1821
1865
|
var hierarchicalFacets = newParameters.hierarchicalFacets || [];
|
|
1822
|
-
hierarchicalFacets.forEach(function(facet) {
|
|
1866
|
+
hierarchicalFacets.forEach(function (facet) {
|
|
1823
1867
|
if (facet.rootPath) {
|
|
1824
1868
|
var currentRefinement = instance.getHierarchicalRefinement(facet.name);
|
|
1825
1869
|
|
|
1826
|
-
if (
|
|
1870
|
+
if (
|
|
1871
|
+
currentRefinement.length > 0 &&
|
|
1872
|
+
currentRefinement[0].indexOf(facet.rootPath) !== 0
|
|
1873
|
+
) {
|
|
1827
1874
|
instance = instance.clearRefinements(facet.name);
|
|
1828
1875
|
}
|
|
1829
1876
|
|
|
1830
1877
|
// get it again in case it has been cleared
|
|
1831
1878
|
currentRefinement = instance.getHierarchicalRefinement(facet.name);
|
|
1832
1879
|
if (currentRefinement.length === 0) {
|
|
1833
|
-
instance = instance.toggleHierarchicalFacetRefinement(
|
|
1880
|
+
instance = instance.toggleHierarchicalFacetRefinement(
|
|
1881
|
+
facet.name,
|
|
1882
|
+
facet.rootPath
|
|
1883
|
+
);
|
|
1834
1884
|
}
|
|
1835
1885
|
}
|
|
1836
1886
|
});
|
|
@@ -1844,19 +1894,25 @@
|
|
|
1844
1894
|
* @param {object|SearchParameters} parameters the new parameters to set
|
|
1845
1895
|
* @return {Error|null} Error if the modification is invalid, null otherwise
|
|
1846
1896
|
*/
|
|
1847
|
-
SearchParameters.validate = function(currentState, parameters) {
|
|
1897
|
+
SearchParameters.validate = function (currentState, parameters) {
|
|
1848
1898
|
var params = parameters || {};
|
|
1849
1899
|
|
|
1850
|
-
if (
|
|
1900
|
+
if (
|
|
1901
|
+
currentState.tagFilters &&
|
|
1902
|
+
params.tagRefinements &&
|
|
1903
|
+
params.tagRefinements.length > 0
|
|
1904
|
+
) {
|
|
1851
1905
|
return new Error(
|
|
1852
1906
|
'[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
|
|
1853
|
-
|
|
1907
|
+
'an error, if it is really what you want, you should first clear the tags with clearTags method.'
|
|
1908
|
+
);
|
|
1854
1909
|
}
|
|
1855
1910
|
|
|
1856
1911
|
if (currentState.tagRefinements.length > 0 && params.tagFilters) {
|
|
1857
1912
|
return new Error(
|
|
1858
1913
|
'[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
|
|
1859
|
-
|
|
1914
|
+
'an error, if it is not, you should first clear the tags with clearTags method.'
|
|
1915
|
+
);
|
|
1860
1916
|
}
|
|
1861
1917
|
|
|
1862
1918
|
if (
|
|
@@ -1874,8 +1930,9 @@
|
|
|
1874
1930
|
if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
|
|
1875
1931
|
return new Error(
|
|
1876
1932
|
"[Numeric filters] Can't switch from the managed API to the advanced. It" +
|
|
1877
|
-
|
|
1878
|
-
|
|
1933
|
+
' is probably an error, if this is really what you want, you have to first' +
|
|
1934
|
+
' clear the numeric filters.'
|
|
1935
|
+
);
|
|
1879
1936
|
}
|
|
1880
1937
|
|
|
1881
1938
|
return null;
|
|
@@ -1891,7 +1948,7 @@
|
|
|
1891
1948
|
* - If not given, means to clear all the filters.
|
|
1892
1949
|
* - If `string`, means to clear all refinements for the `attribute` named filter.
|
|
1893
1950
|
* - If `function`, means to clear all the refinements that return truthy values.
|
|
1894
|
-
* @return {SearchParameters}
|
|
1951
|
+
* @return {SearchParameters} new instance with filters cleared
|
|
1895
1952
|
*/
|
|
1896
1953
|
clearRefinements: function clearRefinements(attribute) {
|
|
1897
1954
|
var patch = {
|
|
@@ -1915,13 +1972,14 @@
|
|
|
1915
1972
|
this.hierarchicalFacetsRefinements,
|
|
1916
1973
|
attribute,
|
|
1917
1974
|
'hierarchicalFacet'
|
|
1918
|
-
)
|
|
1975
|
+
),
|
|
1919
1976
|
};
|
|
1920
1977
|
if (
|
|
1921
1978
|
patch.numericRefinements === this.numericRefinements &&
|
|
1922
1979
|
patch.facetsRefinements === this.facetsRefinements &&
|
|
1923
1980
|
patch.facetsExcludes === this.facetsExcludes &&
|
|
1924
|
-
patch.disjunctiveFacetsRefinements ===
|
|
1981
|
+
patch.disjunctiveFacetsRefinements ===
|
|
1982
|
+
this.disjunctiveFacetsRefinements &&
|
|
1925
1983
|
patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
|
|
1926
1984
|
) {
|
|
1927
1985
|
return this;
|
|
@@ -1931,53 +1989,54 @@
|
|
|
1931
1989
|
/**
|
|
1932
1990
|
* Remove all the refined tags from the SearchParameters
|
|
1933
1991
|
* @method
|
|
1934
|
-
* @return {SearchParameters}
|
|
1992
|
+
* @return {SearchParameters} new instance with tags cleared
|
|
1935
1993
|
*/
|
|
1936
1994
|
clearTags: function clearTags() {
|
|
1937
|
-
if (this.tagFilters === undefined && this.tagRefinements.length === 0)
|
|
1995
|
+
if (this.tagFilters === undefined && this.tagRefinements.length === 0)
|
|
1996
|
+
return this;
|
|
1938
1997
|
|
|
1939
1998
|
return this.setQueryParameters({
|
|
1940
1999
|
tagFilters: undefined,
|
|
1941
|
-
tagRefinements: []
|
|
2000
|
+
tagRefinements: [],
|
|
1942
2001
|
});
|
|
1943
2002
|
},
|
|
1944
2003
|
/**
|
|
1945
2004
|
* Set the index.
|
|
1946
2005
|
* @method
|
|
1947
2006
|
* @param {string} index the index name
|
|
1948
|
-
* @return {SearchParameters}
|
|
2007
|
+
* @return {SearchParameters} new instance
|
|
1949
2008
|
*/
|
|
1950
2009
|
setIndex: function setIndex(index) {
|
|
1951
2010
|
if (index === this.index) return this;
|
|
1952
2011
|
|
|
1953
2012
|
return this.setQueryParameters({
|
|
1954
|
-
index: index
|
|
2013
|
+
index: index,
|
|
1955
2014
|
});
|
|
1956
2015
|
},
|
|
1957
2016
|
/**
|
|
1958
2017
|
* Query setter
|
|
1959
2018
|
* @method
|
|
1960
2019
|
* @param {string} newQuery value for the new query
|
|
1961
|
-
* @return {SearchParameters}
|
|
2020
|
+
* @return {SearchParameters} new instance
|
|
1962
2021
|
*/
|
|
1963
2022
|
setQuery: function setQuery(newQuery) {
|
|
1964
2023
|
if (newQuery === this.query) return this;
|
|
1965
2024
|
|
|
1966
2025
|
return this.setQueryParameters({
|
|
1967
|
-
query: newQuery
|
|
2026
|
+
query: newQuery,
|
|
1968
2027
|
});
|
|
1969
2028
|
},
|
|
1970
2029
|
/**
|
|
1971
2030
|
* Page setter
|
|
1972
2031
|
* @method
|
|
1973
2032
|
* @param {number} newPage new page number
|
|
1974
|
-
* @return {SearchParameters}
|
|
2033
|
+
* @return {SearchParameters} new instance
|
|
1975
2034
|
*/
|
|
1976
2035
|
setPage: function setPage(newPage) {
|
|
1977
2036
|
if (newPage === this.page) return this;
|
|
1978
2037
|
|
|
1979
2038
|
return this.setQueryParameters({
|
|
1980
|
-
page: newPage
|
|
2039
|
+
page: newPage,
|
|
1981
2040
|
});
|
|
1982
2041
|
},
|
|
1983
2042
|
/**
|
|
@@ -1985,11 +2044,11 @@
|
|
|
1985
2044
|
* The facets are the simple facets, used for conjunctive (and) faceting.
|
|
1986
2045
|
* @method
|
|
1987
2046
|
* @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
|
|
1988
|
-
* @return {SearchParameters}
|
|
2047
|
+
* @return {SearchParameters} new instance
|
|
1989
2048
|
*/
|
|
1990
2049
|
setFacets: function setFacets(facets) {
|
|
1991
2050
|
return this.setQueryParameters({
|
|
1992
|
-
facets: facets
|
|
2051
|
+
facets: facets,
|
|
1993
2052
|
});
|
|
1994
2053
|
},
|
|
1995
2054
|
/**
|
|
@@ -1997,11 +2056,11 @@
|
|
|
1997
2056
|
* Change the list of disjunctive (or) facets the helper chan handle.
|
|
1998
2057
|
* @method
|
|
1999
2058
|
* @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
|
|
2000
|
-
* @return {SearchParameters}
|
|
2059
|
+
* @return {SearchParameters} new instance
|
|
2001
2060
|
*/
|
|
2002
2061
|
setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
|
|
2003
2062
|
return this.setQueryParameters({
|
|
2004
|
-
disjunctiveFacets: facets
|
|
2063
|
+
disjunctiveFacets: facets,
|
|
2005
2064
|
});
|
|
2006
2065
|
},
|
|
2007
2066
|
/**
|
|
@@ -2009,13 +2068,13 @@
|
|
|
2009
2068
|
* Hits per page represents the number of hits retrieved for this query
|
|
2010
2069
|
* @method
|
|
2011
2070
|
* @param {number} n number of hits retrieved per page of results
|
|
2012
|
-
* @return {SearchParameters}
|
|
2071
|
+
* @return {SearchParameters} new instance
|
|
2013
2072
|
*/
|
|
2014
2073
|
setHitsPerPage: function setHitsPerPage(n) {
|
|
2015
2074
|
if (this.hitsPerPage === n) return this;
|
|
2016
2075
|
|
|
2017
2076
|
return this.setQueryParameters({
|
|
2018
|
-
hitsPerPage: n
|
|
2077
|
+
hitsPerPage: n,
|
|
2019
2078
|
});
|
|
2020
2079
|
},
|
|
2021
2080
|
/**
|
|
@@ -2023,13 +2082,13 @@
|
|
|
2023
2082
|
* Set the value of typoTolerance
|
|
2024
2083
|
* @method
|
|
2025
2084
|
* @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
|
|
2026
|
-
* @return {SearchParameters}
|
|
2085
|
+
* @return {SearchParameters} new instance
|
|
2027
2086
|
*/
|
|
2028
2087
|
setTypoTolerance: function setTypoTolerance(typoTolerance) {
|
|
2029
2088
|
if (this.typoTolerance === typoTolerance) return this;
|
|
2030
2089
|
|
|
2031
2090
|
return this.setQueryParameters({
|
|
2032
|
-
typoTolerance: typoTolerance
|
|
2091
|
+
typoTolerance: typoTolerance,
|
|
2033
2092
|
});
|
|
2034
2093
|
},
|
|
2035
2094
|
/**
|
|
@@ -2040,19 +2099,19 @@
|
|
|
2040
2099
|
* @param {string} attribute attribute to set the filter on
|
|
2041
2100
|
* @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
|
|
2042
2101
|
* @param {number | number[]} value value of the filter
|
|
2043
|
-
* @return {SearchParameters}
|
|
2102
|
+
* @return {SearchParameters} new instance
|
|
2044
2103
|
* @example
|
|
2045
2104
|
* // for price = 50 or 40
|
|
2046
|
-
*
|
|
2105
|
+
* state.addNumericRefinement('price', '=', [50, 40]);
|
|
2047
2106
|
* @example
|
|
2048
2107
|
* // for size = 38 and 40
|
|
2049
|
-
*
|
|
2050
|
-
*
|
|
2108
|
+
* state.addNumericRefinement('size', '=', 38);
|
|
2109
|
+
* state.addNumericRefinement('size', '=', 40);
|
|
2051
2110
|
*/
|
|
2052
|
-
addNumericRefinement: function(attribute, operator,
|
|
2053
|
-
var
|
|
2111
|
+
addNumericRefinement: function (attribute, operator, value) {
|
|
2112
|
+
var val = valToNumber_1(value);
|
|
2054
2113
|
|
|
2055
|
-
if (this.isNumericRefined(attribute, operator,
|
|
2114
|
+
if (this.isNumericRefined(attribute, operator, val)) return this;
|
|
2056
2115
|
|
|
2057
2116
|
var mod = merge_1({}, this.numericRefinements);
|
|
2058
2117
|
|
|
@@ -2062,13 +2121,13 @@
|
|
|
2062
2121
|
// Array copy
|
|
2063
2122
|
mod[attribute][operator] = mod[attribute][operator].slice();
|
|
2064
2123
|
// Add the element. Concat can't be used here because value can be an array.
|
|
2065
|
-
mod[attribute][operator].push(
|
|
2124
|
+
mod[attribute][operator].push(val);
|
|
2066
2125
|
} else {
|
|
2067
|
-
mod[attribute][operator] = [
|
|
2126
|
+
mod[attribute][operator] = [val];
|
|
2068
2127
|
}
|
|
2069
2128
|
|
|
2070
2129
|
return this.setQueryParameters({
|
|
2071
|
-
numericRefinements: mod
|
|
2130
|
+
numericRefinements: mod,
|
|
2072
2131
|
});
|
|
2073
2132
|
},
|
|
2074
2133
|
/**
|
|
@@ -2076,7 +2135,7 @@
|
|
|
2076
2135
|
* @param {string} facetName name of the attribute used for faceting
|
|
2077
2136
|
* @return {string[]} list of refinements
|
|
2078
2137
|
*/
|
|
2079
|
-
getConjunctiveRefinements: function(facetName) {
|
|
2138
|
+
getConjunctiveRefinements: function (facetName) {
|
|
2080
2139
|
if (!this.isConjunctiveFacet(facetName)) {
|
|
2081
2140
|
return [];
|
|
2082
2141
|
}
|
|
@@ -2087,7 +2146,7 @@
|
|
|
2087
2146
|
* @param {string} facetName name of the attribute used for faceting
|
|
2088
2147
|
* @return {string[]} list of refinements
|
|
2089
2148
|
*/
|
|
2090
|
-
getDisjunctiveRefinements: function(facetName) {
|
|
2149
|
+
getDisjunctiveRefinements: function (facetName) {
|
|
2091
2150
|
if (!this.isDisjunctiveFacet(facetName)) {
|
|
2092
2151
|
return [];
|
|
2093
2152
|
}
|
|
@@ -2098,7 +2157,7 @@
|
|
|
2098
2157
|
* @param {string} facetName name of the attribute used for faceting
|
|
2099
2158
|
* @return {string[]} list of refinements
|
|
2100
2159
|
*/
|
|
2101
|
-
getHierarchicalRefinement: function(facetName) {
|
|
2160
|
+
getHierarchicalRefinement: function (facetName) {
|
|
2102
2161
|
// we send an array but we currently do not support multiple
|
|
2103
2162
|
// hierarchicalRefinements for a hierarchicalFacet
|
|
2104
2163
|
return this.hierarchicalFacetsRefinements[facetName] || [];
|
|
@@ -2108,7 +2167,7 @@
|
|
|
2108
2167
|
* @param {string} facetName name of the attribute used for faceting
|
|
2109
2168
|
* @return {string[]} list of refinements
|
|
2110
2169
|
*/
|
|
2111
|
-
getExcludeRefinements: function(facetName) {
|
|
2170
|
+
getExcludeRefinements: function (facetName) {
|
|
2112
2171
|
if (!this.isConjunctiveFacet(facetName)) {
|
|
2113
2172
|
return [];
|
|
2114
2173
|
}
|
|
@@ -2121,36 +2180,43 @@
|
|
|
2121
2180
|
* @param {string} attribute attribute to set the filter on
|
|
2122
2181
|
* @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
|
|
2123
2182
|
* @param {number} [number] the value to be removed
|
|
2124
|
-
* @return {SearchParameters}
|
|
2183
|
+
* @return {SearchParameters} new instance
|
|
2125
2184
|
*/
|
|
2126
|
-
removeNumericRefinement: function(attribute, operator,
|
|
2185
|
+
removeNumericRefinement: function (attribute, operator, number) {
|
|
2186
|
+
var paramValue = number;
|
|
2127
2187
|
if (paramValue !== undefined) {
|
|
2128
2188
|
if (!this.isNumericRefined(attribute, operator, paramValue)) {
|
|
2129
2189
|
return this;
|
|
2130
2190
|
}
|
|
2131
2191
|
return this.setQueryParameters({
|
|
2132
|
-
numericRefinements: this._clearNumericRefinements(function(
|
|
2192
|
+
numericRefinements: this._clearNumericRefinements(function (
|
|
2193
|
+
value,
|
|
2194
|
+
key
|
|
2195
|
+
) {
|
|
2133
2196
|
return (
|
|
2134
2197
|
key === attribute &&
|
|
2135
2198
|
value.op === operator &&
|
|
2136
2199
|
isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
|
|
2137
2200
|
);
|
|
2138
|
-
})
|
|
2201
|
+
}),
|
|
2139
2202
|
});
|
|
2140
2203
|
} else if (operator !== undefined) {
|
|
2141
2204
|
if (!this.isNumericRefined(attribute, operator)) return this;
|
|
2142
2205
|
return this.setQueryParameters({
|
|
2143
|
-
numericRefinements: this._clearNumericRefinements(function(
|
|
2206
|
+
numericRefinements: this._clearNumericRefinements(function (
|
|
2207
|
+
value,
|
|
2208
|
+
key
|
|
2209
|
+
) {
|
|
2144
2210
|
return key === attribute && value.op === operator;
|
|
2145
|
-
})
|
|
2211
|
+
}),
|
|
2146
2212
|
});
|
|
2147
2213
|
}
|
|
2148
2214
|
|
|
2149
2215
|
if (!this.isNumericRefined(attribute)) return this;
|
|
2150
2216
|
return this.setQueryParameters({
|
|
2151
|
-
numericRefinements: this._clearNumericRefinements(function(value, key) {
|
|
2217
|
+
numericRefinements: this._clearNumericRefinements(function (value, key) {
|
|
2152
2218
|
return key === attribute;
|
|
2153
|
-
})
|
|
2219
|
+
}),
|
|
2154
2220
|
});
|
|
2155
2221
|
},
|
|
2156
2222
|
/**
|
|
@@ -2158,7 +2224,7 @@
|
|
|
2158
2224
|
* @param {string} facetName name of the attribute used for faceting
|
|
2159
2225
|
* @return {SearchParameters.OperatorList} list of refinements
|
|
2160
2226
|
*/
|
|
2161
|
-
getNumericRefinements: function(facetName) {
|
|
2227
|
+
getNumericRefinements: function (facetName) {
|
|
2162
2228
|
return this.numericRefinements[facetName] || {};
|
|
2163
2229
|
},
|
|
2164
2230
|
/**
|
|
@@ -2167,8 +2233,11 @@
|
|
|
2167
2233
|
* @param {string} operator operator applied on the refined values
|
|
2168
2234
|
* @return {Array.<number|number[]>} refined values
|
|
2169
2235
|
*/
|
|
2170
|
-
getNumericRefinement: function(attribute, operator) {
|
|
2171
|
-
return
|
|
2236
|
+
getNumericRefinement: function (attribute, operator) {
|
|
2237
|
+
return (
|
|
2238
|
+
this.numericRefinements[attribute] &&
|
|
2239
|
+
this.numericRefinements[attribute][operator]
|
|
2240
|
+
);
|
|
2172
2241
|
},
|
|
2173
2242
|
/**
|
|
2174
2243
|
* Clear numeric filters.
|
|
@@ -2178,7 +2247,7 @@
|
|
|
2178
2247
|
* - If not given, means to clear all the filters.
|
|
2179
2248
|
* - If `string`, means to clear all refinements for the `attribute` named filter.
|
|
2180
2249
|
* - If `function`, means to clear all the refinements that return truthy values.
|
|
2181
|
-
* @return {Object.<string, OperatorList>}
|
|
2250
|
+
* @return {Object.<string, OperatorList>} new numeric refinements
|
|
2182
2251
|
*/
|
|
2183
2252
|
_clearNumericRefinements: function _clearNumericRefinements(attribute) {
|
|
2184
2253
|
if (attribute === undefined) {
|
|
@@ -2191,39 +2260,50 @@
|
|
|
2191
2260
|
} else if (typeof attribute === 'function') {
|
|
2192
2261
|
var hasChanged = false;
|
|
2193
2262
|
var numericRefinements = this.numericRefinements;
|
|
2194
|
-
var newNumericRefinements = Object.keys(numericRefinements).reduce(
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2263
|
+
var newNumericRefinements = Object.keys(numericRefinements).reduce(
|
|
2264
|
+
function (memo, key) {
|
|
2265
|
+
var operators = numericRefinements[key];
|
|
2266
|
+
var operatorList = {};
|
|
2267
|
+
|
|
2268
|
+
operators = operators || {};
|
|
2269
|
+
Object.keys(operators).forEach(function (operator) {
|
|
2270
|
+
var values = operators[operator] || [];
|
|
2271
|
+
var outValues = [];
|
|
2272
|
+
values.forEach(function (value) {
|
|
2273
|
+
var predicateResult = attribute(
|
|
2274
|
+
{ val: value, op: operator },
|
|
2275
|
+
key,
|
|
2276
|
+
'numeric'
|
|
2277
|
+
);
|
|
2278
|
+
if (!predicateResult) outValues.push(value);
|
|
2279
|
+
});
|
|
2280
|
+
if (outValues.length !== values.length) {
|
|
2281
|
+
hasChanged = true;
|
|
2282
|
+
}
|
|
2283
|
+
operatorList[operator] = outValues;
|
|
2205
2284
|
});
|
|
2206
|
-
if (outValues.length !== values.length) {
|
|
2207
|
-
hasChanged = true;
|
|
2208
|
-
}
|
|
2209
|
-
operatorList[operator] = outValues;
|
|
2210
|
-
});
|
|
2211
2285
|
|
|
2212
|
-
|
|
2286
|
+
memo[key] = operatorList;
|
|
2213
2287
|
|
|
2214
|
-
|
|
2215
|
-
|
|
2288
|
+
return memo;
|
|
2289
|
+
},
|
|
2290
|
+
{}
|
|
2291
|
+
);
|
|
2216
2292
|
|
|
2217
2293
|
if (hasChanged) return newNumericRefinements;
|
|
2218
2294
|
return this.numericRefinements;
|
|
2219
2295
|
}
|
|
2296
|
+
|
|
2297
|
+
// We return nothing if the attribute is not undefined, a string or a function,
|
|
2298
|
+
// as it is not a valid value for a refinement
|
|
2299
|
+
return undefined;
|
|
2220
2300
|
},
|
|
2221
2301
|
/**
|
|
2222
2302
|
* Add a facet to the facets attribute of the helper configuration, if it
|
|
2223
2303
|
* isn't already present.
|
|
2224
2304
|
* @method
|
|
2225
2305
|
* @param {string} facet facet name to add
|
|
2226
|
-
* @return {SearchParameters}
|
|
2306
|
+
* @return {SearchParameters} new instance
|
|
2227
2307
|
*/
|
|
2228
2308
|
addFacet: function addFacet(facet) {
|
|
2229
2309
|
if (this.isConjunctiveFacet(facet)) {
|
|
@@ -2231,7 +2311,7 @@
|
|
|
2231
2311
|
}
|
|
2232
2312
|
|
|
2233
2313
|
return this.setQueryParameters({
|
|
2234
|
-
facets: this.facets.concat([facet])
|
|
2314
|
+
facets: this.facets.concat([facet]),
|
|
2235
2315
|
});
|
|
2236
2316
|
},
|
|
2237
2317
|
/**
|
|
@@ -2239,7 +2319,7 @@
|
|
|
2239
2319
|
* configuration, if it isn't already present.
|
|
2240
2320
|
* @method
|
|
2241
2321
|
* @param {string} facet disjunctive facet name to add
|
|
2242
|
-
* @return {SearchParameters}
|
|
2322
|
+
* @return {SearchParameters} new instance
|
|
2243
2323
|
*/
|
|
2244
2324
|
addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
|
|
2245
2325
|
if (this.isDisjunctiveFacet(facet)) {
|
|
@@ -2247,7 +2327,7 @@
|
|
|
2247
2327
|
}
|
|
2248
2328
|
|
|
2249
2329
|
return this.setQueryParameters({
|
|
2250
|
-
disjunctiveFacets: this.disjunctiveFacets.concat([facet])
|
|
2330
|
+
disjunctiveFacets: this.disjunctiveFacets.concat([facet]),
|
|
2251
2331
|
});
|
|
2252
2332
|
},
|
|
2253
2333
|
/**
|
|
@@ -2255,17 +2335,20 @@
|
|
|
2255
2335
|
* configuration.
|
|
2256
2336
|
* @method
|
|
2257
2337
|
* @param {object} hierarchicalFacet hierarchical facet to add
|
|
2258
|
-
* @return {SearchParameters}
|
|
2338
|
+
* @return {SearchParameters} new instance
|
|
2259
2339
|
* @throws will throw an error if a hierarchical facet with the same name was already declared
|
|
2260
2340
|
*/
|
|
2261
2341
|
addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
|
|
2262
2342
|
if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
|
|
2263
2343
|
throw new Error(
|
|
2264
|
-
'Cannot declare two hierarchical facets with the same name: `' +
|
|
2344
|
+
'Cannot declare two hierarchical facets with the same name: `' +
|
|
2345
|
+
hierarchicalFacet.name +
|
|
2346
|
+
'`'
|
|
2347
|
+
);
|
|
2265
2348
|
}
|
|
2266
2349
|
|
|
2267
2350
|
return this.setQueryParameters({
|
|
2268
|
-
hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
|
|
2351
|
+
hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet]),
|
|
2269
2352
|
});
|
|
2270
2353
|
},
|
|
2271
2354
|
/**
|
|
@@ -2273,16 +2356,24 @@
|
|
|
2273
2356
|
* @method
|
|
2274
2357
|
* @param {string} facet attribute to apply the faceting on
|
|
2275
2358
|
* @param {string} value value of the attribute (will be converted to string)
|
|
2276
|
-
* @return {SearchParameters}
|
|
2359
|
+
* @return {SearchParameters} new instance
|
|
2277
2360
|
*/
|
|
2278
2361
|
addFacetRefinement: function addFacetRefinement(facet, value) {
|
|
2279
2362
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2280
|
-
throw new Error(
|
|
2363
|
+
throw new Error(
|
|
2364
|
+
facet +
|
|
2365
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2366
|
+
);
|
|
2281
2367
|
}
|
|
2282
|
-
if (RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2368
|
+
if (RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2369
|
+
return this;
|
|
2283
2370
|
|
|
2284
2371
|
return this.setQueryParameters({
|
|
2285
|
-
facetsRefinements: RefinementList.addRefinement(
|
|
2372
|
+
facetsRefinements: RefinementList.addRefinement(
|
|
2373
|
+
this.facetsRefinements,
|
|
2374
|
+
facet,
|
|
2375
|
+
value
|
|
2376
|
+
),
|
|
2286
2377
|
});
|
|
2287
2378
|
},
|
|
2288
2379
|
/**
|
|
@@ -2290,16 +2381,24 @@
|
|
|
2290
2381
|
* @method
|
|
2291
2382
|
* @param {string} facet attribute to apply the exclusion on
|
|
2292
2383
|
* @param {string} value value of the attribute (will be converted to string)
|
|
2293
|
-
* @return {SearchParameters}
|
|
2384
|
+
* @return {SearchParameters} new instance
|
|
2294
2385
|
*/
|
|
2295
2386
|
addExcludeRefinement: function addExcludeRefinement(facet, value) {
|
|
2296
2387
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2297
|
-
throw new Error(
|
|
2388
|
+
throw new Error(
|
|
2389
|
+
facet +
|
|
2390
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2391
|
+
);
|
|
2298
2392
|
}
|
|
2299
|
-
if (RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2393
|
+
if (RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2394
|
+
return this;
|
|
2300
2395
|
|
|
2301
2396
|
return this.setQueryParameters({
|
|
2302
|
-
facetsExcludes: RefinementList.addRefinement(
|
|
2397
|
+
facetsExcludes: RefinementList.addRefinement(
|
|
2398
|
+
this.facetsExcludes,
|
|
2399
|
+
facet,
|
|
2400
|
+
value
|
|
2401
|
+
),
|
|
2303
2402
|
});
|
|
2304
2403
|
},
|
|
2305
2404
|
/**
|
|
@@ -2307,31 +2406,42 @@
|
|
|
2307
2406
|
* @method
|
|
2308
2407
|
* @param {string} facet attribute to apply the faceting on
|
|
2309
2408
|
* @param {string} value value of the attribute (will be converted to string)
|
|
2310
|
-
* @return {SearchParameters}
|
|
2409
|
+
* @return {SearchParameters} new instance
|
|
2311
2410
|
*/
|
|
2312
|
-
addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
|
|
2411
|
+
addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
|
|
2412
|
+
facet,
|
|
2413
|
+
value
|
|
2414
|
+
) {
|
|
2313
2415
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2314
2416
|
throw new Error(
|
|
2315
|
-
facet +
|
|
2417
|
+
facet +
|
|
2418
|
+
' is not defined in the disjunctiveFacets attribute of the helper configuration'
|
|
2419
|
+
);
|
|
2316
2420
|
}
|
|
2317
2421
|
|
|
2318
|
-
if (
|
|
2422
|
+
if (
|
|
2423
|
+
RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
|
|
2424
|
+
)
|
|
2425
|
+
return this;
|
|
2319
2426
|
|
|
2320
2427
|
return this.setQueryParameters({
|
|
2321
2428
|
disjunctiveFacetsRefinements: RefinementList.addRefinement(
|
|
2322
|
-
this.disjunctiveFacetsRefinements,
|
|
2429
|
+
this.disjunctiveFacetsRefinements,
|
|
2430
|
+
facet,
|
|
2431
|
+
value
|
|
2432
|
+
),
|
|
2323
2433
|
});
|
|
2324
2434
|
},
|
|
2325
2435
|
/**
|
|
2326
2436
|
* addTagRefinement adds a tag to the list used to filter the results
|
|
2327
2437
|
* @param {string} tag tag to be added
|
|
2328
|
-
* @return {SearchParameters}
|
|
2438
|
+
* @return {SearchParameters} new instance
|
|
2329
2439
|
*/
|
|
2330
2440
|
addTagRefinement: function addTagRefinement(tag) {
|
|
2331
2441
|
if (this.isTagRefined(tag)) return this;
|
|
2332
2442
|
|
|
2333
2443
|
var modification = {
|
|
2334
|
-
tagRefinements: this.tagRefinements.concat(tag)
|
|
2444
|
+
tagRefinements: this.tagRefinements.concat(tag),
|
|
2335
2445
|
};
|
|
2336
2446
|
|
|
2337
2447
|
return this.setQueryParameters(modification);
|
|
@@ -2341,7 +2451,7 @@
|
|
|
2341
2451
|
* is present.
|
|
2342
2452
|
* @method
|
|
2343
2453
|
* @param {string} facet facet name to remove
|
|
2344
|
-
* @return {SearchParameters}
|
|
2454
|
+
* @return {SearchParameters} new instance
|
|
2345
2455
|
*/
|
|
2346
2456
|
removeFacet: function removeFacet(facet) {
|
|
2347
2457
|
if (!this.isConjunctiveFacet(facet)) {
|
|
@@ -2349,9 +2459,9 @@
|
|
|
2349
2459
|
}
|
|
2350
2460
|
|
|
2351
2461
|
return this.clearRefinements(facet).setQueryParameters({
|
|
2352
|
-
facets: this.facets.filter(function(f) {
|
|
2462
|
+
facets: this.facets.filter(function (f) {
|
|
2353
2463
|
return f !== facet;
|
|
2354
|
-
})
|
|
2464
|
+
}),
|
|
2355
2465
|
});
|
|
2356
2466
|
},
|
|
2357
2467
|
/**
|
|
@@ -2359,7 +2469,7 @@
|
|
|
2359
2469
|
* helper configuration, if it is present.
|
|
2360
2470
|
* @method
|
|
2361
2471
|
* @param {string} facet disjunctive facet name to remove
|
|
2362
|
-
* @return {SearchParameters}
|
|
2472
|
+
* @return {SearchParameters} new instance
|
|
2363
2473
|
*/
|
|
2364
2474
|
removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
|
|
2365
2475
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
@@ -2367,9 +2477,9 @@
|
|
|
2367
2477
|
}
|
|
2368
2478
|
|
|
2369
2479
|
return this.clearRefinements(facet).setQueryParameters({
|
|
2370
|
-
disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
|
|
2480
|
+
disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
|
|
2371
2481
|
return f !== facet;
|
|
2372
|
-
})
|
|
2482
|
+
}),
|
|
2373
2483
|
});
|
|
2374
2484
|
},
|
|
2375
2485
|
/**
|
|
@@ -2377,7 +2487,7 @@
|
|
|
2377
2487
|
* helper configuration, if it is present.
|
|
2378
2488
|
* @method
|
|
2379
2489
|
* @param {string} facet hierarchical facet name to remove
|
|
2380
|
-
* @return {SearchParameters}
|
|
2490
|
+
* @return {SearchParameters} new instance
|
|
2381
2491
|
*/
|
|
2382
2492
|
removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
|
|
2383
2493
|
if (!this.isHierarchicalFacet(facet)) {
|
|
@@ -2385,9 +2495,9 @@
|
|
|
2385
2495
|
}
|
|
2386
2496
|
|
|
2387
2497
|
return this.clearRefinements(facet).setQueryParameters({
|
|
2388
|
-
hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
|
|
2498
|
+
hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
|
|
2389
2499
|
return f.name !== facet;
|
|
2390
|
-
})
|
|
2500
|
+
}),
|
|
2391
2501
|
});
|
|
2392
2502
|
},
|
|
2393
2503
|
/**
|
|
@@ -2397,16 +2507,24 @@
|
|
|
2397
2507
|
* @method
|
|
2398
2508
|
* @param {string} facet name of the attribute used for faceting
|
|
2399
2509
|
* @param {string} [value] value used to filter
|
|
2400
|
-
* @return {SearchParameters}
|
|
2510
|
+
* @return {SearchParameters} new instance
|
|
2401
2511
|
*/
|
|
2402
2512
|
removeFacetRefinement: function removeFacetRefinement(facet, value) {
|
|
2403
2513
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2404
|
-
throw new Error(
|
|
2514
|
+
throw new Error(
|
|
2515
|
+
facet +
|
|
2516
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2517
|
+
);
|
|
2405
2518
|
}
|
|
2406
|
-
if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2519
|
+
if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2520
|
+
return this;
|
|
2407
2521
|
|
|
2408
2522
|
return this.setQueryParameters({
|
|
2409
|
-
facetsRefinements: RefinementList.removeRefinement(
|
|
2523
|
+
facetsRefinements: RefinementList.removeRefinement(
|
|
2524
|
+
this.facetsRefinements,
|
|
2525
|
+
facet,
|
|
2526
|
+
value
|
|
2527
|
+
),
|
|
2410
2528
|
});
|
|
2411
2529
|
},
|
|
2412
2530
|
/**
|
|
@@ -2414,16 +2532,24 @@
|
|
|
2414
2532
|
* @method
|
|
2415
2533
|
* @param {string} facet name of the attribute used for faceting
|
|
2416
2534
|
* @param {string} value value used to filter
|
|
2417
|
-
* @return {SearchParameters}
|
|
2535
|
+
* @return {SearchParameters} new instance
|
|
2418
2536
|
*/
|
|
2419
2537
|
removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
|
|
2420
2538
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2421
|
-
throw new Error(
|
|
2539
|
+
throw new Error(
|
|
2540
|
+
facet +
|
|
2541
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2542
|
+
);
|
|
2422
2543
|
}
|
|
2423
|
-
if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2544
|
+
if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2545
|
+
return this;
|
|
2424
2546
|
|
|
2425
2547
|
return this.setQueryParameters({
|
|
2426
|
-
facetsExcludes: RefinementList.removeRefinement(
|
|
2548
|
+
facetsExcludes: RefinementList.removeRefinement(
|
|
2549
|
+
this.facetsExcludes,
|
|
2550
|
+
facet,
|
|
2551
|
+
value
|
|
2552
|
+
),
|
|
2427
2553
|
});
|
|
2428
2554
|
},
|
|
2429
2555
|
/**
|
|
@@ -2431,33 +2557,44 @@
|
|
|
2431
2557
|
* @method
|
|
2432
2558
|
* @param {string} facet name of the attribute used for faceting
|
|
2433
2559
|
* @param {string} value value used to filter
|
|
2434
|
-
* @return {SearchParameters}
|
|
2560
|
+
* @return {SearchParameters} new instance
|
|
2435
2561
|
*/
|
|
2436
|
-
removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
|
|
2562
|
+
removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
|
|
2563
|
+
facet,
|
|
2564
|
+
value
|
|
2565
|
+
) {
|
|
2437
2566
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2438
2567
|
throw new Error(
|
|
2439
|
-
facet +
|
|
2568
|
+
facet +
|
|
2569
|
+
' is not defined in the disjunctiveFacets attribute of the helper configuration'
|
|
2570
|
+
);
|
|
2440
2571
|
}
|
|
2441
|
-
if (
|
|
2572
|
+
if (
|
|
2573
|
+
!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
|
|
2574
|
+
)
|
|
2575
|
+
return this;
|
|
2442
2576
|
|
|
2443
2577
|
return this.setQueryParameters({
|
|
2444
2578
|
disjunctiveFacetsRefinements: RefinementList.removeRefinement(
|
|
2445
|
-
this.disjunctiveFacetsRefinements,
|
|
2579
|
+
this.disjunctiveFacetsRefinements,
|
|
2580
|
+
facet,
|
|
2581
|
+
value
|
|
2582
|
+
),
|
|
2446
2583
|
});
|
|
2447
2584
|
},
|
|
2448
2585
|
/**
|
|
2449
2586
|
* Remove a tag from the list of tag refinements
|
|
2450
2587
|
* @method
|
|
2451
2588
|
* @param {string} tag the tag to remove
|
|
2452
|
-
* @return {SearchParameters}
|
|
2589
|
+
* @return {SearchParameters} new instance
|
|
2453
2590
|
*/
|
|
2454
2591
|
removeTagRefinement: function removeTagRefinement(tag) {
|
|
2455
2592
|
if (!this.isTagRefined(tag)) return this;
|
|
2456
2593
|
|
|
2457
2594
|
var modification = {
|
|
2458
|
-
tagRefinements: this.tagRefinements.filter(function(t) {
|
|
2595
|
+
tagRefinements: this.tagRefinements.filter(function (t) {
|
|
2459
2596
|
return t !== tag;
|
|
2460
|
-
})
|
|
2597
|
+
}),
|
|
2461
2598
|
};
|
|
2462
2599
|
|
|
2463
2600
|
return this.setQueryParameters(modification);
|
|
@@ -2467,7 +2604,7 @@
|
|
|
2467
2604
|
* and hierarchical facets
|
|
2468
2605
|
* @param {string} facet the facet to refine
|
|
2469
2606
|
* @param {string} value the associated value
|
|
2470
|
-
* @return {SearchParameters}
|
|
2607
|
+
* @return {SearchParameters} new instance
|
|
2471
2608
|
* @throws will throw an error if the facet is not declared in the settings of the helper
|
|
2472
2609
|
* @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
|
|
2473
2610
|
*/
|
|
@@ -2479,7 +2616,7 @@
|
|
|
2479
2616
|
* and hierarchical facets
|
|
2480
2617
|
* @param {string} facet the facet to refine
|
|
2481
2618
|
* @param {string} value the associated value
|
|
2482
|
-
* @return {SearchParameters}
|
|
2619
|
+
* @return {SearchParameters} new instance
|
|
2483
2620
|
* @throws will throw an error if the facet is not declared in the settings of the helper
|
|
2484
2621
|
*/
|
|
2485
2622
|
toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
|
|
@@ -2491,23 +2628,36 @@
|
|
|
2491
2628
|
return this.toggleDisjunctiveFacetRefinement(facet, value);
|
|
2492
2629
|
}
|
|
2493
2630
|
|
|
2494
|
-
throw new Error(
|
|
2495
|
-
'
|
|
2631
|
+
throw new Error(
|
|
2632
|
+
'Cannot refine the undeclared facet ' +
|
|
2633
|
+
facet +
|
|
2634
|
+
'; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets'
|
|
2635
|
+
);
|
|
2496
2636
|
},
|
|
2497
2637
|
/**
|
|
2498
2638
|
* Switch the refinement applied over a facet/value
|
|
2499
2639
|
* @method
|
|
2500
2640
|
* @param {string} facet name of the attribute used for faceting
|
|
2501
2641
|
* @param {value} value value used for filtering
|
|
2502
|
-
* @return {SearchParameters}
|
|
2642
|
+
* @return {SearchParameters} new instance
|
|
2503
2643
|
*/
|
|
2504
|
-
toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
|
|
2644
|
+
toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
|
|
2645
|
+
facet,
|
|
2646
|
+
value
|
|
2647
|
+
) {
|
|
2505
2648
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2506
|
-
throw new Error(
|
|
2649
|
+
throw new Error(
|
|
2650
|
+
facet +
|
|
2651
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2652
|
+
);
|
|
2507
2653
|
}
|
|
2508
2654
|
|
|
2509
2655
|
return this.setQueryParameters({
|
|
2510
|
-
facetsRefinements: RefinementList.toggleRefinement(
|
|
2656
|
+
facetsRefinements: RefinementList.toggleRefinement(
|
|
2657
|
+
this.facetsRefinements,
|
|
2658
|
+
facet,
|
|
2659
|
+
value
|
|
2660
|
+
),
|
|
2511
2661
|
});
|
|
2512
2662
|
},
|
|
2513
2663
|
/**
|
|
@@ -2515,15 +2665,25 @@
|
|
|
2515
2665
|
* @method
|
|
2516
2666
|
* @param {string} facet name of the attribute used for faceting
|
|
2517
2667
|
* @param {value} value value used for filtering
|
|
2518
|
-
* @return {SearchParameters}
|
|
2668
|
+
* @return {SearchParameters} new instance
|
|
2519
2669
|
*/
|
|
2520
|
-
toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
|
|
2670
|
+
toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
|
|
2671
|
+
facet,
|
|
2672
|
+
value
|
|
2673
|
+
) {
|
|
2521
2674
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2522
|
-
throw new Error(
|
|
2675
|
+
throw new Error(
|
|
2676
|
+
facet +
|
|
2677
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2678
|
+
);
|
|
2523
2679
|
}
|
|
2524
2680
|
|
|
2525
2681
|
return this.setQueryParameters({
|
|
2526
|
-
facetsExcludes: RefinementList.toggleRefinement(
|
|
2682
|
+
facetsExcludes: RefinementList.toggleRefinement(
|
|
2683
|
+
this.facetsExcludes,
|
|
2684
|
+
facet,
|
|
2685
|
+
value
|
|
2686
|
+
),
|
|
2527
2687
|
});
|
|
2528
2688
|
},
|
|
2529
2689
|
/**
|
|
@@ -2531,17 +2691,25 @@
|
|
|
2531
2691
|
* @method
|
|
2532
2692
|
* @param {string} facet name of the attribute used for faceting
|
|
2533
2693
|
* @param {value} value value used for filtering
|
|
2534
|
-
* @return {SearchParameters}
|
|
2694
|
+
* @return {SearchParameters} new instance
|
|
2535
2695
|
*/
|
|
2536
|
-
toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
|
|
2696
|
+
toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
|
|
2697
|
+
facet,
|
|
2698
|
+
value
|
|
2699
|
+
) {
|
|
2537
2700
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2538
2701
|
throw new Error(
|
|
2539
|
-
facet +
|
|
2702
|
+
facet +
|
|
2703
|
+
' is not defined in the disjunctiveFacets attribute of the helper configuration'
|
|
2704
|
+
);
|
|
2540
2705
|
}
|
|
2541
2706
|
|
|
2542
2707
|
return this.setQueryParameters({
|
|
2543
2708
|
disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
|
|
2544
|
-
this.disjunctiveFacetsRefinements,
|
|
2709
|
+
this.disjunctiveFacetsRefinements,
|
|
2710
|
+
facet,
|
|
2711
|
+
value
|
|
2712
|
+
),
|
|
2545
2713
|
});
|
|
2546
2714
|
},
|
|
2547
2715
|
/**
|
|
@@ -2549,29 +2717,38 @@
|
|
|
2549
2717
|
* @method
|
|
2550
2718
|
* @param {string} facet name of the attribute used for faceting
|
|
2551
2719
|
* @param {value} value value used for filtering
|
|
2552
|
-
* @return {SearchParameters}
|
|
2720
|
+
* @return {SearchParameters} new instance
|
|
2553
2721
|
*/
|
|
2554
|
-
toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
|
|
2722
|
+
toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
|
|
2723
|
+
facet,
|
|
2724
|
+
value
|
|
2725
|
+
) {
|
|
2555
2726
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2556
2727
|
throw new Error(
|
|
2557
|
-
facet +
|
|
2728
|
+
facet +
|
|
2729
|
+
' is not defined in the hierarchicalFacets attribute of the helper configuration'
|
|
2730
|
+
);
|
|
2558
2731
|
}
|
|
2559
2732
|
|
|
2560
|
-
var separator = this._getHierarchicalFacetSeparator(
|
|
2733
|
+
var separator = this._getHierarchicalFacetSeparator(
|
|
2734
|
+
this.getHierarchicalFacetByName(facet)
|
|
2735
|
+
);
|
|
2561
2736
|
|
|
2562
2737
|
var mod = {};
|
|
2563
2738
|
|
|
2564
|
-
var upOneOrMultipleLevel =
|
|
2565
|
-
this.hierarchicalFacetsRefinements[facet]
|
|
2739
|
+
var upOneOrMultipleLevel =
|
|
2740
|
+
this.hierarchicalFacetsRefinements[facet] !== undefined &&
|
|
2741
|
+
this.hierarchicalFacetsRefinements[facet].length > 0 &&
|
|
2566
2742
|
// remove current refinement:
|
|
2567
2743
|
// refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
|
|
2568
|
-
this.hierarchicalFacetsRefinements[facet][0] === value ||
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2744
|
+
(this.hierarchicalFacetsRefinements[facet][0] === value ||
|
|
2745
|
+
// remove a parent refinement of the current refinement:
|
|
2746
|
+
// - refinement was 'beer > IPA > Flying dog'
|
|
2747
|
+
// - call is toggleRefine('beer > IPA')
|
|
2748
|
+
// - refinement should be `beer`
|
|
2749
|
+
this.hierarchicalFacetsRefinements[facet][0].indexOf(
|
|
2750
|
+
value + separator
|
|
2751
|
+
) === 0);
|
|
2575
2752
|
|
|
2576
2753
|
if (upOneOrMultipleLevel) {
|
|
2577
2754
|
if (value.indexOf(separator) === -1) {
|
|
@@ -2585,7 +2762,11 @@
|
|
|
2585
2762
|
}
|
|
2586
2763
|
|
|
2587
2764
|
return this.setQueryParameters({
|
|
2588
|
-
hierarchicalFacetsRefinements: defaultsPure(
|
|
2765
|
+
hierarchicalFacetsRefinements: defaultsPure(
|
|
2766
|
+
{},
|
|
2767
|
+
mod,
|
|
2768
|
+
this.hierarchicalFacetsRefinements
|
|
2769
|
+
),
|
|
2589
2770
|
});
|
|
2590
2771
|
},
|
|
2591
2772
|
|
|
@@ -2596,17 +2777,24 @@
|
|
|
2596
2777
|
* @return {SearchParameter} the new state
|
|
2597
2778
|
* @throws Error if the facet is not defined or if the facet is refined
|
|
2598
2779
|
*/
|
|
2599
|
-
addHierarchicalFacetRefinement: function(facet, path) {
|
|
2780
|
+
addHierarchicalFacetRefinement: function (facet, path) {
|
|
2600
2781
|
if (this.isHierarchicalFacetRefined(facet)) {
|
|
2601
2782
|
throw new Error(facet + ' is already refined.');
|
|
2602
2783
|
}
|
|
2603
2784
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2604
|
-
throw new Error(
|
|
2785
|
+
throw new Error(
|
|
2786
|
+
facet +
|
|
2787
|
+
' is not defined in the hierarchicalFacets attribute of the helper configuration.'
|
|
2788
|
+
);
|
|
2605
2789
|
}
|
|
2606
2790
|
var mod = {};
|
|
2607
2791
|
mod[facet] = [path];
|
|
2608
2792
|
return this.setQueryParameters({
|
|
2609
|
-
hierarchicalFacetsRefinements: defaultsPure(
|
|
2793
|
+
hierarchicalFacetsRefinements: defaultsPure(
|
|
2794
|
+
{},
|
|
2795
|
+
mod,
|
|
2796
|
+
this.hierarchicalFacetsRefinements
|
|
2797
|
+
),
|
|
2610
2798
|
});
|
|
2611
2799
|
},
|
|
2612
2800
|
|
|
@@ -2616,21 +2804,25 @@
|
|
|
2616
2804
|
* @return {SearchParameter} the new state
|
|
2617
2805
|
* @throws Error if the facet is not defined or if the facet is not refined
|
|
2618
2806
|
*/
|
|
2619
|
-
removeHierarchicalFacetRefinement: function(facet) {
|
|
2807
|
+
removeHierarchicalFacetRefinement: function (facet) {
|
|
2620
2808
|
if (!this.isHierarchicalFacetRefined(facet)) {
|
|
2621
2809
|
return this;
|
|
2622
2810
|
}
|
|
2623
2811
|
var mod = {};
|
|
2624
2812
|
mod[facet] = [];
|
|
2625
2813
|
return this.setQueryParameters({
|
|
2626
|
-
hierarchicalFacetsRefinements: defaultsPure(
|
|
2814
|
+
hierarchicalFacetsRefinements: defaultsPure(
|
|
2815
|
+
{},
|
|
2816
|
+
mod,
|
|
2817
|
+
this.hierarchicalFacetsRefinements
|
|
2818
|
+
),
|
|
2627
2819
|
});
|
|
2628
2820
|
},
|
|
2629
2821
|
/**
|
|
2630
2822
|
* Switch the tag refinement
|
|
2631
2823
|
* @method
|
|
2632
2824
|
* @param {string} tag the tag to remove or add
|
|
2633
|
-
* @return {SearchParameters}
|
|
2825
|
+
* @return {SearchParameters} new instance
|
|
2634
2826
|
*/
|
|
2635
2827
|
toggleTagRefinement: function toggleTagRefinement(tag) {
|
|
2636
2828
|
if (this.isTagRefined(tag)) {
|
|
@@ -2643,27 +2835,27 @@
|
|
|
2643
2835
|
* Test if the facet name is from one of the disjunctive facets
|
|
2644
2836
|
* @method
|
|
2645
2837
|
* @param {string} facet facet name to test
|
|
2646
|
-
* @return {boolean}
|
|
2838
|
+
* @return {boolean} true if facet is a disjunctive facet
|
|
2647
2839
|
*/
|
|
2648
|
-
isDisjunctiveFacet: function(facet) {
|
|
2840
|
+
isDisjunctiveFacet: function (facet) {
|
|
2649
2841
|
return this.disjunctiveFacets.indexOf(facet) > -1;
|
|
2650
2842
|
},
|
|
2651
2843
|
/**
|
|
2652
2844
|
* Test if the facet name is from one of the hierarchical facets
|
|
2653
2845
|
* @method
|
|
2654
2846
|
* @param {string} facetName facet name to test
|
|
2655
|
-
* @return {boolean}
|
|
2847
|
+
* @return {boolean} true if facetName is a hierarchical facet
|
|
2656
2848
|
*/
|
|
2657
|
-
isHierarchicalFacet: function(facetName) {
|
|
2849
|
+
isHierarchicalFacet: function (facetName) {
|
|
2658
2850
|
return this.getHierarchicalFacetByName(facetName) !== undefined;
|
|
2659
2851
|
},
|
|
2660
2852
|
/**
|
|
2661
2853
|
* Test if the facet name is from one of the conjunctive/normal facets
|
|
2662
2854
|
* @method
|
|
2663
2855
|
* @param {string} facet facet name to test
|
|
2664
|
-
* @return {boolean}
|
|
2856
|
+
* @return {boolean} true if facet is a conjunctive facet
|
|
2665
2857
|
*/
|
|
2666
|
-
isConjunctiveFacet: function(facet) {
|
|
2858
|
+
isConjunctiveFacet: function (facet) {
|
|
2667
2859
|
return this.facets.indexOf(facet) > -1;
|
|
2668
2860
|
},
|
|
2669
2861
|
/**
|
|
@@ -2704,13 +2896,17 @@
|
|
|
2704
2896
|
* @param {string} facet name of the attribute for used for faceting
|
|
2705
2897
|
* @param {string} value optional, will test if the value is used for refinement
|
|
2706
2898
|
* if there is one, otherwise will test if the facet contains any refinement
|
|
2707
|
-
* @return {boolean}
|
|
2899
|
+
* @return {boolean} true if the facet is refined
|
|
2708
2900
|
*/
|
|
2709
2901
|
isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
|
|
2710
2902
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2711
2903
|
return false;
|
|
2712
2904
|
}
|
|
2713
|
-
return RefinementList.isRefined(
|
|
2905
|
+
return RefinementList.isRefined(
|
|
2906
|
+
this.disjunctiveFacetsRefinements,
|
|
2907
|
+
facet,
|
|
2908
|
+
value
|
|
2909
|
+
);
|
|
2714
2910
|
},
|
|
2715
2911
|
/**
|
|
2716
2912
|
* Returns true if the facet contains a refinement, or if a value passed is a
|
|
@@ -2719,9 +2915,12 @@
|
|
|
2719
2915
|
* @param {string} facet name of the attribute for used for faceting
|
|
2720
2916
|
* @param {string} value optional, will test if the value is used for refinement
|
|
2721
2917
|
* if there is one, otherwise will test if the facet contains any refinement
|
|
2722
|
-
* @return {boolean}
|
|
2918
|
+
* @return {boolean} true if the facet is refined
|
|
2723
2919
|
*/
|
|
2724
|
-
isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
|
|
2920
|
+
isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
|
|
2921
|
+
facet,
|
|
2922
|
+
value
|
|
2923
|
+
) {
|
|
2725
2924
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2726
2925
|
return false;
|
|
2727
2926
|
}
|
|
@@ -2746,7 +2945,7 @@
|
|
|
2746
2945
|
*/
|
|
2747
2946
|
isNumericRefined: function isNumericRefined(attribute, operator, value) {
|
|
2748
2947
|
if (value === undefined && operator === undefined) {
|
|
2749
|
-
return
|
|
2948
|
+
return Boolean(this.numericRefinements[attribute]);
|
|
2750
2949
|
}
|
|
2751
2950
|
|
|
2752
2951
|
var isOperatorDefined =
|
|
@@ -2768,7 +2967,7 @@
|
|
|
2768
2967
|
* Returns true if the tag refined, false otherwise
|
|
2769
2968
|
* @method
|
|
2770
2969
|
* @param {string} tag the tag to check
|
|
2771
|
-
* @return {boolean}
|
|
2970
|
+
* @return {boolean} true if tag is refined
|
|
2772
2971
|
*/
|
|
2773
2972
|
isTagRefined: function isTagRefined(tag) {
|
|
2774
2973
|
return this.tagRefinements.indexOf(tag) !== -1;
|
|
@@ -2778,22 +2977,24 @@
|
|
|
2778
2977
|
* @method
|
|
2779
2978
|
* @param {string} facet name of the attribute used for faceting
|
|
2780
2979
|
* @param {value} value value used for filtering
|
|
2781
|
-
* @return {string[]}
|
|
2980
|
+
* @return {string[]} returns the list of refinements
|
|
2782
2981
|
*/
|
|
2783
2982
|
getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
|
|
2983
|
+
// eslint-disable-next-line consistent-this
|
|
2784
2984
|
var self = this;
|
|
2785
2985
|
|
|
2786
2986
|
// attributes used for numeric filter can also be disjunctive
|
|
2787
2987
|
var disjunctiveNumericRefinedFacets = intersection_1(
|
|
2788
|
-
Object.keys(this.numericRefinements).filter(function(facet) {
|
|
2988
|
+
Object.keys(this.numericRefinements).filter(function (facet) {
|
|
2789
2989
|
return Object.keys(self.numericRefinements[facet]).length > 0;
|
|
2790
2990
|
}),
|
|
2791
2991
|
this.disjunctiveFacets
|
|
2792
2992
|
);
|
|
2793
2993
|
|
|
2794
|
-
return Object.keys(this.disjunctiveFacetsRefinements)
|
|
2795
|
-
|
|
2796
|
-
|
|
2994
|
+
return Object.keys(this.disjunctiveFacetsRefinements)
|
|
2995
|
+
.filter(function (facet) {
|
|
2996
|
+
return self.disjunctiveFacetsRefinements[facet].length > 0;
|
|
2997
|
+
})
|
|
2797
2998
|
.concat(disjunctiveNumericRefinedFacets)
|
|
2798
2999
|
.concat(this.getRefinedHierarchicalFacets());
|
|
2799
3000
|
},
|
|
@@ -2802,15 +3003,18 @@
|
|
|
2802
3003
|
* @method
|
|
2803
3004
|
* @param {string} facet name of the attribute used for faceting
|
|
2804
3005
|
* @param {value} value value used for filtering
|
|
2805
|
-
* @return {string[]}
|
|
3006
|
+
* @return {string[]} returns the list of refinements
|
|
2806
3007
|
*/
|
|
2807
3008
|
getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
|
|
3009
|
+
// eslint-disable-next-line consistent-this
|
|
2808
3010
|
var self = this;
|
|
2809
3011
|
return intersection_1(
|
|
2810
3012
|
// enforce the order between the two arrays,
|
|
2811
3013
|
// so that refinement name index === hierarchical facet index
|
|
2812
|
-
this.hierarchicalFacets.map(function(facet) {
|
|
2813
|
-
|
|
3014
|
+
this.hierarchicalFacets.map(function (facet) {
|
|
3015
|
+
return facet.name;
|
|
3016
|
+
}),
|
|
3017
|
+
Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
|
|
2814
3018
|
return self.hierarchicalFacetsRefinements[facet].length > 0;
|
|
2815
3019
|
})
|
|
2816
3020
|
);
|
|
@@ -2818,12 +3022,12 @@
|
|
|
2818
3022
|
/**
|
|
2819
3023
|
* Returned the list of all disjunctive facets not refined
|
|
2820
3024
|
* @method
|
|
2821
|
-
* @return {string[]}
|
|
3025
|
+
* @return {string[]} returns the list of facets that are not refined
|
|
2822
3026
|
*/
|
|
2823
|
-
getUnrefinedDisjunctiveFacets: function() {
|
|
3027
|
+
getUnrefinedDisjunctiveFacets: function () {
|
|
2824
3028
|
var refinedFacets = this.getRefinedDisjunctiveFacets();
|
|
2825
3029
|
|
|
2826
|
-
return this.disjunctiveFacets.filter(function(f) {
|
|
3030
|
+
return this.disjunctiveFacets.filter(function (f) {
|
|
2827
3031
|
return refinedFacets.indexOf(f) === -1;
|
|
2828
3032
|
});
|
|
2829
3033
|
},
|
|
@@ -2840,17 +3044,22 @@
|
|
|
2840
3044
|
'disjunctiveFacetsRefinements',
|
|
2841
3045
|
'numericRefinements',
|
|
2842
3046
|
'tagRefinements',
|
|
2843
|
-
'hierarchicalFacetsRefinements'
|
|
3047
|
+
'hierarchicalFacetsRefinements',
|
|
2844
3048
|
],
|
|
3049
|
+
|
|
2845
3050
|
getQueryParams: function getQueryParams() {
|
|
2846
3051
|
var managedParameters = this.managedParameters;
|
|
2847
3052
|
|
|
2848
3053
|
var queryParams = {};
|
|
2849
3054
|
|
|
3055
|
+
// eslint-disable-next-line consistent-this
|
|
2850
3056
|
var self = this;
|
|
2851
|
-
Object.keys(this).forEach(function(paramName) {
|
|
3057
|
+
Object.keys(this).forEach(function (paramName) {
|
|
2852
3058
|
var paramValue = self[paramName];
|
|
2853
|
-
if (
|
|
3059
|
+
if (
|
|
3060
|
+
managedParameters.indexOf(paramName) === -1 &&
|
|
3061
|
+
paramValue !== undefined
|
|
3062
|
+
) {
|
|
2854
3063
|
queryParams[paramName] = paramValue;
|
|
2855
3064
|
}
|
|
2856
3065
|
});
|
|
@@ -2891,30 +3100,32 @@
|
|
|
2891
3100
|
throw error;
|
|
2892
3101
|
}
|
|
2893
3102
|
|
|
3103
|
+
// eslint-disable-next-line consistent-this
|
|
2894
3104
|
var self = this;
|
|
2895
3105
|
var nextWithNumbers = SearchParameters._parseNumbers(params);
|
|
2896
|
-
var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
|
|
3106
|
+
var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
|
|
2897
3107
|
acc[key] = self[key];
|
|
2898
3108
|
return acc;
|
|
2899
3109
|
}, {});
|
|
2900
3110
|
|
|
2901
|
-
var nextPlainObject = Object.keys(nextWithNumbers).reduce(
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
3111
|
+
var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (
|
|
3112
|
+
previous,
|
|
3113
|
+
key
|
|
3114
|
+
) {
|
|
3115
|
+
var isPreviousValueDefined = previous[key] !== undefined;
|
|
3116
|
+
var isNextValueDefined = nextWithNumbers[key] !== undefined;
|
|
2905
3117
|
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
3118
|
+
if (isPreviousValueDefined && !isNextValueDefined) {
|
|
3119
|
+
return omit$1(previous, [key]);
|
|
3120
|
+
}
|
|
2909
3121
|
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
3122
|
+
if (isNextValueDefined) {
|
|
3123
|
+
previous[key] = nextWithNumbers[key];
|
|
3124
|
+
}
|
|
2913
3125
|
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
);
|
|
3126
|
+
return previous;
|
|
3127
|
+
},
|
|
3128
|
+
previousPlainObject);
|
|
2918
3129
|
|
|
2919
3130
|
return new this.constructor(nextPlainObject);
|
|
2920
3131
|
},
|
|
@@ -2925,7 +3136,7 @@
|
|
|
2925
3136
|
* the page is set -> return a new instance with a page of 0
|
|
2926
3137
|
* @return {SearchParameters} a new updated instance
|
|
2927
3138
|
*/
|
|
2928
|
-
resetPage: function() {
|
|
3139
|
+
resetPage: function () {
|
|
2929
3140
|
if (this.page === undefined) {
|
|
2930
3141
|
return this;
|
|
2931
3142
|
}
|
|
@@ -2935,40 +3146,40 @@
|
|
|
2935
3146
|
|
|
2936
3147
|
/**
|
|
2937
3148
|
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
|
|
2938
|
-
* @param {object} hierarchicalFacet
|
|
3149
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2939
3150
|
* @return {string} returns the hierarchicalFacet.separator or `>` as default
|
|
2940
3151
|
*/
|
|
2941
|
-
_getHierarchicalFacetSortBy: function(hierarchicalFacet) {
|
|
3152
|
+
_getHierarchicalFacetSortBy: function (hierarchicalFacet) {
|
|
2942
3153
|
return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
|
|
2943
3154
|
},
|
|
2944
3155
|
|
|
2945
3156
|
/**
|
|
2946
3157
|
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
|
|
2947
3158
|
* @private
|
|
2948
|
-
* @param {object} hierarchicalFacet
|
|
3159
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2949
3160
|
* @return {string} returns the hierarchicalFacet.separator or `>` as default
|
|
2950
3161
|
*/
|
|
2951
|
-
_getHierarchicalFacetSeparator: function(hierarchicalFacet) {
|
|
3162
|
+
_getHierarchicalFacetSeparator: function (hierarchicalFacet) {
|
|
2952
3163
|
return hierarchicalFacet.separator || ' > ';
|
|
2953
3164
|
},
|
|
2954
3165
|
|
|
2955
3166
|
/**
|
|
2956
3167
|
* Helper function to get the hierarchicalFacet prefix path or null
|
|
2957
3168
|
* @private
|
|
2958
|
-
* @param {object} hierarchicalFacet
|
|
3169
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2959
3170
|
* @return {string} returns the hierarchicalFacet.rootPath or null as default
|
|
2960
3171
|
*/
|
|
2961
|
-
_getHierarchicalRootPath: function(hierarchicalFacet) {
|
|
3172
|
+
_getHierarchicalRootPath: function (hierarchicalFacet) {
|
|
2962
3173
|
return hierarchicalFacet.rootPath || null;
|
|
2963
3174
|
},
|
|
2964
3175
|
|
|
2965
3176
|
/**
|
|
2966
3177
|
* Helper function to check if we show the parent level of the hierarchicalFacet
|
|
2967
3178
|
* @private
|
|
2968
|
-
* @param {object} hierarchicalFacet
|
|
3179
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2969
3180
|
* @return {string} returns the hierarchicalFacet.showParentLevel or true as default
|
|
2970
3181
|
*/
|
|
2971
|
-
_getHierarchicalShowParentLevel: function(hierarchicalFacet) {
|
|
3182
|
+
_getHierarchicalShowParentLevel: function (hierarchicalFacet) {
|
|
2972
3183
|
if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
|
|
2973
3184
|
return hierarchicalFacet.showParentLevel;
|
|
2974
3185
|
}
|
|
@@ -2977,16 +3188,13 @@
|
|
|
2977
3188
|
|
|
2978
3189
|
/**
|
|
2979
3190
|
* Helper function to get the hierarchicalFacet by it's name
|
|
2980
|
-
* @param {string} hierarchicalFacetName
|
|
3191
|
+
* @param {string} hierarchicalFacetName the hierarchicalFacet name
|
|
2981
3192
|
* @return {object} a hierarchicalFacet
|
|
2982
3193
|
*/
|
|
2983
|
-
getHierarchicalFacetByName: function(hierarchicalFacetName) {
|
|
2984
|
-
return find$1(
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
return f.name === hierarchicalFacetName;
|
|
2988
|
-
}
|
|
2989
|
-
);
|
|
3194
|
+
getHierarchicalFacetByName: function (hierarchicalFacetName) {
|
|
3195
|
+
return find$1(this.hierarchicalFacets, function (f) {
|
|
3196
|
+
return f.name === hierarchicalFacetName;
|
|
3197
|
+
});
|
|
2990
3198
|
},
|
|
2991
3199
|
|
|
2992
3200
|
/**
|
|
@@ -2994,7 +3202,7 @@
|
|
|
2994
3202
|
* @param {string} facetName Hierarchical facet name
|
|
2995
3203
|
* @return {array.<string>} the path as an array of string
|
|
2996
3204
|
*/
|
|
2997
|
-
getHierarchicalFacetBreadcrumb: function(facetName) {
|
|
3205
|
+
getHierarchicalFacetBreadcrumb: function (facetName) {
|
|
2998
3206
|
if (!this.isHierarchicalFacet(facetName)) {
|
|
2999
3207
|
return [];
|
|
3000
3208
|
}
|
|
@@ -3006,14 +3214,14 @@
|
|
|
3006
3214
|
this.getHierarchicalFacetByName(facetName)
|
|
3007
3215
|
);
|
|
3008
3216
|
var path = refinement.split(separator);
|
|
3009
|
-
return path.map(function(part) {
|
|
3217
|
+
return path.map(function (part) {
|
|
3010
3218
|
return part.trim();
|
|
3011
3219
|
});
|
|
3012
3220
|
},
|
|
3013
3221
|
|
|
3014
|
-
toString: function() {
|
|
3222
|
+
toString: function () {
|
|
3015
3223
|
return JSON.stringify(this, null, 2);
|
|
3016
|
-
}
|
|
3224
|
+
},
|
|
3017
3225
|
};
|
|
3018
3226
|
|
|
3019
3227
|
/**
|
|
@@ -3057,6 +3265,7 @@
|
|
|
3057
3265
|
* @param {Array<object>} collection object with keys in attributes
|
|
3058
3266
|
* @param {Array<string>} iteratees attributes
|
|
3059
3267
|
* @param {Array<string>} orders asc | desc
|
|
3268
|
+
* @return {Array<object>} sorted collection
|
|
3060
3269
|
*/
|
|
3061
3270
|
function orderBy(collection, iteratees, orders) {
|
|
3062
3271
|
if (!Array.isArray(collection)) {
|
|
@@ -3067,13 +3276,13 @@
|
|
|
3067
3276
|
orders = [];
|
|
3068
3277
|
}
|
|
3069
3278
|
|
|
3070
|
-
var result = collection.map(function(value, index) {
|
|
3279
|
+
var result = collection.map(function (value, index) {
|
|
3071
3280
|
return {
|
|
3072
|
-
criteria: iteratees.map(function(iteratee) {
|
|
3281
|
+
criteria: iteratees.map(function (iteratee) {
|
|
3073
3282
|
return value[iteratee];
|
|
3074
3283
|
}),
|
|
3075
3284
|
index: index,
|
|
3076
|
-
value: value
|
|
3285
|
+
value: value,
|
|
3077
3286
|
};
|
|
3078
3287
|
});
|
|
3079
3288
|
|
|
@@ -3098,7 +3307,7 @@
|
|
|
3098
3307
|
return object.index - other.index;
|
|
3099
3308
|
});
|
|
3100
3309
|
|
|
3101
|
-
return result.map(function(res) {
|
|
3310
|
+
return result.map(function (res) {
|
|
3102
3311
|
return res.value;
|
|
3103
3312
|
});
|
|
3104
3313
|
}
|
|
@@ -3134,7 +3343,7 @@
|
|
|
3134
3343
|
* @return {array.<string[]>} array containing 2 elements : attributes, orders
|
|
3135
3344
|
*/
|
|
3136
3345
|
var formatSort = function formatSort(sortBy, defaults) {
|
|
3137
|
-
var defaultInstructions = (defaults || []).map(function(sort) {
|
|
3346
|
+
var defaultInstructions = (defaults || []).map(function (sort) {
|
|
3138
3347
|
return sort.split(':');
|
|
3139
3348
|
});
|
|
3140
3349
|
|
|
@@ -3142,11 +3351,12 @@
|
|
|
3142
3351
|
function preparePredicate(out, sort) {
|
|
3143
3352
|
var sortInstruction = sort.split(':');
|
|
3144
3353
|
|
|
3145
|
-
var matchingDefault = find$1(
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3354
|
+
var matchingDefault = find$1(
|
|
3355
|
+
defaultInstructions,
|
|
3356
|
+
function (defaultInstruction) {
|
|
3357
|
+
return defaultInstruction[0] === sortInstruction[0];
|
|
3358
|
+
}
|
|
3359
|
+
);
|
|
3150
3360
|
|
|
3151
3361
|
if (sortInstruction.length > 1 || !matchingDefault) {
|
|
3152
3362
|
out[0].push(sortInstruction[0]);
|
|
@@ -3166,7 +3376,7 @@
|
|
|
3166
3376
|
* Replaces a leading - with \-
|
|
3167
3377
|
* @private
|
|
3168
3378
|
* @param {any} value the facet value to replace
|
|
3169
|
-
* @returns any
|
|
3379
|
+
* @returns {any} the escaped facet value or the value if it was not a string
|
|
3170
3380
|
*/
|
|
3171
3381
|
function escapeFacetValue(value) {
|
|
3172
3382
|
if (typeof value !== 'string') return value;
|
|
@@ -3178,7 +3388,7 @@
|
|
|
3178
3388
|
* Replaces a leading \- with -
|
|
3179
3389
|
* @private
|
|
3180
3390
|
* @param {any} value the escaped facet value
|
|
3181
|
-
* @returns any
|
|
3391
|
+
* @returns {any} the unescaped facet value or the value if it was not a string
|
|
3182
3392
|
*/
|
|
3183
3393
|
function unescapeFacetValue$1(value) {
|
|
3184
3394
|
if (typeof value !== 'string') return value;
|
|
@@ -3188,7 +3398,7 @@
|
|
|
3188
3398
|
|
|
3189
3399
|
var escapeFacetValue_1 = {
|
|
3190
3400
|
escapeFacetValue: escapeFacetValue,
|
|
3191
|
-
unescapeFacetValue: unescapeFacetValue$1
|
|
3401
|
+
unescapeFacetValue: unescapeFacetValue$1,
|
|
3192
3402
|
};
|
|
3193
3403
|
|
|
3194
3404
|
var generateHierarchicalTree_1 = generateTrees;
|
|
@@ -3207,20 +3417,17 @@
|
|
|
3207
3417
|
(state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
|
|
3208
3418
|
state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
|
|
3209
3419
|
'';
|
|
3210
|
-
var hierarchicalSeparator =
|
|
3211
|
-
hierarchicalFacet
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
|
|
3217
|
-
hierarchicalFacet
|
|
3218
|
-
);
|
|
3420
|
+
var hierarchicalSeparator =
|
|
3421
|
+
state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
3422
|
+
var hierarchicalRootPath =
|
|
3423
|
+
state._getHierarchicalRootPath(hierarchicalFacet);
|
|
3424
|
+
var hierarchicalShowParentLevel =
|
|
3425
|
+
state._getHierarchicalShowParentLevel(hierarchicalFacet);
|
|
3219
3426
|
var sortBy = formatSort(
|
|
3220
3427
|
state._getHierarchicalFacetSortBy(hierarchicalFacet)
|
|
3221
3428
|
);
|
|
3222
3429
|
|
|
3223
|
-
var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
|
|
3430
|
+
var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
|
|
3224
3431
|
return facetResult.exhaustive;
|
|
3225
3432
|
});
|
|
3226
3433
|
|
|
@@ -3247,7 +3454,7 @@
|
|
|
3247
3454
|
path: null, // root level, no path
|
|
3248
3455
|
escapedValue: null,
|
|
3249
3456
|
exhaustive: rootExhaustive,
|
|
3250
|
-
data: null
|
|
3457
|
+
data: null,
|
|
3251
3458
|
});
|
|
3252
3459
|
};
|
|
3253
3460
|
}
|
|
@@ -3276,7 +3483,7 @@
|
|
|
3276
3483
|
* @type {object[]]} hierarchical data
|
|
3277
3484
|
*/
|
|
3278
3485
|
var data = parent && Array.isArray(parent.data) ? parent.data : [];
|
|
3279
|
-
parent = find$1(data, function(subtree) {
|
|
3486
|
+
parent = find$1(data, function (subtree) {
|
|
3280
3487
|
return subtree.isRefined;
|
|
3281
3488
|
});
|
|
3282
3489
|
level++;
|
|
@@ -3297,10 +3504,10 @@
|
|
|
3297
3504
|
// showing up
|
|
3298
3505
|
|
|
3299
3506
|
var picked = Object.keys(hierarchicalFacetResult.data)
|
|
3300
|
-
.map(function(facetValue) {
|
|
3507
|
+
.map(function (facetValue) {
|
|
3301
3508
|
return [facetValue, hierarchicalFacetResult.data[facetValue]];
|
|
3302
3509
|
})
|
|
3303
|
-
.filter(function(tuple) {
|
|
3510
|
+
.filter(function (tuple) {
|
|
3304
3511
|
var facetValue = tuple[0];
|
|
3305
3512
|
return onlyMatchingTree(
|
|
3306
3513
|
facetValue,
|
|
@@ -3313,7 +3520,7 @@
|
|
|
3313
3520
|
});
|
|
3314
3521
|
|
|
3315
3522
|
parent.data = orderBy_1(
|
|
3316
|
-
picked.map(function(tuple) {
|
|
3523
|
+
picked.map(function (tuple) {
|
|
3317
3524
|
var facetValue = tuple[0];
|
|
3318
3525
|
var facetCount = tuple[1];
|
|
3319
3526
|
|
|
@@ -3334,6 +3541,7 @@
|
|
|
3334
3541
|
};
|
|
3335
3542
|
}
|
|
3336
3543
|
|
|
3544
|
+
// eslint-disable-next-line max-params
|
|
3337
3545
|
function onlyMatchingTree(
|
|
3338
3546
|
facetValue,
|
|
3339
3547
|
parentPath,
|
|
@@ -3390,7 +3598,7 @@
|
|
|
3390
3598
|
currentRefinement === facetValue ||
|
|
3391
3599
|
currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
|
|
3392
3600
|
exhaustive: exhaustive,
|
|
3393
|
-
data: null
|
|
3601
|
+
data: null,
|
|
3394
3602
|
};
|
|
3395
3603
|
}
|
|
3396
3604
|
|
|
@@ -3441,12 +3649,14 @@
|
|
|
3441
3649
|
*/
|
|
3442
3650
|
|
|
3443
3651
|
/**
|
|
3444
|
-
*
|
|
3652
|
+
* Turn an array of attributes in an object of attributes with their position in the array as value
|
|
3653
|
+
* @param {string[]} attributes the list of attributes in the record
|
|
3654
|
+
* @return {object} the list of attributes indexed by attribute name
|
|
3445
3655
|
*/
|
|
3446
3656
|
function getIndices(attributes) {
|
|
3447
3657
|
var indices = {};
|
|
3448
3658
|
|
|
3449
|
-
attributes.forEach(function(val, idx) {
|
|
3659
|
+
attributes.forEach(function (val, idx) {
|
|
3450
3660
|
indices[val] = idx;
|
|
3451
3661
|
});
|
|
3452
3662
|
|
|
@@ -3466,22 +3676,24 @@
|
|
|
3466
3676
|
*/
|
|
3467
3677
|
|
|
3468
3678
|
/**
|
|
3469
|
-
* @param {HierarchicalFacet[]} hierarchicalFacets
|
|
3470
|
-
* @param {string} hierarchicalAttributeName
|
|
3679
|
+
* @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
|
|
3680
|
+
* @param {string} hierarchicalAttributeName The name of the hierarchical attribute
|
|
3681
|
+
* @return {HierarchicalFacet} The hierarchical facet matching the attribute name
|
|
3471
3682
|
*/
|
|
3472
3683
|
function findMatchingHierarchicalFacetFromAttributeName(
|
|
3473
3684
|
hierarchicalFacets,
|
|
3474
3685
|
hierarchicalAttributeName
|
|
3475
3686
|
) {
|
|
3476
|
-
return find$1(
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3687
|
+
return find$1(
|
|
3688
|
+
hierarchicalFacets,
|
|
3689
|
+
function facetKeyMatchesAttribute(hierarchicalFacet) {
|
|
3690
|
+
var facetNames = hierarchicalFacet.attributes || [];
|
|
3691
|
+
return facetNames.indexOf(hierarchicalAttributeName) > -1;
|
|
3692
|
+
}
|
|
3693
|
+
);
|
|
3482
3694
|
}
|
|
3483
3695
|
|
|
3484
|
-
|
|
3696
|
+
// eslint-disable-next-line valid-jsdoc
|
|
3485
3697
|
/**
|
|
3486
3698
|
* Constructor for SearchResults
|
|
3487
3699
|
* @class
|
|
@@ -3612,21 +3824,21 @@
|
|
|
3612
3824
|
"index": "bestbuy"
|
|
3613
3825
|
}
|
|
3614
3826
|
**/
|
|
3615
|
-
/*eslint-enable */
|
|
3616
3827
|
function SearchResults(state, results, options) {
|
|
3617
3828
|
var mainSubResponse = results[0];
|
|
3618
3829
|
|
|
3619
3830
|
this._rawResults = results;
|
|
3620
3831
|
|
|
3832
|
+
// eslint-disable-next-line consistent-this
|
|
3621
3833
|
var self = this;
|
|
3622
3834
|
|
|
3623
3835
|
// https://www.algolia.com/doc/api-reference/api-methods/search/#response
|
|
3624
|
-
Object.keys(mainSubResponse).forEach(function(key) {
|
|
3836
|
+
Object.keys(mainSubResponse).forEach(function (key) {
|
|
3625
3837
|
self[key] = mainSubResponse[key];
|
|
3626
3838
|
});
|
|
3627
3839
|
|
|
3628
3840
|
// Make every key of the result options reachable from the instance
|
|
3629
|
-
Object.keys(options || {}).forEach(function(key) {
|
|
3841
|
+
Object.keys(options || {}).forEach(function (key) {
|
|
3630
3842
|
self[key] = options[key];
|
|
3631
3843
|
});
|
|
3632
3844
|
|
|
@@ -3648,8 +3860,8 @@
|
|
|
3648
3860
|
* all the records that match the search parameters. Each record is
|
|
3649
3861
|
* augmented with a new attribute `_highlightResult`
|
|
3650
3862
|
* which is an object keyed by attribute and with the following properties:
|
|
3651
|
-
*
|
|
3652
|
-
*
|
|
3863
|
+
* - `value` : the value of the facet highlighted (html)
|
|
3864
|
+
* - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
|
|
3653
3865
|
* @name hits
|
|
3654
3866
|
* @member {object[]}
|
|
3655
3867
|
* @memberof SearchResults
|
|
@@ -3770,7 +3982,7 @@
|
|
|
3770
3982
|
* @memberof SearchResults
|
|
3771
3983
|
* @instance
|
|
3772
3984
|
*/
|
|
3773
|
-
this.processingTimeMS = results.reduce(function(sum, result) {
|
|
3985
|
+
this.processingTimeMS = results.reduce(function (sum, result) {
|
|
3774
3986
|
return result.processingTimeMS === undefined
|
|
3775
3987
|
? sum
|
|
3776
3988
|
: sum + result.processingTimeMS;
|
|
@@ -3785,9 +3997,11 @@
|
|
|
3785
3997
|
* disjunctive facets results
|
|
3786
3998
|
* @member {SearchResults.HierarchicalFacet[]}
|
|
3787
3999
|
*/
|
|
3788
|
-
this.hierarchicalFacets = state.hierarchicalFacets.map(
|
|
3789
|
-
|
|
3790
|
-
|
|
4000
|
+
this.hierarchicalFacets = state.hierarchicalFacets.map(
|
|
4001
|
+
function initFutureTree() {
|
|
4002
|
+
return [];
|
|
4003
|
+
}
|
|
4004
|
+
);
|
|
3791
4005
|
/**
|
|
3792
4006
|
* other facets results
|
|
3793
4007
|
* @member {SearchResults.Facet[]}
|
|
@@ -3805,7 +4019,7 @@
|
|
|
3805
4019
|
|
|
3806
4020
|
var mainFacets = mainSubResponse.facets || {};
|
|
3807
4021
|
|
|
3808
|
-
Object.keys(mainFacets).forEach(function(facetKey) {
|
|
4022
|
+
Object.keys(mainFacets).forEach(function (facetKey) {
|
|
3809
4023
|
var facetValueObject = mainFacets[facetKey];
|
|
3810
4024
|
|
|
3811
4025
|
var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
|
|
@@ -3817,13 +4031,13 @@
|
|
|
3817
4031
|
// Place the hierarchicalFacet data at the correct index depending on
|
|
3818
4032
|
// the attributes order that was defined at the helper initialization
|
|
3819
4033
|
var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
|
|
3820
|
-
var idxAttributeName = findIndex(state.hierarchicalFacets, function(f) {
|
|
4034
|
+
var idxAttributeName = findIndex(state.hierarchicalFacets, function (f) {
|
|
3821
4035
|
return f.name === hierarchicalFacet.name;
|
|
3822
4036
|
});
|
|
3823
4037
|
self.hierarchicalFacets[idxAttributeName][facetIndex] = {
|
|
3824
4038
|
attribute: facetKey,
|
|
3825
4039
|
data: facetValueObject,
|
|
3826
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4040
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3827
4041
|
};
|
|
3828
4042
|
} else {
|
|
3829
4043
|
var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
|
|
@@ -3835,18 +4049,26 @@
|
|
|
3835
4049
|
self.disjunctiveFacets[position] = {
|
|
3836
4050
|
name: facetKey,
|
|
3837
4051
|
data: facetValueObject,
|
|
3838
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4052
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3839
4053
|
};
|
|
3840
|
-
assignFacetStats(
|
|
4054
|
+
assignFacetStats(
|
|
4055
|
+
self.disjunctiveFacets[position],
|
|
4056
|
+
mainSubResponse.facets_stats,
|
|
4057
|
+
facetKey
|
|
4058
|
+
);
|
|
3841
4059
|
}
|
|
3842
4060
|
if (isFacetConjunctive) {
|
|
3843
4061
|
position = facetsIndices[facetKey];
|
|
3844
4062
|
self.facets[position] = {
|
|
3845
4063
|
name: facetKey,
|
|
3846
4064
|
data: facetValueObject,
|
|
3847
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4065
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3848
4066
|
};
|
|
3849
|
-
assignFacetStats(
|
|
4067
|
+
assignFacetStats(
|
|
4068
|
+
self.facets[position],
|
|
4069
|
+
mainSubResponse.facets_stats,
|
|
4070
|
+
facetKey
|
|
4071
|
+
);
|
|
3850
4072
|
}
|
|
3851
4073
|
}
|
|
3852
4074
|
});
|
|
@@ -3855,24 +4077,27 @@
|
|
|
3855
4077
|
this.hierarchicalFacets = compact(this.hierarchicalFacets);
|
|
3856
4078
|
|
|
3857
4079
|
// aggregate the refined disjunctive facets
|
|
3858
|
-
disjunctiveFacets.forEach(function(disjunctiveFacet) {
|
|
4080
|
+
disjunctiveFacets.forEach(function (disjunctiveFacet) {
|
|
3859
4081
|
var result = results[nextDisjunctiveResult];
|
|
3860
4082
|
var facets = result && result.facets ? result.facets : {};
|
|
3861
4083
|
var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
|
|
3862
4084
|
|
|
3863
4085
|
// There should be only item in facets.
|
|
3864
|
-
Object.keys(facets).forEach(function(dfacet) {
|
|
4086
|
+
Object.keys(facets).forEach(function (dfacet) {
|
|
3865
4087
|
var facetResults = facets[dfacet];
|
|
3866
4088
|
|
|
3867
4089
|
var position;
|
|
3868
4090
|
|
|
3869
4091
|
if (hierarchicalFacet) {
|
|
3870
|
-
position = findIndex(state.hierarchicalFacets, function(f) {
|
|
4092
|
+
position = findIndex(state.hierarchicalFacets, function (f) {
|
|
3871
4093
|
return f.name === hierarchicalFacet.name;
|
|
3872
4094
|
});
|
|
3873
|
-
var attributeIndex = findIndex(
|
|
3874
|
-
|
|
3875
|
-
|
|
4095
|
+
var attributeIndex = findIndex(
|
|
4096
|
+
self.hierarchicalFacets[position],
|
|
4097
|
+
function (f) {
|
|
4098
|
+
return f.attribute === dfacet;
|
|
4099
|
+
}
|
|
4100
|
+
);
|
|
3876
4101
|
|
|
3877
4102
|
// previous refinements and no results so not able to find it
|
|
3878
4103
|
if (attributeIndex === -1) {
|
|
@@ -3887,20 +4112,31 @@
|
|
|
3887
4112
|
} else {
|
|
3888
4113
|
position = disjunctiveFacetsIndices[dfacet];
|
|
3889
4114
|
|
|
3890
|
-
var dataFromMainRequest =
|
|
4115
|
+
var dataFromMainRequest =
|
|
4116
|
+
(mainSubResponse.facets && mainSubResponse.facets[dfacet]) || {};
|
|
3891
4117
|
|
|
3892
4118
|
self.disjunctiveFacets[position] = {
|
|
3893
4119
|
name: dfacet,
|
|
3894
4120
|
data: defaultsPure({}, facetResults, dataFromMainRequest),
|
|
3895
|
-
exhaustive: result.exhaustiveFacetsCount
|
|
4121
|
+
exhaustive: result.exhaustiveFacetsCount,
|
|
3896
4122
|
};
|
|
3897
|
-
assignFacetStats(
|
|
4123
|
+
assignFacetStats(
|
|
4124
|
+
self.disjunctiveFacets[position],
|
|
4125
|
+
result.facets_stats,
|
|
4126
|
+
dfacet
|
|
4127
|
+
);
|
|
3898
4128
|
|
|
3899
4129
|
if (state.disjunctiveFacetsRefinements[dfacet]) {
|
|
3900
|
-
state.disjunctiveFacetsRefinements[dfacet].forEach(function(
|
|
4130
|
+
state.disjunctiveFacetsRefinements[dfacet].forEach(function (
|
|
4131
|
+
refinementValue
|
|
4132
|
+
) {
|
|
3901
4133
|
// add the disjunctive refinements if it is no more retrieved
|
|
3902
|
-
if (
|
|
3903
|
-
|
|
4134
|
+
if (
|
|
4135
|
+
!self.disjunctiveFacets[position].data[refinementValue] &&
|
|
4136
|
+
state.disjunctiveFacetsRefinements[dfacet].indexOf(
|
|
4137
|
+
unescapeFacetValue$3(refinementValue)
|
|
4138
|
+
) > -1
|
|
4139
|
+
) {
|
|
3904
4140
|
self.disjunctiveFacets[position].data[refinementValue] = 0;
|
|
3905
4141
|
}
|
|
3906
4142
|
});
|
|
@@ -3911,30 +4147,34 @@
|
|
|
3911
4147
|
});
|
|
3912
4148
|
|
|
3913
4149
|
// if we have some parent level values for hierarchical facets, merge them
|
|
3914
|
-
state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
|
|
4150
|
+
state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
|
|
3915
4151
|
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
|
|
3916
4152
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
3917
4153
|
|
|
3918
4154
|
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
|
|
3919
4155
|
// if we are already at a root refinement (or no refinement at all), there is no
|
|
3920
4156
|
// root level values request
|
|
3921
|
-
if (
|
|
4157
|
+
if (
|
|
4158
|
+
currentRefinement.length === 0 ||
|
|
4159
|
+
currentRefinement[0].split(separator).length < 2
|
|
4160
|
+
) {
|
|
3922
4161
|
return;
|
|
3923
4162
|
}
|
|
3924
4163
|
|
|
3925
|
-
results.slice(nextDisjunctiveResult).forEach(function(result) {
|
|
3926
|
-
var facets = result && result.facets
|
|
3927
|
-
? result.facets
|
|
3928
|
-
: {};
|
|
4164
|
+
results.slice(nextDisjunctiveResult).forEach(function (result) {
|
|
4165
|
+
var facets = result && result.facets ? result.facets : {};
|
|
3929
4166
|
|
|
3930
|
-
Object.keys(facets).forEach(function(dfacet) {
|
|
4167
|
+
Object.keys(facets).forEach(function (dfacet) {
|
|
3931
4168
|
var facetResults = facets[dfacet];
|
|
3932
|
-
var position = findIndex(state.hierarchicalFacets, function(f) {
|
|
4169
|
+
var position = findIndex(state.hierarchicalFacets, function (f) {
|
|
3933
4170
|
return f.name === hierarchicalFacet.name;
|
|
3934
4171
|
});
|
|
3935
|
-
var attributeIndex = findIndex(
|
|
3936
|
-
|
|
3937
|
-
|
|
4172
|
+
var attributeIndex = findIndex(
|
|
4173
|
+
self.hierarchicalFacets[position],
|
|
4174
|
+
function (f) {
|
|
4175
|
+
return f.attribute === dfacet;
|
|
4176
|
+
}
|
|
4177
|
+
);
|
|
3938
4178
|
|
|
3939
4179
|
// previous refinements and no results so not able to find it
|
|
3940
4180
|
if (attributeIndex === -1) {
|
|
@@ -3953,7 +4193,8 @@
|
|
|
3953
4193
|
|
|
3954
4194
|
if (currentRefinement.length > 0) {
|
|
3955
4195
|
var root = currentRefinement[0].split(separator)[0];
|
|
3956
|
-
defaultData[root] =
|
|
4196
|
+
defaultData[root] =
|
|
4197
|
+
self.hierarchicalFacets[position][attributeIndex].data[root];
|
|
3957
4198
|
}
|
|
3958
4199
|
|
|
3959
4200
|
self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
|
|
@@ -3968,17 +4209,17 @@
|
|
|
3968
4209
|
});
|
|
3969
4210
|
|
|
3970
4211
|
// add the excludes
|
|
3971
|
-
Object.keys(state.facetsExcludes).forEach(function(facetName) {
|
|
4212
|
+
Object.keys(state.facetsExcludes).forEach(function (facetName) {
|
|
3972
4213
|
var excludes = state.facetsExcludes[facetName];
|
|
3973
4214
|
var position = facetsIndices[facetName];
|
|
3974
4215
|
|
|
3975
4216
|
self.facets[position] = {
|
|
3976
4217
|
name: facetName,
|
|
3977
4218
|
data: mainFacets[facetName],
|
|
3978
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4219
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3979
4220
|
};
|
|
3980
|
-
excludes.forEach(function(facetValue) {
|
|
3981
|
-
self.facets[position] = self.facets[position] || {name: facetName};
|
|
4221
|
+
excludes.forEach(function (facetValue) {
|
|
4222
|
+
self.facets[position] = self.facets[position] || { name: facetName };
|
|
3982
4223
|
self.facets[position].data = self.facets[position].data || {};
|
|
3983
4224
|
self.facets[position].data[facetValue] = 0;
|
|
3984
4225
|
});
|
|
@@ -3987,7 +4228,9 @@
|
|
|
3987
4228
|
/**
|
|
3988
4229
|
* @type {Array}
|
|
3989
4230
|
*/
|
|
3990
|
-
this.hierarchicalFacets = this.hierarchicalFacets.map(
|
|
4231
|
+
this.hierarchicalFacets = this.hierarchicalFacets.map(
|
|
4232
|
+
generateHierarchicalTree_1(state)
|
|
4233
|
+
);
|
|
3991
4234
|
|
|
3992
4235
|
/**
|
|
3993
4236
|
* @type {Array}
|
|
@@ -4007,14 +4250,16 @@
|
|
|
4007
4250
|
* @param {string} name name of the faceted attribute
|
|
4008
4251
|
* @return {SearchResults.Facet} the facet object
|
|
4009
4252
|
*/
|
|
4010
|
-
SearchResults.prototype.getFacetByName = function(name) {
|
|
4253
|
+
SearchResults.prototype.getFacetByName = function (name) {
|
|
4011
4254
|
function predicate(facet) {
|
|
4012
4255
|
return facet.name === name;
|
|
4013
4256
|
}
|
|
4014
4257
|
|
|
4015
|
-
return
|
|
4258
|
+
return (
|
|
4259
|
+
find$1(this.facets, predicate) ||
|
|
4016
4260
|
find$1(this.disjunctiveFacets, predicate) ||
|
|
4017
|
-
find$1(this.hierarchicalFacets, predicate)
|
|
4261
|
+
find$1(this.hierarchicalFacets, predicate)
|
|
4262
|
+
);
|
|
4018
4263
|
};
|
|
4019
4264
|
|
|
4020
4265
|
/**
|
|
@@ -4033,55 +4278,70 @@
|
|
|
4033
4278
|
var facet = find$1(results.facets, predicate);
|
|
4034
4279
|
if (!facet) return [];
|
|
4035
4280
|
|
|
4036
|
-
return Object.keys(facet.data).map(function(name) {
|
|
4281
|
+
return Object.keys(facet.data).map(function (name) {
|
|
4037
4282
|
var value = escapeFacetValue$2(name);
|
|
4038
4283
|
return {
|
|
4039
4284
|
name: name,
|
|
4040
4285
|
escapedValue: value,
|
|
4041
4286
|
count: facet.data[name],
|
|
4042
4287
|
isRefined: results._state.isFacetRefined(attribute, value),
|
|
4043
|
-
isExcluded: results._state.isExcludeRefined(attribute, name)
|
|
4288
|
+
isExcluded: results._state.isExcludeRefined(attribute, name),
|
|
4044
4289
|
};
|
|
4045
4290
|
});
|
|
4046
4291
|
} else if (results._state.isDisjunctiveFacet(attribute)) {
|
|
4047
4292
|
var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
|
|
4048
4293
|
if (!disjunctiveFacet) return [];
|
|
4049
4294
|
|
|
4050
|
-
return Object.keys(disjunctiveFacet.data).map(function(name) {
|
|
4295
|
+
return Object.keys(disjunctiveFacet.data).map(function (name) {
|
|
4051
4296
|
var value = escapeFacetValue$2(name);
|
|
4052
4297
|
return {
|
|
4053
4298
|
name: name,
|
|
4054
4299
|
escapedValue: value,
|
|
4055
4300
|
count: disjunctiveFacet.data[name],
|
|
4056
|
-
isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
|
|
4301
|
+
isRefined: results._state.isDisjunctiveFacetRefined(attribute, value),
|
|
4057
4302
|
};
|
|
4058
4303
|
});
|
|
4059
4304
|
} else if (results._state.isHierarchicalFacet(attribute)) {
|
|
4060
4305
|
var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
|
|
4061
4306
|
if (!hierarchicalFacetValues) return hierarchicalFacetValues;
|
|
4062
4307
|
|
|
4063
|
-
var hierarchicalFacet =
|
|
4064
|
-
|
|
4308
|
+
var hierarchicalFacet =
|
|
4309
|
+
results._state.getHierarchicalFacetByName(attribute);
|
|
4310
|
+
var separator =
|
|
4311
|
+
results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
4312
|
+
var currentRefinement = unescapeFacetValue$3(
|
|
4065
4313
|
results._state.getHierarchicalRefinement(attribute)[0] || ''
|
|
4066
|
-
)
|
|
4314
|
+
);
|
|
4315
|
+
|
|
4316
|
+
if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
|
|
4317
|
+
currentRefinement = currentRefinement.replace(
|
|
4318
|
+
hierarchicalFacet.rootPath + separator,
|
|
4319
|
+
''
|
|
4320
|
+
);
|
|
4321
|
+
}
|
|
4322
|
+
|
|
4323
|
+
var currentRefinementSplit = currentRefinement.split(separator);
|
|
4067
4324
|
currentRefinementSplit.unshift(attribute);
|
|
4068
4325
|
|
|
4069
4326
|
setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
|
|
4070
4327
|
|
|
4071
4328
|
return hierarchicalFacetValues;
|
|
4072
4329
|
}
|
|
4330
|
+
|
|
4331
|
+
return undefined;
|
|
4073
4332
|
}
|
|
4074
4333
|
|
|
4075
4334
|
/**
|
|
4076
4335
|
* Set the isRefined of a hierarchical facet result based on the current state.
|
|
4077
4336
|
* @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
|
|
4078
|
-
* @param {string[]}
|
|
4337
|
+
* @param {string[]} currentRefinement array of parts of the current hierarchical refinement
|
|
4079
4338
|
* @param {number} depth recursion depth in the currentRefinement
|
|
4339
|
+
* @return {undefined} function mutates the item
|
|
4080
4340
|
*/
|
|
4081
4341
|
function setIsRefined(item, currentRefinement, depth) {
|
|
4082
4342
|
item.isRefined = item.name === currentRefinement[depth];
|
|
4083
4343
|
if (item.data) {
|
|
4084
|
-
item.data.forEach(function(child) {
|
|
4344
|
+
item.data.forEach(function (child) {
|
|
4085
4345
|
setIsRefined(child, currentRefinement, depth + 1);
|
|
4086
4346
|
});
|
|
4087
4347
|
}
|
|
@@ -4090,10 +4350,11 @@
|
|
|
4090
4350
|
/**
|
|
4091
4351
|
* Sort nodes of a hierarchical or disjunctive facet results
|
|
4092
4352
|
* @private
|
|
4093
|
-
* @param {function} sortFn
|
|
4353
|
+
* @param {function} sortFn sort function to apply
|
|
4094
4354
|
* @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
|
|
4095
4355
|
* @param {string[]} names attribute names
|
|
4096
4356
|
* @param {number} [level=0] current index in the names array
|
|
4357
|
+
* @return {HierarchicalFacet|Array} sorted node
|
|
4097
4358
|
*/
|
|
4098
4359
|
function recSort(sortFn, node, names, level) {
|
|
4099
4360
|
level = level || 0;
|
|
@@ -4106,11 +4367,11 @@
|
|
|
4106
4367
|
return node;
|
|
4107
4368
|
}
|
|
4108
4369
|
|
|
4109
|
-
var children = node.data.map(function(childNode) {
|
|
4370
|
+
var children = node.data.map(function (childNode) {
|
|
4110
4371
|
return recSort(sortFn, childNode, names, level + 1);
|
|
4111
4372
|
});
|
|
4112
4373
|
var sortedChildren = sortFn(children, names[level]);
|
|
4113
|
-
var newNode = defaultsPure({data: sortedChildren}, node);
|
|
4374
|
+
var newNode = defaultsPure({ data: sortedChildren }, node);
|
|
4114
4375
|
return newNode;
|
|
4115
4376
|
}
|
|
4116
4377
|
|
|
@@ -4131,7 +4392,7 @@
|
|
|
4131
4392
|
* Sorts facet arrays via their facet ordering
|
|
4132
4393
|
* @param {Array} facetValues the values
|
|
4133
4394
|
* @param {FacetOrdering} facetOrdering the ordering
|
|
4134
|
-
* @returns {Array}
|
|
4395
|
+
* @returns {Array} the sorted facet values
|
|
4135
4396
|
*/
|
|
4136
4397
|
function sortViaFacetOrdering(facetValues, facetOrdering) {
|
|
4137
4398
|
var orderedFacets = [];
|
|
@@ -4142,12 +4403,12 @@
|
|
|
4142
4403
|
* an object with the keys being the values in order, the values their index:
|
|
4143
4404
|
* ['one', 'two'] -> { one: 0, two: 1 }
|
|
4144
4405
|
*/
|
|
4145
|
-
var reverseOrder = order.reduce(function(acc, name, i) {
|
|
4406
|
+
var reverseOrder = order.reduce(function (acc, name, i) {
|
|
4146
4407
|
acc[name] = i;
|
|
4147
4408
|
return acc;
|
|
4148
4409
|
}, {});
|
|
4149
4410
|
|
|
4150
|
-
facetValues.forEach(function(item) {
|
|
4411
|
+
facetValues.forEach(function (item) {
|
|
4151
4412
|
// hierarchical facets get sorted using their raw name
|
|
4152
4413
|
var name = item.path || item.name;
|
|
4153
4414
|
if (reverseOrder[name] !== undefined) {
|
|
@@ -4157,7 +4418,7 @@
|
|
|
4157
4418
|
}
|
|
4158
4419
|
});
|
|
4159
4420
|
|
|
4160
|
-
orderedFacets = orderedFacets.filter(function(facet) {
|
|
4421
|
+
orderedFacets = orderedFacets.filter(function (facet) {
|
|
4161
4422
|
return facet;
|
|
4162
4423
|
});
|
|
4163
4424
|
|
|
@@ -4166,7 +4427,10 @@
|
|
|
4166
4427
|
if (sortRemainingBy === 'hidden') {
|
|
4167
4428
|
return orderedFacets;
|
|
4168
4429
|
} else if (sortRemainingBy === 'alpha') {
|
|
4169
|
-
ordering = [
|
|
4430
|
+
ordering = [
|
|
4431
|
+
['path', 'name'],
|
|
4432
|
+
['asc', 'asc'],
|
|
4433
|
+
];
|
|
4170
4434
|
} else {
|
|
4171
4435
|
ordering = [['count'], ['desc']];
|
|
4172
4436
|
}
|
|
@@ -4179,7 +4443,7 @@
|
|
|
4179
4443
|
/**
|
|
4180
4444
|
* @param {SearchResults} results the search results class
|
|
4181
4445
|
* @param {string} attribute the attribute to retrieve ordering of
|
|
4182
|
-
* @returns {FacetOrdering
|
|
4446
|
+
* @returns {FacetOrdering | undefined} the facet ordering
|
|
4183
4447
|
*/
|
|
4184
4448
|
function getFacetOrdering(results, attribute) {
|
|
4185
4449
|
return (
|
|
@@ -4238,7 +4502,7 @@
|
|
|
4238
4502
|
* });
|
|
4239
4503
|
* });
|
|
4240
4504
|
*/
|
|
4241
|
-
SearchResults.prototype.getFacetValues = function(attribute, opts) {
|
|
4505
|
+
SearchResults.prototype.getFacetValues = function (attribute, opts) {
|
|
4242
4506
|
var facetValues = extractNormalizedFacetValues(this, attribute);
|
|
4243
4507
|
if (!facetValues) {
|
|
4244
4508
|
return undefined;
|
|
@@ -4248,9 +4512,10 @@
|
|
|
4248
4512
|
sortBy: SearchResults.DEFAULT_SORT,
|
|
4249
4513
|
// if no sortBy is given, attempt to sort based on facetOrdering
|
|
4250
4514
|
// if it is given, we still allow to sort via facet ordering first
|
|
4251
|
-
facetOrdering: !(opts && opts.sortBy)
|
|
4515
|
+
facetOrdering: !(opts && opts.sortBy),
|
|
4252
4516
|
});
|
|
4253
4517
|
|
|
4518
|
+
// eslint-disable-next-line consistent-this
|
|
4254
4519
|
var results = this;
|
|
4255
4520
|
var attributes;
|
|
4256
4521
|
if (Array.isArray(facetValues)) {
|
|
@@ -4260,25 +4525,29 @@
|
|
|
4260
4525
|
attributes = config.attributes;
|
|
4261
4526
|
}
|
|
4262
4527
|
|
|
4263
|
-
return recSort(
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4528
|
+
return recSort(
|
|
4529
|
+
function (data, facetName) {
|
|
4530
|
+
if (options.facetOrdering) {
|
|
4531
|
+
var facetOrdering = getFacetOrdering(results, facetName);
|
|
4532
|
+
if (facetOrdering) {
|
|
4533
|
+
return sortViaFacetOrdering(data, facetOrdering);
|
|
4534
|
+
}
|
|
4268
4535
|
}
|
|
4269
|
-
}
|
|
4270
4536
|
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4537
|
+
if (Array.isArray(options.sortBy)) {
|
|
4538
|
+
var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
|
|
4539
|
+
return orderBy_1(data, order[0], order[1]);
|
|
4540
|
+
} else if (typeof options.sortBy === 'function') {
|
|
4541
|
+
return vanillaSortFn(options.sortBy, data);
|
|
4542
|
+
}
|
|
4543
|
+
throw new Error(
|
|
4544
|
+
'options.sortBy is optional but if defined it must be ' +
|
|
4545
|
+
'either an array of string (predicates) or a sorting function'
|
|
4546
|
+
);
|
|
4547
|
+
},
|
|
4548
|
+
facetValues,
|
|
4549
|
+
attributes
|
|
4550
|
+
);
|
|
4282
4551
|
};
|
|
4283
4552
|
|
|
4284
4553
|
/**
|
|
@@ -4287,7 +4556,7 @@
|
|
|
4287
4556
|
* @param {string} attribute name of the faceted attribute
|
|
4288
4557
|
* @return {object} The stats of the facet
|
|
4289
4558
|
*/
|
|
4290
|
-
SearchResults.prototype.getFacetStats = function(attribute) {
|
|
4559
|
+
SearchResults.prototype.getFacetStats = function (attribute) {
|
|
4291
4560
|
if (this._state.isConjunctiveFacet(attribute)) {
|
|
4292
4561
|
return getFacetStatsIfAvailable(this.facets, attribute);
|
|
4293
4562
|
} else if (this._state.isDisjunctiveFacet(attribute)) {
|
|
@@ -4304,10 +4573,11 @@
|
|
|
4304
4573
|
|
|
4305
4574
|
/**
|
|
4306
4575
|
* @param {FacetListItem[]} facetList (has more items, but enough for here)
|
|
4307
|
-
* @param {string} facetName
|
|
4576
|
+
* @param {string} facetName The attribute to look for
|
|
4577
|
+
* @return {object|undefined} The stats of the facet
|
|
4308
4578
|
*/
|
|
4309
4579
|
function getFacetStatsIfAvailable(facetList, facetName) {
|
|
4310
|
-
var data = find$1(facetList, function(facet) {
|
|
4580
|
+
var data = find$1(facetList, function (facet) {
|
|
4311
4581
|
return facet.name === facetName;
|
|
4312
4582
|
});
|
|
4313
4583
|
return data && data.stats;
|
|
@@ -4325,53 +4595,76 @@
|
|
|
4325
4595
|
*
|
|
4326
4596
|
* @return {Array.<Refinement>} all the refinements
|
|
4327
4597
|
*/
|
|
4328
|
-
SearchResults.prototype.getRefinements = function() {
|
|
4598
|
+
SearchResults.prototype.getRefinements = function () {
|
|
4329
4599
|
var state = this._state;
|
|
4600
|
+
// eslint-disable-next-line consistent-this
|
|
4330
4601
|
var results = this;
|
|
4331
4602
|
var res = [];
|
|
4332
4603
|
|
|
4333
|
-
Object.keys(state.facetsRefinements).forEach(function(attributeName) {
|
|
4334
|
-
state.facetsRefinements[attributeName].forEach(function(name) {
|
|
4335
|
-
res.push(
|
|
4604
|
+
Object.keys(state.facetsRefinements).forEach(function (attributeName) {
|
|
4605
|
+
state.facetsRefinements[attributeName].forEach(function (name) {
|
|
4606
|
+
res.push(
|
|
4607
|
+
getRefinement(state, 'facet', attributeName, name, results.facets)
|
|
4608
|
+
);
|
|
4336
4609
|
});
|
|
4337
4610
|
});
|
|
4338
4611
|
|
|
4339
|
-
Object.keys(state.facetsExcludes).forEach(function(attributeName) {
|
|
4340
|
-
state.facetsExcludes[attributeName].forEach(function(name) {
|
|
4341
|
-
res.push(
|
|
4612
|
+
Object.keys(state.facetsExcludes).forEach(function (attributeName) {
|
|
4613
|
+
state.facetsExcludes[attributeName].forEach(function (name) {
|
|
4614
|
+
res.push(
|
|
4615
|
+
getRefinement(state, 'exclude', attributeName, name, results.facets)
|
|
4616
|
+
);
|
|
4342
4617
|
});
|
|
4343
4618
|
});
|
|
4344
4619
|
|
|
4345
|
-
Object.keys(state.disjunctiveFacetsRefinements).forEach(function(
|
|
4346
|
-
|
|
4347
|
-
|
|
4620
|
+
Object.keys(state.disjunctiveFacetsRefinements).forEach(function (
|
|
4621
|
+
attributeName
|
|
4622
|
+
) {
|
|
4623
|
+
state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
|
|
4624
|
+
res.push(
|
|
4625
|
+
getRefinement(
|
|
4626
|
+
state,
|
|
4627
|
+
'disjunctive',
|
|
4628
|
+
attributeName,
|
|
4629
|
+
name,
|
|
4630
|
+
results.disjunctiveFacets
|
|
4631
|
+
)
|
|
4632
|
+
);
|
|
4348
4633
|
});
|
|
4349
4634
|
});
|
|
4350
4635
|
|
|
4351
|
-
Object.keys(state.hierarchicalFacetsRefinements).forEach(function(
|
|
4352
|
-
|
|
4353
|
-
|
|
4636
|
+
Object.keys(state.hierarchicalFacetsRefinements).forEach(function (
|
|
4637
|
+
attributeName
|
|
4638
|
+
) {
|
|
4639
|
+
state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
|
|
4640
|
+
res.push(
|
|
4641
|
+
getHierarchicalRefinement(
|
|
4642
|
+
state,
|
|
4643
|
+
attributeName,
|
|
4644
|
+
name,
|
|
4645
|
+
results.hierarchicalFacets
|
|
4646
|
+
)
|
|
4647
|
+
);
|
|
4354
4648
|
});
|
|
4355
4649
|
});
|
|
4356
4650
|
|
|
4357
|
-
|
|
4358
|
-
Object.keys(state.numericRefinements).forEach(function(attributeName) {
|
|
4651
|
+
Object.keys(state.numericRefinements).forEach(function (attributeName) {
|
|
4359
4652
|
var operators = state.numericRefinements[attributeName];
|
|
4360
|
-
Object.keys(operators).forEach(function(operator) {
|
|
4361
|
-
operators[operator].forEach(function(value) {
|
|
4653
|
+
Object.keys(operators).forEach(function (operator) {
|
|
4654
|
+
operators[operator].forEach(function (value) {
|
|
4362
4655
|
res.push({
|
|
4363
4656
|
type: 'numeric',
|
|
4364
4657
|
attributeName: attributeName,
|
|
4365
4658
|
name: value,
|
|
4366
4659
|
numericValue: value,
|
|
4367
|
-
operator: operator
|
|
4660
|
+
operator: operator,
|
|
4368
4661
|
});
|
|
4369
4662
|
});
|
|
4370
4663
|
});
|
|
4371
4664
|
});
|
|
4372
4665
|
|
|
4373
|
-
state.tagRefinements.forEach(function(name) {
|
|
4374
|
-
res.push({type: 'tag', attributeName: '_tags', name: name});
|
|
4666
|
+
state.tagRefinements.forEach(function (name) {
|
|
4667
|
+
res.push({ type: 'tag', attributeName: '_tags', name: name });
|
|
4375
4668
|
});
|
|
4376
4669
|
|
|
4377
4670
|
return res;
|
|
@@ -4385,14 +4678,15 @@
|
|
|
4385
4678
|
*/
|
|
4386
4679
|
|
|
4387
4680
|
/**
|
|
4388
|
-
* @param {
|
|
4389
|
-
* @param {
|
|
4390
|
-
* @param {string} attributeName
|
|
4391
|
-
* @param {*} name
|
|
4392
|
-
* @param {Facet[]} resultsFacets
|
|
4681
|
+
* @param {SearchParameters} state the current state
|
|
4682
|
+
* @param {string} type the type of the refinement
|
|
4683
|
+
* @param {string} attributeName The attribute of the facet
|
|
4684
|
+
* @param {*} name The name of the facet
|
|
4685
|
+
* @param {Facet[]} resultsFacets facets from the results
|
|
4686
|
+
* @return {Refinement} the refinement
|
|
4393
4687
|
*/
|
|
4394
4688
|
function getRefinement(state, type, attributeName, name, resultsFacets) {
|
|
4395
|
-
var facet = find$1(resultsFacets, function(f) {
|
|
4689
|
+
var facet = find$1(resultsFacets, function (f) {
|
|
4396
4690
|
return f.name === attributeName;
|
|
4397
4691
|
});
|
|
4398
4692
|
var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
|
|
@@ -4403,27 +4697,29 @@
|
|
|
4403
4697
|
attributeName: attributeName,
|
|
4404
4698
|
name: name,
|
|
4405
4699
|
count: count,
|
|
4406
|
-
exhaustive: exhaustive
|
|
4700
|
+
exhaustive: exhaustive,
|
|
4407
4701
|
};
|
|
4408
4702
|
}
|
|
4409
4703
|
|
|
4410
4704
|
/**
|
|
4411
|
-
* @param {
|
|
4412
|
-
* @param {string} attributeName
|
|
4413
|
-
* @param {
|
|
4414
|
-
* @param {Facet[]} resultsFacets
|
|
4705
|
+
* @param {SearchParameters} state the current state
|
|
4706
|
+
* @param {string} attributeName the attribute of the hierarchical facet
|
|
4707
|
+
* @param {string} name the name of the facet
|
|
4708
|
+
* @param {Facet[]} resultsFacets facets from the results
|
|
4709
|
+
* @return {HierarchicalFacet} the hierarchical facet
|
|
4415
4710
|
*/
|
|
4416
4711
|
function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
|
|
4417
4712
|
var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
|
|
4418
4713
|
var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
|
|
4419
4714
|
var split = name.split(separator);
|
|
4420
|
-
var rootFacet = find$1(resultsFacets, function(facet) {
|
|
4715
|
+
var rootFacet = find$1(resultsFacets, function (facet) {
|
|
4421
4716
|
return facet.name === attributeName;
|
|
4422
4717
|
});
|
|
4423
4718
|
|
|
4424
|
-
var facet = split.reduce(function(intermediateFacet, part) {
|
|
4719
|
+
var facet = split.reduce(function (intermediateFacet, part) {
|
|
4425
4720
|
var newFacet =
|
|
4426
|
-
intermediateFacet &&
|
|
4721
|
+
intermediateFacet &&
|
|
4722
|
+
find$1(intermediateFacet.data, function (f) {
|
|
4427
4723
|
return f.name === part;
|
|
4428
4724
|
});
|
|
4429
4725
|
return newFacet !== undefined ? newFacet : intermediateFacet;
|
|
@@ -4438,7 +4734,7 @@
|
|
|
4438
4734
|
attributeName: attributeName,
|
|
4439
4735
|
name: path,
|
|
4440
4736
|
count: count,
|
|
4441
|
-
exhaustive: exhaustive
|
|
4737
|
+
exhaustive: exhaustive,
|
|
4442
4738
|
};
|
|
4443
4739
|
}
|
|
4444
4740
|
|
|
@@ -4753,8 +5049,8 @@
|
|
|
4753
5049
|
value: ctor,
|
|
4754
5050
|
enumerable: false,
|
|
4755
5051
|
writable: true,
|
|
4756
|
-
configurable: true
|
|
4757
|
-
}
|
|
5052
|
+
configurable: true,
|
|
5053
|
+
},
|
|
4758
5054
|
});
|
|
4759
5055
|
}
|
|
4760
5056
|
|
|
@@ -4769,6 +5065,8 @@
|
|
|
4769
5065
|
* - result: when the response is retrieved from Algolia and is processed.
|
|
4770
5066
|
* This event contains a {@link SearchResults} object and the
|
|
4771
5067
|
* {@link SearchParameters} corresponding to this answer.
|
|
5068
|
+
* @param {AlgoliaSearchHelper} mainHelper the main helper
|
|
5069
|
+
* @param {function} fn the function to create the derived state
|
|
4772
5070
|
*/
|
|
4773
5071
|
function DerivedHelper(mainHelper, fn) {
|
|
4774
5072
|
this.main = mainHelper;
|
|
@@ -4783,12 +5081,12 @@
|
|
|
4783
5081
|
* @return {undefined}
|
|
4784
5082
|
* @throws Error if the derived helper is already detached
|
|
4785
5083
|
*/
|
|
4786
|
-
DerivedHelper.prototype.detach = function() {
|
|
5084
|
+
DerivedHelper.prototype.detach = function () {
|
|
4787
5085
|
this.removeAllListeners();
|
|
4788
5086
|
this.main.detachDerivedHelper(this);
|
|
4789
5087
|
};
|
|
4790
5088
|
|
|
4791
|
-
DerivedHelper.prototype.getModifiedState = function(parameters) {
|
|
5089
|
+
DerivedHelper.prototype.getModifiedState = function (parameters) {
|
|
4792
5090
|
return this.fn(parameters);
|
|
4793
5091
|
};
|
|
4794
5092
|
|
|
@@ -4796,10 +5094,10 @@
|
|
|
4796
5094
|
|
|
4797
5095
|
function sortObject(obj) {
|
|
4798
5096
|
return Object.keys(obj)
|
|
4799
|
-
.sort(function(a, b) {
|
|
5097
|
+
.sort(function (a, b) {
|
|
4800
5098
|
return a.localeCompare(b);
|
|
4801
5099
|
})
|
|
4802
|
-
.reduce(function(acc, curr) {
|
|
5100
|
+
.reduce(function (acc, curr) {
|
|
4803
5101
|
acc[curr] = obj[curr];
|
|
4804
5102
|
return acc;
|
|
4805
5103
|
}, {});
|
|
@@ -4810,6 +5108,8 @@
|
|
|
4810
5108
|
* Get all the queries to send to the client, those queries can used directly
|
|
4811
5109
|
* with the Algolia client.
|
|
4812
5110
|
* @private
|
|
5111
|
+
* @param {string} index The name of the index
|
|
5112
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
4813
5113
|
* @return {object[]} The queries
|
|
4814
5114
|
*/
|
|
4815
5115
|
_getQueries: function getQueries(index, state) {
|
|
@@ -4818,39 +5118,47 @@
|
|
|
4818
5118
|
// One query for the hits
|
|
4819
5119
|
queries.push({
|
|
4820
5120
|
indexName: index,
|
|
4821
|
-
params: requestBuilder._getHitsSearchParams(state)
|
|
5121
|
+
params: requestBuilder._getHitsSearchParams(state),
|
|
4822
5122
|
});
|
|
4823
5123
|
|
|
4824
5124
|
// One for each disjunctive facets
|
|
4825
|
-
state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
|
|
5125
|
+
state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
|
|
4826
5126
|
queries.push({
|
|
4827
5127
|
indexName: index,
|
|
4828
|
-
params: requestBuilder._getDisjunctiveFacetSearchParams(
|
|
5128
|
+
params: requestBuilder._getDisjunctiveFacetSearchParams(
|
|
5129
|
+
state,
|
|
5130
|
+
refinedFacet
|
|
5131
|
+
),
|
|
4829
5132
|
});
|
|
4830
5133
|
});
|
|
4831
5134
|
|
|
4832
5135
|
// More to get the parent levels of the hierarchical facets when refined
|
|
4833
|
-
state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
|
|
5136
|
+
state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
|
|
4834
5137
|
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
|
|
4835
5138
|
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
|
|
4836
5139
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
4837
5140
|
|
|
4838
5141
|
// If we are deeper than level 0 (starting from `beer > IPA`)
|
|
4839
5142
|
// we want to get all parent values
|
|
4840
|
-
if (
|
|
5143
|
+
if (
|
|
5144
|
+
currentRefinement.length > 0 &&
|
|
5145
|
+
currentRefinement[0].split(separator).length > 1
|
|
5146
|
+
) {
|
|
4841
5147
|
// We generate a map of the filters we will use for our facet values queries
|
|
4842
|
-
var filtersMap = currentRefinement[0]
|
|
4843
|
-
|
|
5148
|
+
var filtersMap = currentRefinement[0]
|
|
5149
|
+
.split(separator)
|
|
5150
|
+
.slice(0, -1)
|
|
5151
|
+
.reduce(function createFiltersMap(map, segment, level) {
|
|
4844
5152
|
return map.concat({
|
|
4845
5153
|
attribute: hierarchicalFacet.attributes[level],
|
|
4846
|
-
value:
|
|
4847
|
-
|
|
4848
|
-
|
|
5154
|
+
value:
|
|
5155
|
+
level === 0
|
|
5156
|
+
? segment
|
|
5157
|
+
: [map[map.length - 1].value, segment].join(separator),
|
|
4849
5158
|
});
|
|
4850
|
-
}
|
|
4851
|
-
, []);
|
|
5159
|
+
}, []);
|
|
4852
5160
|
|
|
4853
|
-
filtersMap.forEach(function(filter, level) {
|
|
5161
|
+
filtersMap.forEach(function (filter, level) {
|
|
4854
5162
|
var params = requestBuilder._getDisjunctiveFacetSearchParams(
|
|
4855
5163
|
state,
|
|
4856
5164
|
filter.attribute,
|
|
@@ -4859,37 +5167,48 @@
|
|
|
4859
5167
|
|
|
4860
5168
|
// Keep facet filters unrelated to current hierarchical attributes
|
|
4861
5169
|
function hasHierarchicalFacetFilter(value) {
|
|
4862
|
-
return hierarchicalFacet.attributes.some(function(attribute) {
|
|
5170
|
+
return hierarchicalFacet.attributes.some(function (attribute) {
|
|
4863
5171
|
return attribute === value.split(':')[0];
|
|
4864
5172
|
});
|
|
4865
5173
|
}
|
|
4866
5174
|
|
|
4867
|
-
var filteredFacetFilters = (params.facetFilters || []).reduce(
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
5175
|
+
var filteredFacetFilters = (params.facetFilters || []).reduce(
|
|
5176
|
+
function (acc, facetFilter) {
|
|
5177
|
+
if (Array.isArray(facetFilter)) {
|
|
5178
|
+
var filtered = facetFilter.filter(function (filterValue) {
|
|
5179
|
+
return !hasHierarchicalFacetFilter(filterValue);
|
|
5180
|
+
});
|
|
4872
5181
|
|
|
4873
|
-
|
|
4874
|
-
|
|
5182
|
+
if (filtered.length > 0) {
|
|
5183
|
+
acc.push(filtered);
|
|
5184
|
+
}
|
|
4875
5185
|
}
|
|
4876
|
-
}
|
|
4877
5186
|
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
5187
|
+
if (
|
|
5188
|
+
typeof facetFilter === 'string' &&
|
|
5189
|
+
!hasHierarchicalFacetFilter(facetFilter)
|
|
5190
|
+
) {
|
|
5191
|
+
acc.push(facetFilter);
|
|
5192
|
+
}
|
|
4881
5193
|
|
|
4882
|
-
|
|
4883
|
-
|
|
5194
|
+
return acc;
|
|
5195
|
+
},
|
|
5196
|
+
[]
|
|
5197
|
+
);
|
|
4884
5198
|
|
|
4885
5199
|
var parent = filtersMap[level - 1];
|
|
4886
5200
|
if (level > 0) {
|
|
4887
|
-
params.facetFilters = filteredFacetFilters.concat(
|
|
5201
|
+
params.facetFilters = filteredFacetFilters.concat(
|
|
5202
|
+
parent.attribute + ':' + parent.value
|
|
5203
|
+
);
|
|
4888
5204
|
} else {
|
|
4889
|
-
params.facetFilters =
|
|
5205
|
+
params.facetFilters =
|
|
5206
|
+
filteredFacetFilters.length > 0
|
|
5207
|
+
? filteredFacetFilters
|
|
5208
|
+
: undefined;
|
|
4890
5209
|
}
|
|
4891
5210
|
|
|
4892
|
-
queries.push({indexName: index, params: params});
|
|
5211
|
+
queries.push({ indexName: index, params: params });
|
|
4893
5212
|
});
|
|
4894
5213
|
}
|
|
4895
5214
|
});
|
|
@@ -4900,20 +5219,20 @@
|
|
|
4900
5219
|
/**
|
|
4901
5220
|
* Build search parameters used to fetch hits
|
|
4902
5221
|
* @private
|
|
4903
|
-
* @
|
|
5222
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
5223
|
+
* @return {object.<string, any>} The search parameters for hits
|
|
4904
5224
|
*/
|
|
4905
|
-
_getHitsSearchParams: function(state) {
|
|
5225
|
+
_getHitsSearchParams: function (state) {
|
|
4906
5226
|
var facets = state.facets
|
|
4907
5227
|
.concat(state.disjunctiveFacets)
|
|
4908
5228
|
.concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
|
|
4909
5229
|
|
|
4910
|
-
|
|
4911
5230
|
var facetFilters = requestBuilder._getFacetFilters(state);
|
|
4912
5231
|
var numericFilters = requestBuilder._getNumericFilters(state);
|
|
4913
5232
|
var tagFilters = requestBuilder._getTagFilters(state);
|
|
4914
5233
|
var additionalParams = {
|
|
4915
5234
|
facets: facets.indexOf('*') > -1 ? ['*'] : facets,
|
|
4916
|
-
tagFilters: tagFilters
|
|
5235
|
+
tagFilters: tagFilters,
|
|
4917
5236
|
};
|
|
4918
5237
|
|
|
4919
5238
|
if (facetFilters.length > 0) {
|
|
@@ -4930,19 +5249,28 @@
|
|
|
4930
5249
|
/**
|
|
4931
5250
|
* Build search parameters used to fetch a disjunctive facet
|
|
4932
5251
|
* @private
|
|
5252
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
4933
5253
|
* @param {string} facet the associated facet name
|
|
4934
5254
|
* @param {boolean} hierarchicalRootLevel ?? FIXME
|
|
4935
|
-
* @return {object}
|
|
5255
|
+
* @return {object} The search parameters for a disjunctive facet
|
|
4936
5256
|
*/
|
|
4937
|
-
_getDisjunctiveFacetSearchParams: function(
|
|
4938
|
-
|
|
5257
|
+
_getDisjunctiveFacetSearchParams: function (
|
|
5258
|
+
state,
|
|
5259
|
+
facet,
|
|
5260
|
+
hierarchicalRootLevel
|
|
5261
|
+
) {
|
|
5262
|
+
var facetFilters = requestBuilder._getFacetFilters(
|
|
5263
|
+
state,
|
|
5264
|
+
facet,
|
|
5265
|
+
hierarchicalRootLevel
|
|
5266
|
+
);
|
|
4939
5267
|
var numericFilters = requestBuilder._getNumericFilters(state, facet);
|
|
4940
5268
|
var tagFilters = requestBuilder._getTagFilters(state);
|
|
4941
5269
|
var additionalParams = {
|
|
4942
5270
|
hitsPerPage: 0,
|
|
4943
5271
|
page: 0,
|
|
4944
5272
|
analytics: false,
|
|
4945
|
-
clickAnalytics: false
|
|
5273
|
+
clickAnalytics: false,
|
|
4946
5274
|
};
|
|
4947
5275
|
|
|
4948
5276
|
if (tagFilters.length > 0) {
|
|
@@ -4952,11 +5280,12 @@
|
|
|
4952
5280
|
var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
|
|
4953
5281
|
|
|
4954
5282
|
if (hierarchicalFacet) {
|
|
4955
|
-
additionalParams.facets =
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
5283
|
+
additionalParams.facets =
|
|
5284
|
+
requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
|
|
5285
|
+
state,
|
|
5286
|
+
hierarchicalFacet,
|
|
5287
|
+
hierarchicalRootLevel
|
|
5288
|
+
);
|
|
4960
5289
|
} else {
|
|
4961
5290
|
additionalParams.facets = facet;
|
|
4962
5291
|
}
|
|
@@ -4975,24 +5304,25 @@
|
|
|
4975
5304
|
/**
|
|
4976
5305
|
* Return the numeric filters in an algolia request fashion
|
|
4977
5306
|
* @private
|
|
5307
|
+
* @param {SearchParameters} state the state from which to get the filters
|
|
4978
5308
|
* @param {string} [facetName] the name of the attribute for which the filters should be excluded
|
|
4979
5309
|
* @return {string[]} the numeric filters in the algolia format
|
|
4980
5310
|
*/
|
|
4981
|
-
_getNumericFilters: function(state, facetName) {
|
|
5311
|
+
_getNumericFilters: function (state, facetName) {
|
|
4982
5312
|
if (state.numericFilters) {
|
|
4983
5313
|
return state.numericFilters;
|
|
4984
5314
|
}
|
|
4985
5315
|
|
|
4986
5316
|
var numericFilters = [];
|
|
4987
5317
|
|
|
4988
|
-
Object.keys(state.numericRefinements).forEach(function(attribute) {
|
|
5318
|
+
Object.keys(state.numericRefinements).forEach(function (attribute) {
|
|
4989
5319
|
var operators = state.numericRefinements[attribute] || {};
|
|
4990
|
-
Object.keys(operators).forEach(function(operator) {
|
|
5320
|
+
Object.keys(operators).forEach(function (operator) {
|
|
4991
5321
|
var values = operators[operator] || [];
|
|
4992
5322
|
if (facetName !== attribute) {
|
|
4993
|
-
values.forEach(function(value) {
|
|
5323
|
+
values.forEach(function (value) {
|
|
4994
5324
|
if (Array.isArray(value)) {
|
|
4995
|
-
var vs = value.map(function(v) {
|
|
5325
|
+
var vs = value.map(function (v) {
|
|
4996
5326
|
return attribute + operator + v;
|
|
4997
5327
|
});
|
|
4998
5328
|
numericFilters.push(vs);
|
|
@@ -5008,11 +5338,12 @@
|
|
|
5008
5338
|
},
|
|
5009
5339
|
|
|
5010
5340
|
/**
|
|
5011
|
-
* Return the tags filters depending
|
|
5341
|
+
* Return the tags filters depending on which format is used, either tagFilters or tagRefinements
|
|
5012
5342
|
* @private
|
|
5013
|
-
* @
|
|
5343
|
+
* @param {SearchParameters} state the state from which to get the filters
|
|
5344
|
+
* @return {string} Tag filters in a single string
|
|
5014
5345
|
*/
|
|
5015
|
-
_getTagFilters: function(state) {
|
|
5346
|
+
_getTagFilters: function (state) {
|
|
5016
5347
|
if (state.tagFilters) {
|
|
5017
5348
|
return state.tagFilters;
|
|
5018
5349
|
}
|
|
@@ -5020,50 +5351,52 @@
|
|
|
5020
5351
|
return state.tagRefinements.join(',');
|
|
5021
5352
|
},
|
|
5022
5353
|
|
|
5023
|
-
|
|
5024
5354
|
/**
|
|
5025
5355
|
* Build facetFilters parameter based on current refinements. The array returned
|
|
5026
5356
|
* contains strings representing the facet filters in the algolia format.
|
|
5027
5357
|
* @private
|
|
5358
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
5028
5359
|
* @param {string} [facet] if set, the current disjunctive facet
|
|
5029
|
-
* @
|
|
5360
|
+
* @param {boolean} [hierarchicalRootLevel] ?? FIXME
|
|
5361
|
+
* @return {array.<string>} The facet filters in the algolia format
|
|
5030
5362
|
*/
|
|
5031
|
-
_getFacetFilters: function(state, facet, hierarchicalRootLevel) {
|
|
5363
|
+
_getFacetFilters: function (state, facet, hierarchicalRootLevel) {
|
|
5032
5364
|
var facetFilters = [];
|
|
5033
5365
|
|
|
5034
5366
|
var facetsRefinements = state.facetsRefinements || {};
|
|
5035
|
-
Object.keys(facetsRefinements).forEach(function(facetName) {
|
|
5367
|
+
Object.keys(facetsRefinements).forEach(function (facetName) {
|
|
5036
5368
|
var facetValues = facetsRefinements[facetName] || [];
|
|
5037
|
-
facetValues.forEach(function(facetValue) {
|
|
5369
|
+
facetValues.forEach(function (facetValue) {
|
|
5038
5370
|
facetFilters.push(facetName + ':' + facetValue);
|
|
5039
5371
|
});
|
|
5040
5372
|
});
|
|
5041
5373
|
|
|
5042
5374
|
var facetsExcludes = state.facetsExcludes || {};
|
|
5043
|
-
Object.keys(facetsExcludes).forEach(function(facetName) {
|
|
5375
|
+
Object.keys(facetsExcludes).forEach(function (facetName) {
|
|
5044
5376
|
var facetValues = facetsExcludes[facetName] || [];
|
|
5045
|
-
facetValues.forEach(function(facetValue) {
|
|
5377
|
+
facetValues.forEach(function (facetValue) {
|
|
5046
5378
|
facetFilters.push(facetName + ':-' + facetValue);
|
|
5047
5379
|
});
|
|
5048
5380
|
});
|
|
5049
5381
|
|
|
5050
5382
|
var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
|
|
5051
|
-
Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
|
|
5383
|
+
Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
|
|
5052
5384
|
var facetValues = disjunctiveFacetsRefinements[facetName] || [];
|
|
5053
5385
|
if (facetName === facet || !facetValues || facetValues.length === 0) {
|
|
5054
5386
|
return;
|
|
5055
5387
|
}
|
|
5056
5388
|
var orFilters = [];
|
|
5057
5389
|
|
|
5058
|
-
facetValues.forEach(function(facetValue) {
|
|
5390
|
+
facetValues.forEach(function (facetValue) {
|
|
5059
5391
|
orFilters.push(facetName + ':' + facetValue);
|
|
5060
5392
|
});
|
|
5061
5393
|
|
|
5062
5394
|
facetFilters.push(orFilters);
|
|
5063
5395
|
});
|
|
5064
5396
|
|
|
5065
|
-
var hierarchicalFacetsRefinements =
|
|
5066
|
-
|
|
5397
|
+
var hierarchicalFacetsRefinements =
|
|
5398
|
+
state.hierarchicalFacetsRefinements || {};
|
|
5399
|
+
Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
|
|
5067
5400
|
var facetValues = hierarchicalFacetsRefinements[facetName] || [];
|
|
5068
5401
|
var facetValue = facetValues[0];
|
|
5069
5402
|
|
|
@@ -5081,8 +5414,13 @@
|
|
|
5081
5414
|
if (facet === facetName) {
|
|
5082
5415
|
// if we are at the root level already, no need to ask for facet values, we get them from
|
|
5083
5416
|
// the hits query
|
|
5084
|
-
if (
|
|
5085
|
-
|
|
5417
|
+
if (
|
|
5418
|
+
facetValue.indexOf(separator) === -1 ||
|
|
5419
|
+
(!rootPath && hierarchicalRootLevel === true) ||
|
|
5420
|
+
(rootPath &&
|
|
5421
|
+
rootPath.split(separator).length ===
|
|
5422
|
+
facetValue.split(separator).length)
|
|
5423
|
+
) {
|
|
5086
5424
|
return;
|
|
5087
5425
|
}
|
|
5088
5426
|
|
|
@@ -5109,13 +5447,18 @@
|
|
|
5109
5447
|
return facetFilters;
|
|
5110
5448
|
},
|
|
5111
5449
|
|
|
5112
|
-
_getHitsHierarchicalFacetsAttributes: function(state) {
|
|
5450
|
+
_getHitsHierarchicalFacetsAttributes: function (state) {
|
|
5113
5451
|
var out = [];
|
|
5114
5452
|
|
|
5115
5453
|
return state.hierarchicalFacets.reduce(
|
|
5116
5454
|
// ask for as much levels as there's hierarchical refinements
|
|
5117
|
-
function getHitsAttributesForHierarchicalFacet(
|
|
5118
|
-
|
|
5455
|
+
function getHitsAttributesForHierarchicalFacet(
|
|
5456
|
+
allAttributes,
|
|
5457
|
+
hierarchicalFacet
|
|
5458
|
+
) {
|
|
5459
|
+
var hierarchicalRefinement = state.getHierarchicalRefinement(
|
|
5460
|
+
hierarchicalFacet.name
|
|
5461
|
+
)[0];
|
|
5119
5462
|
|
|
5120
5463
|
// if no refinement, ask for root level
|
|
5121
5464
|
if (!hierarchicalRefinement) {
|
|
@@ -5128,10 +5471,16 @@
|
|
|
5128
5471
|
var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
|
|
5129
5472
|
|
|
5130
5473
|
return allAttributes.concat(newAttributes);
|
|
5131
|
-
},
|
|
5474
|
+
},
|
|
5475
|
+
out
|
|
5476
|
+
);
|
|
5132
5477
|
},
|
|
5133
5478
|
|
|
5134
|
-
_getDisjunctiveHierarchicalFacetAttribute: function(
|
|
5479
|
+
_getDisjunctiveHierarchicalFacetAttribute: function (
|
|
5480
|
+
state,
|
|
5481
|
+
hierarchicalFacet,
|
|
5482
|
+
rootLevel
|
|
5483
|
+
) {
|
|
5135
5484
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
5136
5485
|
if (rootLevel === true) {
|
|
5137
5486
|
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
|
|
@@ -5143,7 +5492,8 @@
|
|
|
5143
5492
|
return [hierarchicalFacet.attributes[attributeIndex]];
|
|
5144
5493
|
}
|
|
5145
5494
|
|
|
5146
|
-
var hierarchicalRefinement =
|
|
5495
|
+
var hierarchicalRefinement =
|
|
5496
|
+
state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
|
|
5147
5497
|
// if refinement is 'beers > IPA > Flying dog',
|
|
5148
5498
|
// then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
|
|
5149
5499
|
|
|
@@ -5151,28 +5501,30 @@
|
|
|
5151
5501
|
return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
|
|
5152
5502
|
},
|
|
5153
5503
|
|
|
5154
|
-
getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
|
|
5155
|
-
var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
|
|
5156
|
-
state.clearRefinements(facetName)
|
|
5157
|
-
state;
|
|
5504
|
+
getSearchForFacetQuery: function (facetName, query, maxFacetHits, state) {
|
|
5505
|
+
var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
|
|
5506
|
+
? state.clearRefinements(facetName)
|
|
5507
|
+
: state;
|
|
5158
5508
|
var searchForFacetSearchParameters = {
|
|
5159
5509
|
facetQuery: query,
|
|
5160
|
-
facetName: facetName
|
|
5510
|
+
facetName: facetName,
|
|
5161
5511
|
};
|
|
5162
5512
|
if (typeof maxFacetHits === 'number') {
|
|
5163
5513
|
searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
|
|
5164
5514
|
}
|
|
5165
|
-
return sortObject(
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5515
|
+
return sortObject(
|
|
5516
|
+
merge_1(
|
|
5517
|
+
{},
|
|
5518
|
+
requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
|
|
5519
|
+
searchForFacetSearchParameters
|
|
5520
|
+
)
|
|
5521
|
+
);
|
|
5522
|
+
},
|
|
5171
5523
|
};
|
|
5172
5524
|
|
|
5173
5525
|
var requestBuilder_1 = requestBuilder;
|
|
5174
5526
|
|
|
5175
|
-
var version$1 = '3.13.
|
|
5527
|
+
var version$1 = '3.13.5';
|
|
5176
5528
|
|
|
5177
5529
|
var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
|
|
5178
5530
|
|
|
@@ -5302,19 +5654,19 @@
|
|
|
5302
5654
|
* method is called, it triggers a `search` event. The results will
|
|
5303
5655
|
* be available through the `result` event. If an error occurs, an
|
|
5304
5656
|
* `error` will be fired instead.
|
|
5305
|
-
* @return {AlgoliaSearchHelper}
|
|
5657
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5306
5658
|
* @fires search
|
|
5307
5659
|
* @fires result
|
|
5308
5660
|
* @fires error
|
|
5309
5661
|
* @chainable
|
|
5310
5662
|
*/
|
|
5311
|
-
AlgoliaSearchHelper.prototype.search = function() {
|
|
5312
|
-
this._search({onlyWithDerivedHelpers: false});
|
|
5663
|
+
AlgoliaSearchHelper.prototype.search = function () {
|
|
5664
|
+
this._search({ onlyWithDerivedHelpers: false });
|
|
5313
5665
|
return this;
|
|
5314
5666
|
};
|
|
5315
5667
|
|
|
5316
|
-
AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
|
|
5317
|
-
this._search({onlyWithDerivedHelpers: true});
|
|
5668
|
+
AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
|
|
5669
|
+
this._search({ onlyWithDerivedHelpers: true });
|
|
5318
5670
|
return this;
|
|
5319
5671
|
};
|
|
5320
5672
|
|
|
@@ -5323,7 +5675,7 @@
|
|
|
5323
5675
|
* for the hits
|
|
5324
5676
|
* @return {object} Query Parameters
|
|
5325
5677
|
*/
|
|
5326
|
-
AlgoliaSearchHelper.prototype.getQuery = function() {
|
|
5678
|
+
AlgoliaSearchHelper.prototype.getQuery = function () {
|
|
5327
5679
|
var state = this.state;
|
|
5328
5680
|
return requestBuilder_1._getHitsSearchParams(state);
|
|
5329
5681
|
};
|
|
@@ -5335,7 +5687,7 @@
|
|
|
5335
5687
|
* same as a search call before calling searchOnce.
|
|
5336
5688
|
* @param {object} options can contain all the parameters that can be set to SearchParameters
|
|
5337
5689
|
* plus the index
|
|
5338
|
-
* @param {function} [
|
|
5690
|
+
* @param {function} [cb] optional callback executed when the response from the
|
|
5339
5691
|
* server is back.
|
|
5340
5692
|
* @return {promise|undefined} if a callback is passed the method returns undefined
|
|
5341
5693
|
* otherwise it returns a promise containing an object with two keys :
|
|
@@ -5364,21 +5716,24 @@
|
|
|
5364
5716
|
* // }
|
|
5365
5717
|
* }
|
|
5366
5718
|
*/
|
|
5367
|
-
AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
|
|
5368
|
-
var tempState = !options
|
|
5719
|
+
AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
|
|
5720
|
+
var tempState = !options
|
|
5721
|
+
? this.state
|
|
5722
|
+
: this.state.setQueryParameters(options);
|
|
5369
5723
|
var queries = requestBuilder_1._getQueries(tempState.index, tempState);
|
|
5724
|
+
// eslint-disable-next-line consistent-this
|
|
5370
5725
|
var self = this;
|
|
5371
5726
|
|
|
5372
5727
|
this._currentNbQueries++;
|
|
5373
5728
|
|
|
5374
5729
|
this.emit('searchOnce', {
|
|
5375
|
-
state: tempState
|
|
5730
|
+
state: tempState,
|
|
5376
5731
|
});
|
|
5377
5732
|
|
|
5378
5733
|
if (cb) {
|
|
5379
5734
|
this.client
|
|
5380
5735
|
.search(queries)
|
|
5381
|
-
.then(function(content) {
|
|
5736
|
+
.then(function (content) {
|
|
5382
5737
|
self._currentNbQueries--;
|
|
5383
5738
|
if (self._currentNbQueries === 0) {
|
|
5384
5739
|
self.emit('searchQueueEmpty');
|
|
@@ -5386,7 +5741,7 @@
|
|
|
5386
5741
|
|
|
5387
5742
|
cb(null, new SearchResults_1(tempState, content.results), tempState);
|
|
5388
5743
|
})
|
|
5389
|
-
.catch(function(err) {
|
|
5744
|
+
.catch(function (err) {
|
|
5390
5745
|
self._currentNbQueries--;
|
|
5391
5746
|
if (self._currentNbQueries === 0) {
|
|
5392
5747
|
self.emit('searchQueueEmpty');
|
|
@@ -5398,22 +5753,25 @@
|
|
|
5398
5753
|
return undefined;
|
|
5399
5754
|
}
|
|
5400
5755
|
|
|
5401
|
-
return this.client.search(queries).then(
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5756
|
+
return this.client.search(queries).then(
|
|
5757
|
+
function (content) {
|
|
5758
|
+
self._currentNbQueries--;
|
|
5759
|
+
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5760
|
+
return {
|
|
5761
|
+
content: new SearchResults_1(tempState, content.results),
|
|
5762
|
+
state: tempState,
|
|
5763
|
+
_originalResponse: content,
|
|
5764
|
+
};
|
|
5765
|
+
},
|
|
5766
|
+
function (e) {
|
|
5767
|
+
self._currentNbQueries--;
|
|
5768
|
+
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5769
|
+
throw e;
|
|
5770
|
+
}
|
|
5771
|
+
);
|
|
5414
5772
|
};
|
|
5415
5773
|
|
|
5416
|
-
|
|
5774
|
+
/**
|
|
5417
5775
|
* Start the search for answers with the parameters set in the state.
|
|
5418
5776
|
* This method returns a promise.
|
|
5419
5777
|
* @param {Object} options - the options for answers API call
|
|
@@ -5424,7 +5782,8 @@
|
|
|
5424
5782
|
* @return {promise} the answer results
|
|
5425
5783
|
* @deprecated answers is deprecated and will be replaced with new initiatives
|
|
5426
5784
|
*/
|
|
5427
|
-
AlgoliaSearchHelper.prototype.findAnswers = function(options) {
|
|
5785
|
+
AlgoliaSearchHelper.prototype.findAnswers = function (options) {
|
|
5786
|
+
// eslint-disable-next-line no-console
|
|
5428
5787
|
console.warn('[algoliasearch-helper] answers is no longer supported');
|
|
5429
5788
|
var state = this.state;
|
|
5430
5789
|
var derivedHelper = this.derivedHelpers[0];
|
|
@@ -5435,19 +5794,20 @@
|
|
|
5435
5794
|
var data = merge_1(
|
|
5436
5795
|
{
|
|
5437
5796
|
attributesForPrediction: options.attributesForPrediction,
|
|
5438
|
-
nbHits: options.nbHits
|
|
5797
|
+
nbHits: options.nbHits,
|
|
5439
5798
|
},
|
|
5440
5799
|
{
|
|
5441
5800
|
params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
|
|
5442
5801
|
'attributesToSnippet',
|
|
5443
5802
|
'hitsPerPage',
|
|
5444
5803
|
'restrictSearchableAttributes',
|
|
5445
|
-
'snippetEllipsisText'
|
|
5446
|
-
])
|
|
5804
|
+
'snippetEllipsisText',
|
|
5805
|
+
]),
|
|
5447
5806
|
}
|
|
5448
5807
|
);
|
|
5449
5808
|
|
|
5450
|
-
var errorMessage =
|
|
5809
|
+
var errorMessage =
|
|
5810
|
+
'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
|
|
5451
5811
|
if (typeof this.client.initIndex !== 'function') {
|
|
5452
5812
|
throw new Error(errorMessage);
|
|
5453
5813
|
}
|
|
@@ -5492,7 +5852,12 @@
|
|
|
5492
5852
|
* it in the generated query.
|
|
5493
5853
|
* @return {promise.<FacetSearchResult>} the results of the search
|
|
5494
5854
|
*/
|
|
5495
|
-
AlgoliaSearchHelper.prototype.searchForFacetValues = function(
|
|
5855
|
+
AlgoliaSearchHelper.prototype.searchForFacetValues = function (
|
|
5856
|
+
facet,
|
|
5857
|
+
query,
|
|
5858
|
+
maxFacetHits,
|
|
5859
|
+
userState
|
|
5860
|
+
) {
|
|
5496
5861
|
var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
|
|
5497
5862
|
var clientHasInitIndex = typeof this.client.initIndex === 'function';
|
|
5498
5863
|
if (
|
|
@@ -5507,15 +5872,21 @@
|
|
|
5507
5872
|
|
|
5508
5873
|
var state = this.state.setQueryParameters(userState || {});
|
|
5509
5874
|
var isDisjunctive = state.isDisjunctiveFacet(facet);
|
|
5510
|
-
var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
|
|
5875
|
+
var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
|
|
5876
|
+
facet,
|
|
5877
|
+
query,
|
|
5878
|
+
maxFacetHits,
|
|
5879
|
+
state
|
|
5880
|
+
);
|
|
5511
5881
|
|
|
5512
5882
|
this._currentNbQueries++;
|
|
5883
|
+
// eslint-disable-next-line consistent-this
|
|
5513
5884
|
var self = this;
|
|
5514
5885
|
var searchForFacetValuesPromise;
|
|
5515
5886
|
// newer algoliasearch ^3.27.1 - ~4.0.0
|
|
5516
5887
|
if (clientHasSFFV) {
|
|
5517
5888
|
searchForFacetValuesPromise = this.client.searchForFacetValues([
|
|
5518
|
-
{indexName: state.index, params: algoliaQuery}
|
|
5889
|
+
{ indexName: state.index, params: algoliaQuery },
|
|
5519
5890
|
]);
|
|
5520
5891
|
// algoliasearch < 3.27.1
|
|
5521
5892
|
} else if (clientHasInitIndex) {
|
|
@@ -5532,8 +5903,8 @@
|
|
|
5532
5903
|
type: 'facet',
|
|
5533
5904
|
facet: facet,
|
|
5534
5905
|
indexName: state.index,
|
|
5535
|
-
params: algoliaQuery
|
|
5536
|
-
}
|
|
5906
|
+
params: algoliaQuery,
|
|
5907
|
+
},
|
|
5537
5908
|
])
|
|
5538
5909
|
.then(function processResponse(response) {
|
|
5539
5910
|
return response.results[0];
|
|
@@ -5543,28 +5914,31 @@
|
|
|
5543
5914
|
this.emit('searchForFacetValues', {
|
|
5544
5915
|
state: state,
|
|
5545
5916
|
facet: facet,
|
|
5546
|
-
query: query
|
|
5917
|
+
query: query,
|
|
5547
5918
|
});
|
|
5548
5919
|
|
|
5549
|
-
return searchForFacetValuesPromise.then(
|
|
5550
|
-
|
|
5551
|
-
|
|
5920
|
+
return searchForFacetValuesPromise.then(
|
|
5921
|
+
function addIsRefined(content) {
|
|
5922
|
+
self._currentNbQueries--;
|
|
5923
|
+
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5552
5924
|
|
|
5553
|
-
|
|
5925
|
+
content = Array.isArray(content) ? content[0] : content;
|
|
5554
5926
|
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5927
|
+
content.facetHits.forEach(function (f) {
|
|
5928
|
+
f.escapedValue = escapeFacetValue$3(f.value);
|
|
5929
|
+
f.isRefined = isDisjunctive
|
|
5930
|
+
? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
|
|
5931
|
+
: state.isFacetRefined(facet, f.escapedValue);
|
|
5932
|
+
});
|
|
5561
5933
|
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5934
|
+
return content;
|
|
5935
|
+
},
|
|
5936
|
+
function (e) {
|
|
5937
|
+
self._currentNbQueries--;
|
|
5938
|
+
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5939
|
+
throw e;
|
|
5940
|
+
}
|
|
5941
|
+
);
|
|
5568
5942
|
};
|
|
5569
5943
|
|
|
5570
5944
|
/**
|
|
@@ -5572,14 +5946,14 @@
|
|
|
5572
5946
|
*
|
|
5573
5947
|
* This method resets the current page to 0.
|
|
5574
5948
|
* @param {string} q the user query
|
|
5575
|
-
* @return {AlgoliaSearchHelper}
|
|
5949
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5576
5950
|
* @fires change
|
|
5577
5951
|
* @chainable
|
|
5578
5952
|
*/
|
|
5579
|
-
AlgoliaSearchHelper.prototype.setQuery = function(q) {
|
|
5953
|
+
AlgoliaSearchHelper.prototype.setQuery = function (q) {
|
|
5580
5954
|
this._change({
|
|
5581
5955
|
state: this.state.resetPage().setQuery(q),
|
|
5582
|
-
isPageReset: true
|
|
5956
|
+
isPageReset: true,
|
|
5583
5957
|
});
|
|
5584
5958
|
|
|
5585
5959
|
return this;
|
|
@@ -5593,7 +5967,7 @@
|
|
|
5593
5967
|
*
|
|
5594
5968
|
* This method resets the current page to 0.
|
|
5595
5969
|
* @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
|
|
5596
|
-
* @return {AlgoliaSearchHelper}
|
|
5970
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5597
5971
|
* @fires change
|
|
5598
5972
|
* @chainable
|
|
5599
5973
|
* @example
|
|
@@ -5608,10 +5982,10 @@
|
|
|
5608
5982
|
* return type === 'exclude' && attribute === 'category';
|
|
5609
5983
|
* }).search();
|
|
5610
5984
|
*/
|
|
5611
|
-
AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
|
|
5985
|
+
AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
|
|
5612
5986
|
this._change({
|
|
5613
5987
|
state: this.state.resetPage().clearRefinements(name),
|
|
5614
|
-
isPageReset: true
|
|
5988
|
+
isPageReset: true,
|
|
5615
5989
|
});
|
|
5616
5990
|
|
|
5617
5991
|
return this;
|
|
@@ -5621,14 +5995,14 @@
|
|
|
5621
5995
|
* Remove all the tag filters.
|
|
5622
5996
|
*
|
|
5623
5997
|
* This method resets the current page to 0.
|
|
5624
|
-
* @return {AlgoliaSearchHelper}
|
|
5998
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5625
5999
|
* @fires change
|
|
5626
6000
|
* @chainable
|
|
5627
6001
|
*/
|
|
5628
|
-
AlgoliaSearchHelper.prototype.clearTags = function() {
|
|
6002
|
+
AlgoliaSearchHelper.prototype.clearTags = function () {
|
|
5629
6003
|
this._change({
|
|
5630
6004
|
state: this.state.resetPage().clearTags(),
|
|
5631
|
-
isPageReset: true
|
|
6005
|
+
isPageReset: true,
|
|
5632
6006
|
});
|
|
5633
6007
|
|
|
5634
6008
|
return this;
|
|
@@ -5641,23 +6015,27 @@
|
|
|
5641
6015
|
* This method resets the current page to 0.
|
|
5642
6016
|
* @param {string} facet the facet to refine
|
|
5643
6017
|
* @param {string} value the associated value (will be converted to string)
|
|
5644
|
-
* @return {AlgoliaSearchHelper}
|
|
6018
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5645
6019
|
* @fires change
|
|
5646
6020
|
* @chainable
|
|
5647
6021
|
*/
|
|
5648
|
-
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(
|
|
6022
|
+
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
|
|
6023
|
+
facet,
|
|
6024
|
+
value
|
|
6025
|
+
) {
|
|
5649
6026
|
this._change({
|
|
5650
6027
|
state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
|
|
5651
|
-
isPageReset: true
|
|
6028
|
+
isPageReset: true,
|
|
5652
6029
|
});
|
|
5653
6030
|
|
|
5654
6031
|
return this;
|
|
5655
6032
|
};
|
|
5656
6033
|
|
|
6034
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5657
6035
|
/**
|
|
5658
6036
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
|
|
5659
6037
|
*/
|
|
5660
|
-
AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
|
|
6038
|
+
AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
|
|
5661
6039
|
return this.addDisjunctiveFacetRefinement.apply(this, arguments);
|
|
5662
6040
|
};
|
|
5663
6041
|
|
|
@@ -5669,15 +6047,18 @@
|
|
|
5669
6047
|
* This method resets the current page to 0.
|
|
5670
6048
|
* @param {string} facet the facet name
|
|
5671
6049
|
* @param {string} path the hierarchical facet path
|
|
5672
|
-
* @return {AlgoliaSearchHelper}
|
|
6050
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5673
6051
|
* @throws Error if the facet is not defined or if the facet is refined
|
|
5674
6052
|
* @chainable
|
|
5675
6053
|
* @fires change
|
|
5676
6054
|
*/
|
|
5677
|
-
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(
|
|
6055
|
+
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
|
|
6056
|
+
facet,
|
|
6057
|
+
path
|
|
6058
|
+
) {
|
|
5678
6059
|
this._change({
|
|
5679
|
-
state: this.state.resetPage().addHierarchicalFacetRefinement(facet,
|
|
5680
|
-
isPageReset: true
|
|
6060
|
+
state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
|
|
6061
|
+
isPageReset: true,
|
|
5681
6062
|
});
|
|
5682
6063
|
|
|
5683
6064
|
return this;
|
|
@@ -5691,14 +6072,20 @@
|
|
|
5691
6072
|
* @param {string} attribute the attribute on which the numeric filter applies
|
|
5692
6073
|
* @param {string} operator the operator of the filter
|
|
5693
6074
|
* @param {number} value the value of the filter
|
|
5694
|
-
* @return {AlgoliaSearchHelper}
|
|
6075
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5695
6076
|
* @fires change
|
|
5696
6077
|
* @chainable
|
|
5697
6078
|
*/
|
|
5698
|
-
AlgoliaSearchHelper.prototype.addNumericRefinement = function(
|
|
6079
|
+
AlgoliaSearchHelper.prototype.addNumericRefinement = function (
|
|
6080
|
+
attribute,
|
|
6081
|
+
operator,
|
|
6082
|
+
value
|
|
6083
|
+
) {
|
|
5699
6084
|
this._change({
|
|
5700
|
-
state: this.state
|
|
5701
|
-
|
|
6085
|
+
state: this.state
|
|
6086
|
+
.resetPage()
|
|
6087
|
+
.addNumericRefinement(attribute, operator, value),
|
|
6088
|
+
isPageReset: true,
|
|
5702
6089
|
});
|
|
5703
6090
|
|
|
5704
6091
|
return this;
|
|
@@ -5711,27 +6098,27 @@
|
|
|
5711
6098
|
* This method resets the current page to 0.
|
|
5712
6099
|
* @param {string} facet the facet to refine
|
|
5713
6100
|
* @param {string} value the associated value (will be converted to string)
|
|
5714
|
-
* @return {AlgoliaSearchHelper}
|
|
6101
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5715
6102
|
* @fires change
|
|
5716
6103
|
* @chainable
|
|
5717
6104
|
*/
|
|
5718
|
-
AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
|
|
6105
|
+
AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
|
|
5719
6106
|
this._change({
|
|
5720
6107
|
state: this.state.resetPage().addFacetRefinement(facet, value),
|
|
5721
|
-
isPageReset: true
|
|
6108
|
+
isPageReset: true,
|
|
5722
6109
|
});
|
|
5723
6110
|
|
|
5724
6111
|
return this;
|
|
5725
6112
|
};
|
|
5726
6113
|
|
|
6114
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5727
6115
|
/**
|
|
5728
6116
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
|
|
5729
6117
|
*/
|
|
5730
|
-
AlgoliaSearchHelper.prototype.addRefine = function() {
|
|
6118
|
+
AlgoliaSearchHelper.prototype.addRefine = function () {
|
|
5731
6119
|
return this.addFacetRefinement.apply(this, arguments);
|
|
5732
6120
|
};
|
|
5733
6121
|
|
|
5734
|
-
|
|
5735
6122
|
/**
|
|
5736
6123
|
* Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
|
|
5737
6124
|
* filter is already set, it doesn't change the filters.
|
|
@@ -5739,23 +6126,24 @@
|
|
|
5739
6126
|
* This method resets the current page to 0.
|
|
5740
6127
|
* @param {string} facet the facet to refine
|
|
5741
6128
|
* @param {string} value the associated value (will be converted to string)
|
|
5742
|
-
* @return {AlgoliaSearchHelper}
|
|
6129
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5743
6130
|
* @fires change
|
|
5744
6131
|
* @chainable
|
|
5745
6132
|
*/
|
|
5746
|
-
AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
|
|
6133
|
+
AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
|
|
5747
6134
|
this._change({
|
|
5748
6135
|
state: this.state.resetPage().addExcludeRefinement(facet, value),
|
|
5749
|
-
isPageReset: true
|
|
6136
|
+
isPageReset: true,
|
|
5750
6137
|
});
|
|
5751
6138
|
|
|
5752
6139
|
return this;
|
|
5753
6140
|
};
|
|
5754
6141
|
|
|
6142
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5755
6143
|
/**
|
|
5756
6144
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
|
|
5757
6145
|
*/
|
|
5758
|
-
AlgoliaSearchHelper.prototype.addExclude = function() {
|
|
6146
|
+
AlgoliaSearchHelper.prototype.addExclude = function () {
|
|
5759
6147
|
return this.addFacetExclusion.apply(this, arguments);
|
|
5760
6148
|
};
|
|
5761
6149
|
|
|
@@ -5765,14 +6153,14 @@
|
|
|
5765
6153
|
*
|
|
5766
6154
|
* This method resets the current page to 0.
|
|
5767
6155
|
* @param {string} tag the tag to add to the filter
|
|
5768
|
-
* @return {AlgoliaSearchHelper}
|
|
6156
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5769
6157
|
* @fires change
|
|
5770
6158
|
* @chainable
|
|
5771
6159
|
*/
|
|
5772
|
-
AlgoliaSearchHelper.prototype.addTag = function(tag) {
|
|
6160
|
+
AlgoliaSearchHelper.prototype.addTag = function (tag) {
|
|
5773
6161
|
this._change({
|
|
5774
6162
|
state: this.state.resetPage().addTagRefinement(tag),
|
|
5775
|
-
isPageReset: true
|
|
6163
|
+
isPageReset: true,
|
|
5776
6164
|
});
|
|
5777
6165
|
|
|
5778
6166
|
return this;
|
|
@@ -5792,14 +6180,20 @@
|
|
|
5792
6180
|
* @param {string} attribute the attribute on which the numeric filter applies
|
|
5793
6181
|
* @param {string} [operator] the operator of the filter
|
|
5794
6182
|
* @param {number} [value] the value of the filter
|
|
5795
|
-
* @return {AlgoliaSearchHelper}
|
|
6183
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5796
6184
|
* @fires change
|
|
5797
6185
|
* @chainable
|
|
5798
6186
|
*/
|
|
5799
|
-
AlgoliaSearchHelper.prototype.removeNumericRefinement = function(
|
|
6187
|
+
AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
|
|
6188
|
+
attribute,
|
|
6189
|
+
operator,
|
|
6190
|
+
value
|
|
6191
|
+
) {
|
|
5800
6192
|
this._change({
|
|
5801
|
-
state: this.state
|
|
5802
|
-
|
|
6193
|
+
state: this.state
|
|
6194
|
+
.resetPage()
|
|
6195
|
+
.removeNumericRefinement(attribute, operator, value),
|
|
6196
|
+
isPageReset: true,
|
|
5803
6197
|
});
|
|
5804
6198
|
|
|
5805
6199
|
return this;
|
|
@@ -5815,38 +6209,46 @@
|
|
|
5815
6209
|
* This method resets the current page to 0.
|
|
5816
6210
|
* @param {string} facet the facet to refine
|
|
5817
6211
|
* @param {string} [value] the associated value
|
|
5818
|
-
* @return {AlgoliaSearchHelper}
|
|
6212
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5819
6213
|
* @fires change
|
|
5820
6214
|
* @chainable
|
|
5821
6215
|
*/
|
|
5822
|
-
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(
|
|
6216
|
+
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
|
|
6217
|
+
facet,
|
|
6218
|
+
value
|
|
6219
|
+
) {
|
|
5823
6220
|
this._change({
|
|
5824
|
-
state: this.state
|
|
5825
|
-
|
|
6221
|
+
state: this.state
|
|
6222
|
+
.resetPage()
|
|
6223
|
+
.removeDisjunctiveFacetRefinement(facet, value),
|
|
6224
|
+
isPageReset: true,
|
|
5826
6225
|
});
|
|
5827
6226
|
|
|
5828
6227
|
return this;
|
|
5829
6228
|
};
|
|
5830
6229
|
|
|
6230
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5831
6231
|
/**
|
|
5832
6232
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
|
|
5833
6233
|
*/
|
|
5834
|
-
AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
|
|
6234
|
+
AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
|
|
5835
6235
|
return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
|
|
5836
6236
|
};
|
|
5837
6237
|
|
|
5838
6238
|
/**
|
|
5839
6239
|
* Removes the refinement set on a hierarchical facet.
|
|
5840
6240
|
* @param {string} facet the facet name
|
|
5841
|
-
* @return {AlgoliaSearchHelper}
|
|
6241
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5842
6242
|
* @throws Error if the facet is not defined or if the facet is not refined
|
|
5843
6243
|
* @fires change
|
|
5844
6244
|
* @chainable
|
|
5845
6245
|
*/
|
|
5846
|
-
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(
|
|
6246
|
+
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
|
|
6247
|
+
facet
|
|
6248
|
+
) {
|
|
5847
6249
|
this._change({
|
|
5848
6250
|
state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
|
|
5849
|
-
isPageReset: true
|
|
6251
|
+
isPageReset: true,
|
|
5850
6252
|
});
|
|
5851
6253
|
|
|
5852
6254
|
return this;
|
|
@@ -5862,23 +6264,24 @@
|
|
|
5862
6264
|
* This method resets the current page to 0.
|
|
5863
6265
|
* @param {string} facet the facet to refine
|
|
5864
6266
|
* @param {string} [value] the associated value
|
|
5865
|
-
* @return {AlgoliaSearchHelper}
|
|
6267
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5866
6268
|
* @fires change
|
|
5867
6269
|
* @chainable
|
|
5868
6270
|
*/
|
|
5869
|
-
AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
|
|
6271
|
+
AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
|
|
5870
6272
|
this._change({
|
|
5871
6273
|
state: this.state.resetPage().removeFacetRefinement(facet, value),
|
|
5872
|
-
isPageReset: true
|
|
6274
|
+
isPageReset: true,
|
|
5873
6275
|
});
|
|
5874
6276
|
|
|
5875
6277
|
return this;
|
|
5876
6278
|
};
|
|
5877
6279
|
|
|
6280
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5878
6281
|
/**
|
|
5879
6282
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
|
|
5880
6283
|
*/
|
|
5881
|
-
AlgoliaSearchHelper.prototype.removeRefine = function() {
|
|
6284
|
+
AlgoliaSearchHelper.prototype.removeRefine = function () {
|
|
5882
6285
|
return this.removeFacetRefinement.apply(this, arguments);
|
|
5883
6286
|
};
|
|
5884
6287
|
|
|
@@ -5892,23 +6295,24 @@
|
|
|
5892
6295
|
* This method resets the current page to 0.
|
|
5893
6296
|
* @param {string} facet the facet to refine
|
|
5894
6297
|
* @param {string} [value] the associated value
|
|
5895
|
-
* @return {AlgoliaSearchHelper}
|
|
6298
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5896
6299
|
* @fires change
|
|
5897
6300
|
* @chainable
|
|
5898
6301
|
*/
|
|
5899
|
-
AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
|
|
6302
|
+
AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
|
|
5900
6303
|
this._change({
|
|
5901
6304
|
state: this.state.resetPage().removeExcludeRefinement(facet, value),
|
|
5902
|
-
isPageReset: true
|
|
6305
|
+
isPageReset: true,
|
|
5903
6306
|
});
|
|
5904
6307
|
|
|
5905
6308
|
return this;
|
|
5906
6309
|
};
|
|
5907
6310
|
|
|
6311
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5908
6312
|
/**
|
|
5909
6313
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
|
|
5910
6314
|
*/
|
|
5911
|
-
AlgoliaSearchHelper.prototype.removeExclude = function() {
|
|
6315
|
+
AlgoliaSearchHelper.prototype.removeExclude = function () {
|
|
5912
6316
|
return this.removeFacetExclusion.apply(this, arguments);
|
|
5913
6317
|
};
|
|
5914
6318
|
|
|
@@ -5918,14 +6322,14 @@
|
|
|
5918
6322
|
*
|
|
5919
6323
|
* This method resets the current page to 0.
|
|
5920
6324
|
* @param {string} tag tag to remove from the filter
|
|
5921
|
-
* @return {AlgoliaSearchHelper}
|
|
6325
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5922
6326
|
* @fires change
|
|
5923
6327
|
* @chainable
|
|
5924
6328
|
*/
|
|
5925
|
-
AlgoliaSearchHelper.prototype.removeTag = function(tag) {
|
|
6329
|
+
AlgoliaSearchHelper.prototype.removeTag = function (tag) {
|
|
5926
6330
|
this._change({
|
|
5927
6331
|
state: this.state.resetPage().removeTagRefinement(tag),
|
|
5928
|
-
isPageReset: true
|
|
6332
|
+
isPageReset: true,
|
|
5929
6333
|
});
|
|
5930
6334
|
|
|
5931
6335
|
return this;
|
|
@@ -5938,23 +6342,24 @@
|
|
|
5938
6342
|
* This method resets the current page to 0.
|
|
5939
6343
|
* @param {string} facet the facet to refine
|
|
5940
6344
|
* @param {string} value the associated value
|
|
5941
|
-
* @return {AlgoliaSearchHelper}
|
|
6345
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5942
6346
|
* @fires change
|
|
5943
6347
|
* @chainable
|
|
5944
6348
|
*/
|
|
5945
|
-
AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
|
|
6349
|
+
AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
|
|
5946
6350
|
this._change({
|
|
5947
6351
|
state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
|
|
5948
|
-
isPageReset: true
|
|
6352
|
+
isPageReset: true,
|
|
5949
6353
|
});
|
|
5950
6354
|
|
|
5951
6355
|
return this;
|
|
5952
6356
|
};
|
|
5953
6357
|
|
|
6358
|
+
// eslint-disable-next-line valid-jsdoc
|
|
5954
6359
|
/**
|
|
5955
6360
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
|
|
5956
6361
|
*/
|
|
5957
|
-
AlgoliaSearchHelper.prototype.toggleExclude = function() {
|
|
6362
|
+
AlgoliaSearchHelper.prototype.toggleExclude = function () {
|
|
5958
6363
|
return this.toggleFacetExclusion.apply(this, arguments);
|
|
5959
6364
|
};
|
|
5960
6365
|
|
|
@@ -5967,13 +6372,13 @@
|
|
|
5967
6372
|
* This method resets the current page to 0.
|
|
5968
6373
|
* @param {string} facet the facet to refine
|
|
5969
6374
|
* @param {string} value the associated value
|
|
5970
|
-
* @return {AlgoliaSearchHelper}
|
|
6375
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5971
6376
|
* @throws Error will throw an error if the facet is not declared in the settings of the helper
|
|
5972
6377
|
* @fires change
|
|
5973
6378
|
* @chainable
|
|
5974
6379
|
* @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
|
|
5975
6380
|
*/
|
|
5976
|
-
AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
|
|
6381
|
+
AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
|
|
5977
6382
|
return this.toggleFacetRefinement(facet, value);
|
|
5978
6383
|
};
|
|
5979
6384
|
|
|
@@ -5986,24 +6391,25 @@
|
|
|
5986
6391
|
* This method resets the current page to 0.
|
|
5987
6392
|
* @param {string} facet the facet to refine
|
|
5988
6393
|
* @param {string} value the associated value
|
|
5989
|
-
* @return {AlgoliaSearchHelper}
|
|
6394
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5990
6395
|
* @throws Error will throw an error if the facet is not declared in the settings of the helper
|
|
5991
6396
|
* @fires change
|
|
5992
6397
|
* @chainable
|
|
5993
6398
|
*/
|
|
5994
|
-
AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
|
|
6399
|
+
AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
|
|
5995
6400
|
this._change({
|
|
5996
6401
|
state: this.state.resetPage().toggleFacetRefinement(facet, value),
|
|
5997
|
-
isPageReset: true
|
|
6402
|
+
isPageReset: true,
|
|
5998
6403
|
});
|
|
5999
6404
|
|
|
6000
6405
|
return this;
|
|
6001
6406
|
};
|
|
6002
6407
|
|
|
6408
|
+
// eslint-disable-next-line valid-jsdoc
|
|
6003
6409
|
/**
|
|
6004
6410
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
|
|
6005
6411
|
*/
|
|
6006
|
-
AlgoliaSearchHelper.prototype.toggleRefine = function() {
|
|
6412
|
+
AlgoliaSearchHelper.prototype.toggleRefine = function () {
|
|
6007
6413
|
return this.toggleFacetRefinement.apply(this, arguments);
|
|
6008
6414
|
};
|
|
6009
6415
|
|
|
@@ -6013,14 +6419,14 @@
|
|
|
6013
6419
|
*
|
|
6014
6420
|
* This method resets the current page to 0.
|
|
6015
6421
|
* @param {string} tag tag to remove or add
|
|
6016
|
-
* @return {AlgoliaSearchHelper}
|
|
6422
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6017
6423
|
* @fires change
|
|
6018
6424
|
* @chainable
|
|
6019
6425
|
*/
|
|
6020
|
-
AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
|
|
6426
|
+
AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
|
|
6021
6427
|
this._change({
|
|
6022
6428
|
state: this.state.resetPage().toggleTagRefinement(tag),
|
|
6023
|
-
isPageReset: true
|
|
6429
|
+
isPageReset: true,
|
|
6024
6430
|
});
|
|
6025
6431
|
|
|
6026
6432
|
return this;
|
|
@@ -6028,14 +6434,14 @@
|
|
|
6028
6434
|
|
|
6029
6435
|
/**
|
|
6030
6436
|
* Increments the page number by one.
|
|
6031
|
-
* @return {AlgoliaSearchHelper}
|
|
6437
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6032
6438
|
* @fires change
|
|
6033
6439
|
* @chainable
|
|
6034
6440
|
* @example
|
|
6035
6441
|
* helper.setPage(0).nextPage().getPage();
|
|
6036
6442
|
* // returns 1
|
|
6037
6443
|
*/
|
|
6038
|
-
AlgoliaSearchHelper.prototype.nextPage = function() {
|
|
6444
|
+
AlgoliaSearchHelper.prototype.nextPage = function () {
|
|
6039
6445
|
var page = this.state.page || 0;
|
|
6040
6446
|
return this.setPage(page + 1);
|
|
6041
6447
|
};
|
|
@@ -6043,26 +6449,30 @@
|
|
|
6043
6449
|
/**
|
|
6044
6450
|
* Decrements the page number by one.
|
|
6045
6451
|
* @fires change
|
|
6046
|
-
* @return {AlgoliaSearchHelper}
|
|
6452
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6047
6453
|
* @chainable
|
|
6048
6454
|
* @example
|
|
6049
6455
|
* helper.setPage(1).previousPage().getPage();
|
|
6050
6456
|
* // returns 0
|
|
6051
6457
|
*/
|
|
6052
|
-
AlgoliaSearchHelper.prototype.previousPage = function() {
|
|
6458
|
+
AlgoliaSearchHelper.prototype.previousPage = function () {
|
|
6053
6459
|
var page = this.state.page || 0;
|
|
6054
6460
|
return this.setPage(page - 1);
|
|
6055
6461
|
};
|
|
6056
6462
|
|
|
6057
6463
|
/**
|
|
6058
6464
|
* @private
|
|
6465
|
+
* @param {number} page The page number
|
|
6466
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6467
|
+
* @chainable
|
|
6468
|
+
* @fires change
|
|
6059
6469
|
*/
|
|
6060
6470
|
function setCurrentPage(page) {
|
|
6061
6471
|
if (page < 0) throw new Error('Page requested below 0.');
|
|
6062
6472
|
|
|
6063
6473
|
this._change({
|
|
6064
6474
|
state: this.state.setPage(page),
|
|
6065
|
-
isPageReset: false
|
|
6475
|
+
isPageReset: false,
|
|
6066
6476
|
});
|
|
6067
6477
|
|
|
6068
6478
|
return this;
|
|
@@ -6072,7 +6482,7 @@
|
|
|
6072
6482
|
* Change the current page
|
|
6073
6483
|
* @deprecated
|
|
6074
6484
|
* @param {number} page The page number
|
|
6075
|
-
* @return {AlgoliaSearchHelper}
|
|
6485
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6076
6486
|
* @fires change
|
|
6077
6487
|
* @chainable
|
|
6078
6488
|
*/
|
|
@@ -6082,7 +6492,7 @@
|
|
|
6082
6492
|
* Updates the current page.
|
|
6083
6493
|
* @function
|
|
6084
6494
|
* @param {number} page The page number
|
|
6085
|
-
* @return {AlgoliaSearchHelper}
|
|
6495
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6086
6496
|
* @fires change
|
|
6087
6497
|
* @chainable
|
|
6088
6498
|
*/
|
|
@@ -6093,14 +6503,14 @@
|
|
|
6093
6503
|
*
|
|
6094
6504
|
* This method resets the current page to 0.
|
|
6095
6505
|
* @param {string} name the index name
|
|
6096
|
-
* @return {AlgoliaSearchHelper}
|
|
6506
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6097
6507
|
* @fires change
|
|
6098
6508
|
* @chainable
|
|
6099
6509
|
*/
|
|
6100
|
-
AlgoliaSearchHelper.prototype.setIndex = function(name) {
|
|
6510
|
+
AlgoliaSearchHelper.prototype.setIndex = function (name) {
|
|
6101
6511
|
this._change({
|
|
6102
6512
|
state: this.state.resetPage().setIndex(name),
|
|
6103
|
-
isPageReset: true
|
|
6513
|
+
isPageReset: true,
|
|
6104
6514
|
});
|
|
6105
6515
|
|
|
6106
6516
|
return this;
|
|
@@ -6117,16 +6527,16 @@
|
|
|
6117
6527
|
* This method resets the current page to 0.
|
|
6118
6528
|
* @param {string} parameter name of the parameter to update
|
|
6119
6529
|
* @param {any} value new value of the parameter
|
|
6120
|
-
* @return {AlgoliaSearchHelper}
|
|
6530
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6121
6531
|
* @fires change
|
|
6122
6532
|
* @chainable
|
|
6123
6533
|
* @example
|
|
6124
6534
|
* helper.setQueryParameter('hitsPerPage', 20).search();
|
|
6125
6535
|
*/
|
|
6126
|
-
AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
|
|
6536
|
+
AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
|
|
6127
6537
|
this._change({
|
|
6128
6538
|
state: this.state.resetPage().setQueryParameter(parameter, value),
|
|
6129
|
-
isPageReset: true
|
|
6539
|
+
isPageReset: true,
|
|
6130
6540
|
});
|
|
6131
6541
|
|
|
6132
6542
|
return this;
|
|
@@ -6135,14 +6545,14 @@
|
|
|
6135
6545
|
/**
|
|
6136
6546
|
* Set the whole state (warning: will erase previous state)
|
|
6137
6547
|
* @param {SearchParameters} newState the whole new state
|
|
6138
|
-
* @return {AlgoliaSearchHelper}
|
|
6548
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6139
6549
|
* @fires change
|
|
6140
6550
|
* @chainable
|
|
6141
6551
|
*/
|
|
6142
|
-
AlgoliaSearchHelper.prototype.setState = function(newState) {
|
|
6552
|
+
AlgoliaSearchHelper.prototype.setState = function (newState) {
|
|
6143
6553
|
this._change({
|
|
6144
6554
|
state: SearchParameters_1.make(newState),
|
|
6145
|
-
isPageReset: false
|
|
6555
|
+
isPageReset: false,
|
|
6146
6556
|
});
|
|
6147
6557
|
|
|
6148
6558
|
return this;
|
|
@@ -6153,7 +6563,7 @@
|
|
|
6153
6563
|
* Do not use this method unless you know what you are doing. (see the example
|
|
6154
6564
|
* for a legit use case)
|
|
6155
6565
|
* @param {SearchParameters} newState the whole new state
|
|
6156
|
-
* @return {AlgoliaSearchHelper}
|
|
6566
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6157
6567
|
* @example
|
|
6158
6568
|
* helper.on('change', function(state){
|
|
6159
6569
|
* // In this function you might want to find a way to store the state in the url/history
|
|
@@ -6165,10 +6575,11 @@
|
|
|
6165
6575
|
* }
|
|
6166
6576
|
* @chainable
|
|
6167
6577
|
*/
|
|
6168
|
-
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6578
|
+
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
|
|
6579
|
+
function (newState) {
|
|
6580
|
+
this.state = new SearchParameters_1(newState);
|
|
6581
|
+
return this;
|
|
6582
|
+
};
|
|
6172
6583
|
|
|
6173
6584
|
/**
|
|
6174
6585
|
* Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
|
|
@@ -6193,7 +6604,7 @@
|
|
|
6193
6604
|
* helper.hasRefinements('categories'); // true
|
|
6194
6605
|
*
|
|
6195
6606
|
*/
|
|
6196
|
-
AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
|
|
6607
|
+
AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
|
|
6197
6608
|
if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
|
|
6198
6609
|
return true;
|
|
6199
6610
|
} else if (this.state.isConjunctiveFacet(attribute)) {
|
|
@@ -6218,7 +6629,7 @@
|
|
|
6218
6629
|
*
|
|
6219
6630
|
* @param {string} facet name of the attribute for used for faceting
|
|
6220
6631
|
* @param {string} [value] optional value. If passed will test that this value
|
|
6221
|
-
|
|
6632
|
+
* is filtering the given facet.
|
|
6222
6633
|
* @return {boolean} true if refined
|
|
6223
6634
|
* @example
|
|
6224
6635
|
* helper.isExcludeRefined('color'); // false
|
|
@@ -6231,42 +6642,43 @@
|
|
|
6231
6642
|
* helper.isExcludeRefined('color', 'blue') // false
|
|
6232
6643
|
* helper.isExcludeRefined('color', 'red') // true
|
|
6233
6644
|
*/
|
|
6234
|
-
AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
|
|
6645
|
+
AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
|
|
6235
6646
|
return this.state.isExcludeRefined(facet, value);
|
|
6236
6647
|
};
|
|
6237
6648
|
|
|
6649
|
+
// eslint-disable-next-line valid-jsdoc
|
|
6238
6650
|
/**
|
|
6239
6651
|
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
|
|
6240
6652
|
*/
|
|
6241
|
-
AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
|
|
6653
|
+
AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
|
|
6242
6654
|
return this.state.isDisjunctiveFacetRefined(facet, value);
|
|
6243
6655
|
};
|
|
6244
6656
|
|
|
6245
6657
|
/**
|
|
6246
6658
|
* Check if the string is a currently filtering tag.
|
|
6247
6659
|
* @param {string} tag tag to check
|
|
6248
|
-
* @return {boolean}
|
|
6660
|
+
* @return {boolean} true if the tag is currently refined
|
|
6249
6661
|
*/
|
|
6250
|
-
AlgoliaSearchHelper.prototype.hasTag = function(tag) {
|
|
6662
|
+
AlgoliaSearchHelper.prototype.hasTag = function (tag) {
|
|
6251
6663
|
return this.state.isTagRefined(tag);
|
|
6252
6664
|
};
|
|
6253
6665
|
|
|
6666
|
+
// eslint-disable-next-line valid-jsdoc
|
|
6254
6667
|
/**
|
|
6255
6668
|
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
|
|
6256
6669
|
*/
|
|
6257
|
-
AlgoliaSearchHelper.prototype.isTagRefined = function() {
|
|
6670
|
+
AlgoliaSearchHelper.prototype.isTagRefined = function () {
|
|
6258
6671
|
return this.hasTagRefinements.apply(this, arguments);
|
|
6259
6672
|
};
|
|
6260
6673
|
|
|
6261
|
-
|
|
6262
6674
|
/**
|
|
6263
6675
|
* Get the name of the currently used index.
|
|
6264
|
-
* @return {string}
|
|
6676
|
+
* @return {string} name of the index
|
|
6265
6677
|
* @example
|
|
6266
6678
|
* helper.setIndex('highestPrice_products').getIndex();
|
|
6267
6679
|
* // returns 'highestPrice_products'
|
|
6268
6680
|
*/
|
|
6269
|
-
AlgoliaSearchHelper.prototype.getIndex = function() {
|
|
6681
|
+
AlgoliaSearchHelper.prototype.getIndex = function () {
|
|
6270
6682
|
return this.state.index;
|
|
6271
6683
|
};
|
|
6272
6684
|
|
|
@@ -6292,7 +6704,7 @@
|
|
|
6292
6704
|
*
|
|
6293
6705
|
* @return {string[]} The list of tags currently set.
|
|
6294
6706
|
*/
|
|
6295
|
-
AlgoliaSearchHelper.prototype.getTags = function() {
|
|
6707
|
+
AlgoliaSearchHelper.prototype.getTags = function () {
|
|
6296
6708
|
return this.state.tagRefinements;
|
|
6297
6709
|
};
|
|
6298
6710
|
|
|
@@ -6340,47 +6752,48 @@
|
|
|
6340
6752
|
* // }
|
|
6341
6753
|
* // ]
|
|
6342
6754
|
*/
|
|
6343
|
-
AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
|
|
6755
|
+
AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
|
|
6344
6756
|
var refinements = [];
|
|
6345
6757
|
|
|
6346
6758
|
if (this.state.isConjunctiveFacet(facetName)) {
|
|
6347
6759
|
var conjRefinements = this.state.getConjunctiveRefinements(facetName);
|
|
6348
6760
|
|
|
6349
|
-
conjRefinements.forEach(function(r) {
|
|
6761
|
+
conjRefinements.forEach(function (r) {
|
|
6350
6762
|
refinements.push({
|
|
6351
6763
|
value: r,
|
|
6352
|
-
type: 'conjunctive'
|
|
6764
|
+
type: 'conjunctive',
|
|
6353
6765
|
});
|
|
6354
6766
|
});
|
|
6355
6767
|
|
|
6356
6768
|
var excludeRefinements = this.state.getExcludeRefinements(facetName);
|
|
6357
6769
|
|
|
6358
|
-
excludeRefinements.forEach(function(r) {
|
|
6770
|
+
excludeRefinements.forEach(function (r) {
|
|
6359
6771
|
refinements.push({
|
|
6360
6772
|
value: r,
|
|
6361
|
-
type: 'exclude'
|
|
6773
|
+
type: 'exclude',
|
|
6362
6774
|
});
|
|
6363
6775
|
});
|
|
6364
6776
|
} else if (this.state.isDisjunctiveFacet(facetName)) {
|
|
6365
|
-
var
|
|
6777
|
+
var disjunctiveRefinements =
|
|
6778
|
+
this.state.getDisjunctiveRefinements(facetName);
|
|
6366
6779
|
|
|
6367
|
-
|
|
6780
|
+
disjunctiveRefinements.forEach(function (r) {
|
|
6368
6781
|
refinements.push({
|
|
6369
6782
|
value: r,
|
|
6370
|
-
type: 'disjunctive'
|
|
6783
|
+
type: 'disjunctive',
|
|
6371
6784
|
});
|
|
6372
6785
|
});
|
|
6373
6786
|
}
|
|
6374
6787
|
|
|
6375
6788
|
var numericRefinements = this.state.getNumericRefinements(facetName);
|
|
6376
6789
|
|
|
6377
|
-
Object.keys(numericRefinements).forEach(function(operator) {
|
|
6790
|
+
Object.keys(numericRefinements).forEach(function (operator) {
|
|
6378
6791
|
var value = numericRefinements[operator];
|
|
6379
6792
|
|
|
6380
6793
|
refinements.push({
|
|
6381
6794
|
value: value,
|
|
6382
6795
|
operator: operator,
|
|
6383
|
-
type: 'numeric'
|
|
6796
|
+
type: 'numeric',
|
|
6384
6797
|
});
|
|
6385
6798
|
});
|
|
6386
6799
|
|
|
@@ -6393,7 +6806,10 @@
|
|
|
6393
6806
|
* @param {string} operator operator applied on the refined values
|
|
6394
6807
|
* @return {Array.<number|number[]>} refined values
|
|
6395
6808
|
*/
|
|
6396
|
-
AlgoliaSearchHelper.prototype.getNumericRefinement = function(
|
|
6809
|
+
AlgoliaSearchHelper.prototype.getNumericRefinement = function (
|
|
6810
|
+
attribute,
|
|
6811
|
+
operator
|
|
6812
|
+
) {
|
|
6397
6813
|
return this.state.getNumericRefinement(attribute, operator);
|
|
6398
6814
|
};
|
|
6399
6815
|
|
|
@@ -6402,7 +6818,9 @@
|
|
|
6402
6818
|
* @param {string} facetName Hierarchical facet name
|
|
6403
6819
|
* @return {array.<string>} the path as an array of string
|
|
6404
6820
|
*/
|
|
6405
|
-
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(
|
|
6821
|
+
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
|
|
6822
|
+
facetName
|
|
6823
|
+
) {
|
|
6406
6824
|
return this.state.getHierarchicalFacetBreadcrumb(facetName);
|
|
6407
6825
|
};
|
|
6408
6826
|
|
|
@@ -6411,12 +6829,14 @@
|
|
|
6411
6829
|
/**
|
|
6412
6830
|
* Perform the underlying queries
|
|
6413
6831
|
* @private
|
|
6414
|
-
* @
|
|
6832
|
+
* @param {object} options options for the query
|
|
6833
|
+
* @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
|
|
6834
|
+
* @return {undefined} does not return anything
|
|
6415
6835
|
* @fires search
|
|
6416
6836
|
* @fires result
|
|
6417
6837
|
* @fires error
|
|
6418
6838
|
*/
|
|
6419
|
-
AlgoliaSearchHelper.prototype._search = function(options) {
|
|
6839
|
+
AlgoliaSearchHelper.prototype._search = function (options) {
|
|
6420
6840
|
var state = this.state;
|
|
6421
6841
|
var states = [];
|
|
6422
6842
|
var mainQueries = [];
|
|
@@ -6427,16 +6847,16 @@
|
|
|
6427
6847
|
states.push({
|
|
6428
6848
|
state: state,
|
|
6429
6849
|
queriesCount: mainQueries.length,
|
|
6430
|
-
helper: this
|
|
6850
|
+
helper: this,
|
|
6431
6851
|
});
|
|
6432
6852
|
|
|
6433
6853
|
this.emit('search', {
|
|
6434
6854
|
state: state,
|
|
6435
|
-
results: this.lastResults
|
|
6855
|
+
results: this.lastResults,
|
|
6436
6856
|
});
|
|
6437
6857
|
}
|
|
6438
6858
|
|
|
6439
|
-
var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
|
|
6859
|
+
var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
|
|
6440
6860
|
var derivedState = derivedHelper.getModifiedState(state);
|
|
6441
6861
|
var derivedStateQueries = derivedState.index
|
|
6442
6862
|
? requestBuilder_1._getQueries(derivedState.index, derivedState)
|
|
@@ -6445,12 +6865,12 @@
|
|
|
6445
6865
|
states.push({
|
|
6446
6866
|
state: derivedState,
|
|
6447
6867
|
queriesCount: derivedStateQueries.length,
|
|
6448
|
-
helper: derivedHelper
|
|
6868
|
+
helper: derivedHelper,
|
|
6449
6869
|
});
|
|
6450
6870
|
|
|
6451
6871
|
derivedHelper.emit('search', {
|
|
6452
6872
|
state: derivedState,
|
|
6453
|
-
results: derivedHelper.lastResults
|
|
6873
|
+
results: derivedHelper.lastResults,
|
|
6454
6874
|
});
|
|
6455
6875
|
|
|
6456
6876
|
return derivedStateQueries;
|
|
@@ -6462,21 +6882,24 @@
|
|
|
6462
6882
|
this._currentNbQueries++;
|
|
6463
6883
|
|
|
6464
6884
|
if (!queries.length) {
|
|
6465
|
-
return Promise.resolve({results: []}).then(
|
|
6885
|
+
return Promise.resolve({ results: [] }).then(
|
|
6466
6886
|
this._dispatchAlgoliaResponse.bind(this, states, queryId)
|
|
6467
6887
|
);
|
|
6468
6888
|
}
|
|
6469
6889
|
|
|
6470
6890
|
try {
|
|
6471
|
-
this.client
|
|
6891
|
+
this.client
|
|
6892
|
+
.search(queries)
|
|
6472
6893
|
.then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
|
|
6473
6894
|
.catch(this._dispatchAlgoliaError.bind(this, queryId));
|
|
6474
6895
|
} catch (error) {
|
|
6475
6896
|
// If we reach this part, we're in an internal error state
|
|
6476
6897
|
this.emit('error', {
|
|
6477
|
-
error: error
|
|
6898
|
+
error: error,
|
|
6478
6899
|
});
|
|
6479
6900
|
}
|
|
6901
|
+
|
|
6902
|
+
return undefined;
|
|
6480
6903
|
};
|
|
6481
6904
|
|
|
6482
6905
|
/**
|
|
@@ -6484,28 +6907,31 @@
|
|
|
6484
6907
|
* usable object that merge the results of all the batch requests. It will dispatch
|
|
6485
6908
|
* over the different helper + derived helpers (when there are some).
|
|
6486
6909
|
* @private
|
|
6487
|
-
* @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
|
|
6488
|
-
* state state used for to generate the request
|
|
6910
|
+
* @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
|
|
6489
6911
|
* @param {number} queryId id of the current request
|
|
6490
6912
|
* @param {object} content content of the response
|
|
6491
6913
|
* @return {undefined}
|
|
6492
6914
|
*/
|
|
6493
|
-
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(
|
|
6494
|
-
|
|
6915
|
+
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
|
|
6916
|
+
states,
|
|
6917
|
+
queryId,
|
|
6918
|
+
content
|
|
6919
|
+
) {
|
|
6920
|
+
// @TODO remove the number of outdated queries discarded instead of just one
|
|
6495
6921
|
|
|
6496
6922
|
if (queryId < this._lastQueryIdReceived) {
|
|
6497
6923
|
// Outdated answer
|
|
6498
6924
|
return;
|
|
6499
6925
|
}
|
|
6500
6926
|
|
|
6501
|
-
this._currentNbQueries -=
|
|
6927
|
+
this._currentNbQueries -= queryId - this._lastQueryIdReceived;
|
|
6502
6928
|
this._lastQueryIdReceived = queryId;
|
|
6503
6929
|
|
|
6504
6930
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
6505
6931
|
|
|
6506
6932
|
var results = content.results.slice();
|
|
6507
6933
|
|
|
6508
|
-
states.forEach(function(s) {
|
|
6934
|
+
states.forEach(function (s) {
|
|
6509
6935
|
var state = s.state;
|
|
6510
6936
|
var queriesCount = s.queriesCount;
|
|
6511
6937
|
var helper = s.helper;
|
|
@@ -6514,21 +6940,24 @@
|
|
|
6514
6940
|
if (!state.index) {
|
|
6515
6941
|
helper.emit('result', {
|
|
6516
6942
|
results: null,
|
|
6517
|
-
state: state
|
|
6943
|
+
state: state,
|
|
6518
6944
|
});
|
|
6519
6945
|
return;
|
|
6520
6946
|
}
|
|
6521
6947
|
|
|
6522
|
-
|
|
6948
|
+
helper.lastResults = new SearchResults_1(state, specificResults);
|
|
6523
6949
|
|
|
6524
6950
|
helper.emit('result', {
|
|
6525
|
-
results:
|
|
6526
|
-
state: state
|
|
6951
|
+
results: helper.lastResults,
|
|
6952
|
+
state: state,
|
|
6527
6953
|
});
|
|
6528
6954
|
});
|
|
6529
6955
|
};
|
|
6530
6956
|
|
|
6531
|
-
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(
|
|
6957
|
+
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
|
|
6958
|
+
queryId,
|
|
6959
|
+
error
|
|
6960
|
+
) {
|
|
6532
6961
|
if (queryId < this._lastQueryIdReceived) {
|
|
6533
6962
|
// Outdated answer
|
|
6534
6963
|
return;
|
|
@@ -6538,31 +6967,40 @@
|
|
|
6538
6967
|
this._lastQueryIdReceived = queryId;
|
|
6539
6968
|
|
|
6540
6969
|
this.emit('error', {
|
|
6541
|
-
error: error
|
|
6970
|
+
error: error,
|
|
6542
6971
|
});
|
|
6543
6972
|
|
|
6544
6973
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
6545
6974
|
};
|
|
6546
6975
|
|
|
6547
|
-
AlgoliaSearchHelper.prototype.containsRefinement = function(
|
|
6548
|
-
|
|
6976
|
+
AlgoliaSearchHelper.prototype.containsRefinement = function (
|
|
6977
|
+
query,
|
|
6978
|
+
facetFilters,
|
|
6979
|
+
numericFilters,
|
|
6980
|
+
tagFilters
|
|
6981
|
+
) {
|
|
6982
|
+
return (
|
|
6983
|
+
query ||
|
|
6549
6984
|
facetFilters.length !== 0 ||
|
|
6550
6985
|
numericFilters.length !== 0 ||
|
|
6551
|
-
tagFilters.length !== 0
|
|
6986
|
+
tagFilters.length !== 0
|
|
6987
|
+
);
|
|
6552
6988
|
};
|
|
6553
6989
|
|
|
6554
6990
|
/**
|
|
6555
6991
|
* Test if there are some disjunctive refinements on the facet
|
|
6556
6992
|
* @private
|
|
6557
6993
|
* @param {string} facet the attribute to test
|
|
6558
|
-
* @return {boolean}
|
|
6994
|
+
* @return {boolean} true if there are refinements on this attribute
|
|
6559
6995
|
*/
|
|
6560
|
-
AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
|
|
6561
|
-
return
|
|
6562
|
-
this.state.disjunctiveRefinements[facet]
|
|
6996
|
+
AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
|
|
6997
|
+
return (
|
|
6998
|
+
this.state.disjunctiveRefinements[facet] &&
|
|
6999
|
+
this.state.disjunctiveRefinements[facet].length > 0
|
|
7000
|
+
);
|
|
6563
7001
|
};
|
|
6564
7002
|
|
|
6565
|
-
AlgoliaSearchHelper.prototype._change = function(event) {
|
|
7003
|
+
AlgoliaSearchHelper.prototype._change = function (event) {
|
|
6566
7004
|
var state = event.state;
|
|
6567
7005
|
var isPageReset = event.isPageReset;
|
|
6568
7006
|
|
|
@@ -6572,17 +7010,17 @@
|
|
|
6572
7010
|
this.emit('change', {
|
|
6573
7011
|
state: this.state,
|
|
6574
7012
|
results: this.lastResults,
|
|
6575
|
-
isPageReset: isPageReset
|
|
7013
|
+
isPageReset: isPageReset,
|
|
6576
7014
|
});
|
|
6577
7015
|
}
|
|
6578
7016
|
};
|
|
6579
7017
|
|
|
6580
7018
|
/**
|
|
6581
7019
|
* Clears the cache of the underlying Algolia client.
|
|
6582
|
-
* @return {AlgoliaSearchHelper}
|
|
7020
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6583
7021
|
*/
|
|
6584
|
-
AlgoliaSearchHelper.prototype.clearCache = function() {
|
|
6585
|
-
this.client.clearCache
|
|
7022
|
+
AlgoliaSearchHelper.prototype.clearCache = function () {
|
|
7023
|
+
if (this.client.clearCache) this.client.clearCache();
|
|
6586
7024
|
return this;
|
|
6587
7025
|
};
|
|
6588
7026
|
|
|
@@ -6590,9 +7028,9 @@
|
|
|
6590
7028
|
* Updates the internal client instance. If the reference of the clients
|
|
6591
7029
|
* are equal then no update is actually done.
|
|
6592
7030
|
* @param {AlgoliaSearch} newClient an AlgoliaSearch client
|
|
6593
|
-
* @return {AlgoliaSearchHelper}
|
|
7031
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
6594
7032
|
*/
|
|
6595
|
-
AlgoliaSearchHelper.prototype.setClient = function(newClient) {
|
|
7033
|
+
AlgoliaSearchHelper.prototype.setClient = function (newClient) {
|
|
6596
7034
|
if (this.client === newClient) return this;
|
|
6597
7035
|
|
|
6598
7036
|
if (typeof newClient.addAlgoliaAgent === 'function') {
|
|
@@ -6605,9 +7043,9 @@
|
|
|
6605
7043
|
|
|
6606
7044
|
/**
|
|
6607
7045
|
* Gets the instance of the currently used client.
|
|
6608
|
-
* @return {AlgoliaSearch}
|
|
7046
|
+
* @return {AlgoliaSearch} the currently used client
|
|
6609
7047
|
*/
|
|
6610
|
-
AlgoliaSearchHelper.prototype.getClient = function() {
|
|
7048
|
+
AlgoliaSearchHelper.prototype.getClient = function () {
|
|
6611
7049
|
return this.client;
|
|
6612
7050
|
};
|
|
6613
7051
|
|
|
@@ -6628,9 +7066,9 @@
|
|
|
6628
7066
|
* and the SearchParameters that is returned by the call of the
|
|
6629
7067
|
* parameter function.
|
|
6630
7068
|
* @param {function} fn SearchParameters -> SearchParameters
|
|
6631
|
-
* @return {DerivedHelper}
|
|
7069
|
+
* @return {DerivedHelper} a new DerivedHelper
|
|
6632
7070
|
*/
|
|
6633
|
-
AlgoliaSearchHelper.prototype.derive = function(fn) {
|
|
7071
|
+
AlgoliaSearchHelper.prototype.derive = function (fn) {
|
|
6634
7072
|
var derivedHelper = new DerivedHelper_1(this, fn);
|
|
6635
7073
|
this.derivedHelpers.push(derivedHelper);
|
|
6636
7074
|
return derivedHelper;
|
|
@@ -6640,10 +7078,11 @@
|
|
|
6640
7078
|
* This method detaches a derived Helper from the main one. Prefer using the one from the
|
|
6641
7079
|
* derived helper itself, to remove the event listeners too.
|
|
6642
7080
|
* @private
|
|
6643
|
-
* @
|
|
7081
|
+
* @param {DerivedHelper} derivedHelper the derived helper to detach
|
|
7082
|
+
* @return {undefined} nothing is returned
|
|
6644
7083
|
* @throws Error
|
|
6645
7084
|
*/
|
|
6646
|
-
AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
|
|
7085
|
+
AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
|
|
6647
7086
|
var pos = this.derivedHelpers.indexOf(derivedHelper);
|
|
6648
7087
|
if (pos === -1) throw new Error('Derived helper already detached');
|
|
6649
7088
|
this.derivedHelpers.splice(pos, 1);
|
|
@@ -6653,7 +7092,7 @@
|
|
|
6653
7092
|
* This method returns true if there is currently at least one on-going search.
|
|
6654
7093
|
* @return {boolean} true if there is a search pending
|
|
6655
7094
|
*/
|
|
6656
|
-
AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
|
|
7095
|
+
AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
|
|
6657
7096
|
return this._currentNbQueries > 0;
|
|
6658
7097
|
};
|
|
6659
7098
|
|
|
@@ -6704,7 +7143,7 @@
|
|
|
6704
7143
|
* @param {AlgoliaSearch} client an AlgoliaSearch client
|
|
6705
7144
|
* @param {string} index the name of the index to query
|
|
6706
7145
|
* @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.
|
|
6707
|
-
* @return {AlgoliaSearchHelper}
|
|
7146
|
+
* @return {AlgoliaSearchHelper} The helper instance
|
|
6708
7147
|
*/
|
|
6709
7148
|
function algoliasearchHelper(client, index, opts) {
|
|
6710
7149
|
return new algoliasearch_helper(client, index, opts);
|