react-instantsearch-core 6.40.2 → 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 +1529 -535
- 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) {
|
|
@@ -1215,14 +1215,20 @@
|
|
|
1215
1215
|
});
|
|
1216
1216
|
|
|
1217
1217
|
function clone(value) {
|
|
1218
|
-
if (
|
|
1218
|
+
if (typeof value === 'object' && value !== null) {
|
|
1219
1219
|
return _merge(Array.isArray(value) ? [] : {}, value);
|
|
1220
1220
|
}
|
|
1221
1221
|
return value;
|
|
1222
1222
|
}
|
|
1223
|
+
|
|
1223
1224
|
function isObjectOrArrayOrFunction(value) {
|
|
1224
|
-
return
|
|
1225
|
+
return (
|
|
1226
|
+
typeof value === 'function' ||
|
|
1227
|
+
Array.isArray(value) ||
|
|
1228
|
+
Object.prototype.toString.call(value) === '[object Object]'
|
|
1229
|
+
);
|
|
1225
1230
|
}
|
|
1231
|
+
|
|
1226
1232
|
function _merge(target, source) {
|
|
1227
1233
|
if (target === source) {
|
|
1228
1234
|
return target;
|
|
@@ -1230,17 +1236,27 @@
|
|
|
1230
1236
|
|
|
1231
1237
|
// eslint-disable-next-line no-restricted-syntax
|
|
1232
1238
|
for (var key in source) {
|
|
1233
|
-
if (
|
|
1239
|
+
if (
|
|
1240
|
+
!Object.prototype.hasOwnProperty.call(source, key) ||
|
|
1241
|
+
key === '__proto__' ||
|
|
1242
|
+
key === 'constructor'
|
|
1243
|
+
) {
|
|
1234
1244
|
// eslint-disable-next-line no-continue
|
|
1235
1245
|
continue;
|
|
1236
1246
|
}
|
|
1247
|
+
|
|
1237
1248
|
var sourceVal = source[key];
|
|
1238
1249
|
var targetVal = target[key];
|
|
1250
|
+
|
|
1239
1251
|
if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
|
|
1240
1252
|
// eslint-disable-next-line no-continue
|
|
1241
1253
|
continue;
|
|
1242
1254
|
}
|
|
1243
|
-
|
|
1255
|
+
|
|
1256
|
+
if (
|
|
1257
|
+
isObjectOrArrayOrFunction(targetVal) &&
|
|
1258
|
+
isObjectOrArrayOrFunction(sourceVal)
|
|
1259
|
+
) {
|
|
1244
1260
|
target[key] = _merge(targetVal, sourceVal);
|
|
1245
1261
|
} else {
|
|
1246
1262
|
target[key] = clone(sourceVal);
|
|
@@ -1268,24 +1284,24 @@
|
|
|
1268
1284
|
if (!isObjectOrArrayOrFunction(target)) {
|
|
1269
1285
|
target = {};
|
|
1270
1286
|
}
|
|
1287
|
+
|
|
1271
1288
|
for (var i = 1, l = arguments.length; i < l; i++) {
|
|
1272
1289
|
var source = arguments[i];
|
|
1290
|
+
|
|
1273
1291
|
if (isObjectOrArrayOrFunction(source)) {
|
|
1274
1292
|
_merge(target, source);
|
|
1275
1293
|
}
|
|
1276
1294
|
}
|
|
1277
1295
|
return target;
|
|
1278
1296
|
}
|
|
1279
|
-
module.exports = merge;
|
|
1280
1297
|
|
|
1281
|
-
var
|
|
1282
|
-
__proto__: null
|
|
1283
|
-
});
|
|
1298
|
+
var merge_1 = merge;
|
|
1284
1299
|
|
|
1285
1300
|
// NOTE: this behaves like lodash/defaults, but doesn't mutate the target
|
|
1286
1301
|
// it also preserve keys order
|
|
1287
1302
|
var defaultsPure = function defaultsPure() {
|
|
1288
1303
|
var sources = Array.prototype.slice.call(arguments);
|
|
1304
|
+
|
|
1289
1305
|
return sources.reduceRight(function (acc, source) {
|
|
1290
1306
|
Object.keys(Object(source)).forEach(function (key) {
|
|
1291
1307
|
if (source[key] === undefined) {
|
|
@@ -1303,7 +1319,10 @@
|
|
|
1303
1319
|
|
|
1304
1320
|
function intersection(arr1, arr2) {
|
|
1305
1321
|
return arr1.filter(function (value, index) {
|
|
1306
|
-
return
|
|
1322
|
+
return (
|
|
1323
|
+
arr2.indexOf(value) > -1 &&
|
|
1324
|
+
arr1.indexOf(value) === index /* skips duplicates */
|
|
1325
|
+
);
|
|
1307
1326
|
});
|
|
1308
1327
|
}
|
|
1309
1328
|
|
|
@@ -1314,11 +1333,13 @@
|
|
|
1314
1333
|
if (!Array.isArray(array)) {
|
|
1315
1334
|
return undefined;
|
|
1316
1335
|
}
|
|
1336
|
+
|
|
1317
1337
|
for (var i = 0; i < array.length; i++) {
|
|
1318
1338
|
if (comparator(array[i])) {
|
|
1319
1339
|
return array[i];
|
|
1320
1340
|
}
|
|
1321
1341
|
}
|
|
1342
|
+
|
|
1322
1343
|
return undefined;
|
|
1323
1344
|
};
|
|
1324
1345
|
|
|
@@ -1330,8 +1351,12 @@
|
|
|
1330
1351
|
} else if (Array.isArray(v)) {
|
|
1331
1352
|
return v.map(valToNumber);
|
|
1332
1353
|
}
|
|
1333
|
-
|
|
1354
|
+
|
|
1355
|
+
throw new Error(
|
|
1356
|
+
'The value should be a number, a parsable string or an array of those.'
|
|
1357
|
+
);
|
|
1334
1358
|
}
|
|
1359
|
+
|
|
1335
1360
|
var valToNumber_1 = valToNumber;
|
|
1336
1361
|
|
|
1337
1362
|
// https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
|
|
@@ -1349,11 +1374,13 @@
|
|
|
1349
1374
|
}
|
|
1350
1375
|
return target;
|
|
1351
1376
|
}
|
|
1377
|
+
|
|
1352
1378
|
var omit$1 = _objectWithoutPropertiesLoose$1;
|
|
1353
1379
|
|
|
1354
1380
|
function objectHasKeys$1(obj) {
|
|
1355
1381
|
return obj && Object.keys(obj).length > 0;
|
|
1356
1382
|
}
|
|
1383
|
+
|
|
1357
1384
|
var objectHasKeys_1 = objectHasKeys$1;
|
|
1358
1385
|
|
|
1359
1386
|
var isValidUserToken = function isValidUserToken(userToken) {
|
|
@@ -1377,6 +1404,8 @@
|
|
|
1377
1404
|
|
|
1378
1405
|
|
|
1379
1406
|
|
|
1407
|
+
|
|
1408
|
+
|
|
1380
1409
|
var lib = {
|
|
1381
1410
|
/**
|
|
1382
1411
|
* Adds a refinement to a RefinementList
|
|
@@ -1389,10 +1418,17 @@
|
|
|
1389
1418
|
if (lib.isRefined(refinementList, attribute, value)) {
|
|
1390
1419
|
return refinementList;
|
|
1391
1420
|
}
|
|
1421
|
+
|
|
1392
1422
|
var valueAsString = '' + value;
|
|
1393
|
-
|
|
1423
|
+
|
|
1424
|
+
var facetRefinement = !refinementList[attribute]
|
|
1425
|
+
? [valueAsString]
|
|
1426
|
+
: refinementList[attribute].concat(valueAsString);
|
|
1427
|
+
|
|
1394
1428
|
var mod = {};
|
|
1429
|
+
|
|
1395
1430
|
mod[attribute] = facetRefinement;
|
|
1431
|
+
|
|
1396
1432
|
return defaultsPure({}, mod, refinementList);
|
|
1397
1433
|
},
|
|
1398
1434
|
/**
|
|
@@ -1404,7 +1440,11 @@
|
|
|
1404
1440
|
* @param {string} [value] the value of the refinement
|
|
1405
1441
|
* @return {RefinementList} a new and updated refinement lst
|
|
1406
1442
|
*/
|
|
1407
|
-
removeRefinement: function removeRefinement(
|
|
1443
|
+
removeRefinement: function removeRefinement(
|
|
1444
|
+
refinementList,
|
|
1445
|
+
attribute,
|
|
1446
|
+
value
|
|
1447
|
+
) {
|
|
1408
1448
|
if (value === undefined) {
|
|
1409
1449
|
// we use the "filter" form of clearRefinement, since it leaves empty values as-is
|
|
1410
1450
|
// the form with a string will remove the attribute completely
|
|
@@ -1412,7 +1452,9 @@
|
|
|
1412
1452
|
return attribute === f;
|
|
1413
1453
|
});
|
|
1414
1454
|
}
|
|
1455
|
+
|
|
1415
1456
|
var valueAsString = '' + value;
|
|
1457
|
+
|
|
1416
1458
|
return lib.clearRefinement(refinementList, function (v, f) {
|
|
1417
1459
|
return attribute === f && valueAsString === v;
|
|
1418
1460
|
});
|
|
@@ -1424,11 +1466,18 @@
|
|
|
1424
1466
|
* @param {string} value the value of the refinement
|
|
1425
1467
|
* @return {RefinementList} a new and updated list
|
|
1426
1468
|
*/
|
|
1427
|
-
toggleRefinement: function toggleRefinement(
|
|
1428
|
-
|
|
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');
|
|
1476
|
+
|
|
1429
1477
|
if (lib.isRefined(refinementList, attribute, value)) {
|
|
1430
1478
|
return lib.removeRefinement(refinementList, attribute, value);
|
|
1431
1479
|
}
|
|
1480
|
+
|
|
1432
1481
|
return lib.addRefinement(refinementList, attribute, value);
|
|
1433
1482
|
},
|
|
1434
1483
|
/**
|
|
@@ -1442,7 +1491,11 @@
|
|
|
1442
1491
|
* @param {string} [refinementType] optional parameter to give more context to the attribute function
|
|
1443
1492
|
* @return {RefinementList} a new and updated refinement list
|
|
1444
1493
|
*/
|
|
1445
|
-
clearRefinement: function clearRefinement(
|
|
1494
|
+
clearRefinement: function clearRefinement(
|
|
1495
|
+
refinementList,
|
|
1496
|
+
attribute,
|
|
1497
|
+
refinementType
|
|
1498
|
+
) {
|
|
1446
1499
|
if (attribute === undefined) {
|
|
1447
1500
|
// return the same object if the list is already empty
|
|
1448
1501
|
// this is mainly for tests, as it doesn't have much impact on performance
|
|
@@ -1454,17 +1507,26 @@
|
|
|
1454
1507
|
return omit$1(refinementList, [attribute]);
|
|
1455
1508
|
} else if (typeof attribute === 'function') {
|
|
1456
1509
|
var hasChanged = false;
|
|
1457
|
-
|
|
1510
|
+
|
|
1511
|
+
var newRefinementList = Object.keys(refinementList).reduce(function (
|
|
1512
|
+
memo,
|
|
1513
|
+
key
|
|
1514
|
+
) {
|
|
1458
1515
|
var values = refinementList[key] || [];
|
|
1459
1516
|
var facetList = values.filter(function (value) {
|
|
1460
1517
|
return !attribute(value, key, refinementType);
|
|
1461
1518
|
});
|
|
1519
|
+
|
|
1462
1520
|
if (facetList.length !== values.length) {
|
|
1463
1521
|
hasChanged = true;
|
|
1464
1522
|
}
|
|
1523
|
+
|
|
1465
1524
|
memo[key] = facetList;
|
|
1525
|
+
|
|
1466
1526
|
return memo;
|
|
1467
|
-
},
|
|
1527
|
+
},
|
|
1528
|
+
{});
|
|
1529
|
+
|
|
1468
1530
|
if (hasChanged) return newRefinementList;
|
|
1469
1531
|
return refinementList;
|
|
1470
1532
|
}
|
|
@@ -1483,14 +1545,20 @@
|
|
|
1483
1545
|
* @return {boolean} true if the attribute is refined, false otherwise
|
|
1484
1546
|
*/
|
|
1485
1547
|
isRefined: function isRefined(refinementList, attribute, refinementValue) {
|
|
1486
|
-
var containsRefinements =
|
|
1548
|
+
var containsRefinements =
|
|
1549
|
+
Boolean(refinementList[attribute]) &&
|
|
1550
|
+
refinementList[attribute].length > 0;
|
|
1551
|
+
|
|
1487
1552
|
if (refinementValue === undefined || !containsRefinements) {
|
|
1488
1553
|
return containsRefinements;
|
|
1489
1554
|
}
|
|
1555
|
+
|
|
1490
1556
|
var refinementValueAsString = '' + refinementValue;
|
|
1557
|
+
|
|
1491
1558
|
return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
|
|
1492
|
-
}
|
|
1559
|
+
},
|
|
1493
1560
|
};
|
|
1561
|
+
|
|
1494
1562
|
var RefinementList = lib;
|
|
1495
1563
|
|
|
1496
1564
|
/**
|
|
@@ -1505,9 +1573,12 @@
|
|
|
1505
1573
|
*/
|
|
1506
1574
|
function isEqualNumericRefinement(a, b) {
|
|
1507
1575
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1508
|
-
return
|
|
1509
|
-
|
|
1510
|
-
|
|
1576
|
+
return (
|
|
1577
|
+
a.length === b.length &&
|
|
1578
|
+
a.every(function (el, i) {
|
|
1579
|
+
return isEqualNumericRefinement(b[i], el);
|
|
1580
|
+
})
|
|
1581
|
+
);
|
|
1511
1582
|
}
|
|
1512
1583
|
return a === b;
|
|
1513
1584
|
}
|
|
@@ -1574,10 +1645,15 @@
|
|
|
1574
1645
|
}
|
|
1575
1646
|
*/
|
|
1576
1647
|
function SearchParameters(newParameters) {
|
|
1577
|
-
var params = newParameters
|
|
1648
|
+
var params = newParameters
|
|
1649
|
+
? SearchParameters._parseNumbers(newParameters)
|
|
1650
|
+
: {};
|
|
1651
|
+
|
|
1578
1652
|
if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
|
|
1579
1653
|
// eslint-disable-next-line no-console
|
|
1580
|
-
console.warn(
|
|
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
|
+
);
|
|
1581
1657
|
}
|
|
1582
1658
|
/**
|
|
1583
1659
|
* This attribute contains the list of all the conjunctive facets
|
|
@@ -1677,13 +1753,15 @@
|
|
|
1677
1753
|
* be translated into the `facetFilters` attribute.
|
|
1678
1754
|
* @member {Object.<string, SearchParameters.FacetList>}
|
|
1679
1755
|
*/
|
|
1680
|
-
this.hierarchicalFacetsRefinements =
|
|
1756
|
+
this.hierarchicalFacetsRefinements =
|
|
1757
|
+
params.hierarchicalFacetsRefinements || {};
|
|
1681
1758
|
|
|
1682
1759
|
// eslint-disable-next-line consistent-this
|
|
1683
1760
|
var self = this;
|
|
1684
1761
|
Object.keys(params).forEach(function (paramName) {
|
|
1685
1762
|
var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
|
|
1686
1763
|
var isValueDefined = params[paramName] !== undefined;
|
|
1764
|
+
|
|
1687
1765
|
if (!isKeyKnown && isValueDefined) {
|
|
1688
1766
|
self[paramName] = params[paramName];
|
|
1689
1767
|
}
|
|
@@ -1705,8 +1783,23 @@
|
|
|
1705
1783
|
SearchParameters._parseNumbers = function (partialState) {
|
|
1706
1784
|
// Do not parse numbers again in SearchParameters, they ought to be parsed already
|
|
1707
1785
|
if (partialState instanceof SearchParameters) return partialState;
|
|
1786
|
+
|
|
1708
1787
|
var numbers = {};
|
|
1709
|
-
|
|
1788
|
+
|
|
1789
|
+
var numberKeys = [
|
|
1790
|
+
'aroundPrecision',
|
|
1791
|
+
'aroundRadius',
|
|
1792
|
+
'getRankingInfo',
|
|
1793
|
+
'minWordSizefor2Typos',
|
|
1794
|
+
'minWordSizefor1Typo',
|
|
1795
|
+
'page',
|
|
1796
|
+
'maxValuesPerFacet',
|
|
1797
|
+
'distinct',
|
|
1798
|
+
'minimumAroundRadius',
|
|
1799
|
+
'hitsPerPage',
|
|
1800
|
+
'minProximity',
|
|
1801
|
+
];
|
|
1802
|
+
|
|
1710
1803
|
numberKeys.forEach(function (k) {
|
|
1711
1804
|
var value = partialState[k];
|
|
1712
1805
|
if (typeof value === 'string') {
|
|
@@ -1719,7 +1812,9 @@
|
|
|
1719
1812
|
// there's two formats of insideBoundingBox, we need to parse
|
|
1720
1813
|
// the one which is an array of float geo rectangles
|
|
1721
1814
|
if (Array.isArray(partialState.insideBoundingBox)) {
|
|
1722
|
-
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
|
|
1815
|
+
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
|
|
1816
|
+
geoRect
|
|
1817
|
+
) {
|
|
1723
1818
|
if (Array.isArray(geoRect)) {
|
|
1724
1819
|
return geoRect.map(function (value) {
|
|
1725
1820
|
return parseFloat(value);
|
|
@@ -1728,6 +1823,7 @@
|
|
|
1728
1823
|
return geoRect;
|
|
1729
1824
|
});
|
|
1730
1825
|
}
|
|
1826
|
+
|
|
1731
1827
|
if (partialState.numericRefinements) {
|
|
1732
1828
|
var numericRefinements = {};
|
|
1733
1829
|
Object.keys(partialState.numericRefinements).forEach(function (attribute) {
|
|
@@ -1753,7 +1849,8 @@
|
|
|
1753
1849
|
});
|
|
1754
1850
|
numbers.numericRefinements = numericRefinements;
|
|
1755
1851
|
}
|
|
1756
|
-
|
|
1852
|
+
|
|
1853
|
+
return merge_1({}, partialState, numbers);
|
|
1757
1854
|
};
|
|
1758
1855
|
|
|
1759
1856
|
/**
|
|
@@ -1764,21 +1861,30 @@
|
|
|
1764
1861
|
*/
|
|
1765
1862
|
SearchParameters.make = function makeSearchParameters(newParameters) {
|
|
1766
1863
|
var instance = new SearchParameters(newParameters);
|
|
1864
|
+
|
|
1767
1865
|
var hierarchicalFacets = newParameters.hierarchicalFacets || [];
|
|
1768
1866
|
hierarchicalFacets.forEach(function (facet) {
|
|
1769
1867
|
if (facet.rootPath) {
|
|
1770
1868
|
var currentRefinement = instance.getHierarchicalRefinement(facet.name);
|
|
1771
|
-
|
|
1869
|
+
|
|
1870
|
+
if (
|
|
1871
|
+
currentRefinement.length > 0 &&
|
|
1872
|
+
currentRefinement[0].indexOf(facet.rootPath) !== 0
|
|
1873
|
+
) {
|
|
1772
1874
|
instance = instance.clearRefinements(facet.name);
|
|
1773
1875
|
}
|
|
1774
1876
|
|
|
1775
1877
|
// get it again in case it has been cleared
|
|
1776
1878
|
currentRefinement = instance.getHierarchicalRefinement(facet.name);
|
|
1777
1879
|
if (currentRefinement.length === 0) {
|
|
1778
|
-
instance = instance.toggleHierarchicalFacetRefinement(
|
|
1880
|
+
instance = instance.toggleHierarchicalFacetRefinement(
|
|
1881
|
+
facet.name,
|
|
1882
|
+
facet.rootPath
|
|
1883
|
+
);
|
|
1779
1884
|
}
|
|
1780
1885
|
}
|
|
1781
1886
|
});
|
|
1887
|
+
|
|
1782
1888
|
return instance;
|
|
1783
1889
|
};
|
|
1784
1890
|
|
|
@@ -1790,22 +1896,51 @@
|
|
|
1790
1896
|
*/
|
|
1791
1897
|
SearchParameters.validate = function (currentState, parameters) {
|
|
1792
1898
|
var params = parameters || {};
|
|
1793
|
-
|
|
1794
|
-
|
|
1899
|
+
|
|
1900
|
+
if (
|
|
1901
|
+
currentState.tagFilters &&
|
|
1902
|
+
params.tagRefinements &&
|
|
1903
|
+
params.tagRefinements.length > 0
|
|
1904
|
+
) {
|
|
1905
|
+
return new Error(
|
|
1906
|
+
'[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
|
|
1907
|
+
'an error, if it is really what you want, you should first clear the tags with clearTags method.'
|
|
1908
|
+
);
|
|
1795
1909
|
}
|
|
1910
|
+
|
|
1796
1911
|
if (currentState.tagRefinements.length > 0 && params.tagFilters) {
|
|
1797
|
-
return new Error(
|
|
1912
|
+
return new Error(
|
|
1913
|
+
'[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
|
|
1914
|
+
'an error, if it is not, you should first clear the tags with clearTags method.'
|
|
1915
|
+
);
|
|
1798
1916
|
}
|
|
1799
|
-
|
|
1800
|
-
|
|
1917
|
+
|
|
1918
|
+
if (
|
|
1919
|
+
currentState.numericFilters &&
|
|
1920
|
+
params.numericRefinements &&
|
|
1921
|
+
objectHasKeys_1(params.numericRefinements)
|
|
1922
|
+
) {
|
|
1923
|
+
return new Error(
|
|
1924
|
+
"[Numeric filters] Can't switch from the advanced to the managed API. It" +
|
|
1925
|
+
' is probably an error, if this is really what you want, you have to first' +
|
|
1926
|
+
' clear the numeric filters.'
|
|
1927
|
+
);
|
|
1801
1928
|
}
|
|
1929
|
+
|
|
1802
1930
|
if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
|
|
1803
|
-
return new Error(
|
|
1931
|
+
return new Error(
|
|
1932
|
+
"[Numeric filters] Can't switch from the managed API to the advanced. It" +
|
|
1933
|
+
' is probably an error, if this is really what you want, you have to first' +
|
|
1934
|
+
' clear the numeric filters.'
|
|
1935
|
+
);
|
|
1804
1936
|
}
|
|
1937
|
+
|
|
1805
1938
|
return null;
|
|
1806
1939
|
};
|
|
1940
|
+
|
|
1807
1941
|
SearchParameters.prototype = {
|
|
1808
1942
|
constructor: SearchParameters,
|
|
1943
|
+
|
|
1809
1944
|
/**
|
|
1810
1945
|
* Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
|
|
1811
1946
|
* @method
|
|
@@ -1818,12 +1953,35 @@
|
|
|
1818
1953
|
clearRefinements: function clearRefinements(attribute) {
|
|
1819
1954
|
var patch = {
|
|
1820
1955
|
numericRefinements: this._clearNumericRefinements(attribute),
|
|
1821
|
-
facetsRefinements: RefinementList.clearRefinement(
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1956
|
+
facetsRefinements: RefinementList.clearRefinement(
|
|
1957
|
+
this.facetsRefinements,
|
|
1958
|
+
attribute,
|
|
1959
|
+
'conjunctiveFacet'
|
|
1960
|
+
),
|
|
1961
|
+
facetsExcludes: RefinementList.clearRefinement(
|
|
1962
|
+
this.facetsExcludes,
|
|
1963
|
+
attribute,
|
|
1964
|
+
'exclude'
|
|
1965
|
+
),
|
|
1966
|
+
disjunctiveFacetsRefinements: RefinementList.clearRefinement(
|
|
1967
|
+
this.disjunctiveFacetsRefinements,
|
|
1968
|
+
attribute,
|
|
1969
|
+
'disjunctiveFacet'
|
|
1970
|
+
),
|
|
1971
|
+
hierarchicalFacetsRefinements: RefinementList.clearRefinement(
|
|
1972
|
+
this.hierarchicalFacetsRefinements,
|
|
1973
|
+
attribute,
|
|
1974
|
+
'hierarchicalFacet'
|
|
1975
|
+
),
|
|
1825
1976
|
};
|
|
1826
|
-
if (
|
|
1977
|
+
if (
|
|
1978
|
+
patch.numericRefinements === this.numericRefinements &&
|
|
1979
|
+
patch.facetsRefinements === this.facetsRefinements &&
|
|
1980
|
+
patch.facetsExcludes === this.facetsExcludes &&
|
|
1981
|
+
patch.disjunctiveFacetsRefinements ===
|
|
1982
|
+
this.disjunctiveFacetsRefinements &&
|
|
1983
|
+
patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
|
|
1984
|
+
) {
|
|
1827
1985
|
return this;
|
|
1828
1986
|
}
|
|
1829
1987
|
return this.setQueryParameters(patch);
|
|
@@ -1834,10 +1992,12 @@
|
|
|
1834
1992
|
* @return {SearchParameters} new instance with tags cleared
|
|
1835
1993
|
*/
|
|
1836
1994
|
clearTags: function clearTags() {
|
|
1837
|
-
if (this.tagFilters === undefined && this.tagRefinements.length === 0)
|
|
1995
|
+
if (this.tagFilters === undefined && this.tagRefinements.length === 0)
|
|
1996
|
+
return this;
|
|
1997
|
+
|
|
1838
1998
|
return this.setQueryParameters({
|
|
1839
1999
|
tagFilters: undefined,
|
|
1840
|
-
tagRefinements: []
|
|
2000
|
+
tagRefinements: [],
|
|
1841
2001
|
});
|
|
1842
2002
|
},
|
|
1843
2003
|
/**
|
|
@@ -1848,8 +2008,9 @@
|
|
|
1848
2008
|
*/
|
|
1849
2009
|
setIndex: function setIndex(index) {
|
|
1850
2010
|
if (index === this.index) return this;
|
|
2011
|
+
|
|
1851
2012
|
return this.setQueryParameters({
|
|
1852
|
-
index: index
|
|
2013
|
+
index: index,
|
|
1853
2014
|
});
|
|
1854
2015
|
},
|
|
1855
2016
|
/**
|
|
@@ -1860,8 +2021,9 @@
|
|
|
1860
2021
|
*/
|
|
1861
2022
|
setQuery: function setQuery(newQuery) {
|
|
1862
2023
|
if (newQuery === this.query) return this;
|
|
2024
|
+
|
|
1863
2025
|
return this.setQueryParameters({
|
|
1864
|
-
query: newQuery
|
|
2026
|
+
query: newQuery,
|
|
1865
2027
|
});
|
|
1866
2028
|
},
|
|
1867
2029
|
/**
|
|
@@ -1872,8 +2034,9 @@
|
|
|
1872
2034
|
*/
|
|
1873
2035
|
setPage: function setPage(newPage) {
|
|
1874
2036
|
if (newPage === this.page) return this;
|
|
2037
|
+
|
|
1875
2038
|
return this.setQueryParameters({
|
|
1876
|
-
page: newPage
|
|
2039
|
+
page: newPage,
|
|
1877
2040
|
});
|
|
1878
2041
|
},
|
|
1879
2042
|
/**
|
|
@@ -1885,7 +2048,7 @@
|
|
|
1885
2048
|
*/
|
|
1886
2049
|
setFacets: function setFacets(facets) {
|
|
1887
2050
|
return this.setQueryParameters({
|
|
1888
|
-
facets: facets
|
|
2051
|
+
facets: facets,
|
|
1889
2052
|
});
|
|
1890
2053
|
},
|
|
1891
2054
|
/**
|
|
@@ -1897,7 +2060,7 @@
|
|
|
1897
2060
|
*/
|
|
1898
2061
|
setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
|
|
1899
2062
|
return this.setQueryParameters({
|
|
1900
|
-
disjunctiveFacets: facets
|
|
2063
|
+
disjunctiveFacets: facets,
|
|
1901
2064
|
});
|
|
1902
2065
|
},
|
|
1903
2066
|
/**
|
|
@@ -1909,8 +2072,9 @@
|
|
|
1909
2072
|
*/
|
|
1910
2073
|
setHitsPerPage: function setHitsPerPage(n) {
|
|
1911
2074
|
if (this.hitsPerPage === n) return this;
|
|
2075
|
+
|
|
1912
2076
|
return this.setQueryParameters({
|
|
1913
|
-
hitsPerPage: n
|
|
2077
|
+
hitsPerPage: n,
|
|
1914
2078
|
});
|
|
1915
2079
|
},
|
|
1916
2080
|
/**
|
|
@@ -1922,8 +2086,9 @@
|
|
|
1922
2086
|
*/
|
|
1923
2087
|
setTypoTolerance: function setTypoTolerance(typoTolerance) {
|
|
1924
2088
|
if (this.typoTolerance === typoTolerance) return this;
|
|
2089
|
+
|
|
1925
2090
|
return this.setQueryParameters({
|
|
1926
|
-
typoTolerance: typoTolerance
|
|
2091
|
+
typoTolerance: typoTolerance,
|
|
1927
2092
|
});
|
|
1928
2093
|
},
|
|
1929
2094
|
/**
|
|
@@ -1943,11 +2108,15 @@
|
|
|
1943
2108
|
* state.addNumericRefinement('size', '=', 38);
|
|
1944
2109
|
* state.addNumericRefinement('size', '=', 40);
|
|
1945
2110
|
*/
|
|
1946
|
-
addNumericRefinement: function
|
|
2111
|
+
addNumericRefinement: function (attribute, operator, value) {
|
|
1947
2112
|
var val = valToNumber_1(value);
|
|
2113
|
+
|
|
1948
2114
|
if (this.isNumericRefined(attribute, operator, val)) return this;
|
|
1949
|
-
|
|
1950
|
-
mod
|
|
2115
|
+
|
|
2116
|
+
var mod = merge_1({}, this.numericRefinements);
|
|
2117
|
+
|
|
2118
|
+
mod[attribute] = merge_1({}, mod[attribute]);
|
|
2119
|
+
|
|
1951
2120
|
if (mod[attribute][operator]) {
|
|
1952
2121
|
// Array copy
|
|
1953
2122
|
mod[attribute][operator] = mod[attribute][operator].slice();
|
|
@@ -1956,8 +2125,9 @@
|
|
|
1956
2125
|
} else {
|
|
1957
2126
|
mod[attribute][operator] = [val];
|
|
1958
2127
|
}
|
|
2128
|
+
|
|
1959
2129
|
return this.setQueryParameters({
|
|
1960
|
-
numericRefinements: mod
|
|
2130
|
+
numericRefinements: mod,
|
|
1961
2131
|
});
|
|
1962
2132
|
},
|
|
1963
2133
|
/**
|
|
@@ -1965,7 +2135,7 @@
|
|
|
1965
2135
|
* @param {string} facetName name of the attribute used for faceting
|
|
1966
2136
|
* @return {string[]} list of refinements
|
|
1967
2137
|
*/
|
|
1968
|
-
getConjunctiveRefinements: function
|
|
2138
|
+
getConjunctiveRefinements: function (facetName) {
|
|
1969
2139
|
if (!this.isConjunctiveFacet(facetName)) {
|
|
1970
2140
|
return [];
|
|
1971
2141
|
}
|
|
@@ -1976,7 +2146,7 @@
|
|
|
1976
2146
|
* @param {string} facetName name of the attribute used for faceting
|
|
1977
2147
|
* @return {string[]} list of refinements
|
|
1978
2148
|
*/
|
|
1979
|
-
getDisjunctiveRefinements: function
|
|
2149
|
+
getDisjunctiveRefinements: function (facetName) {
|
|
1980
2150
|
if (!this.isDisjunctiveFacet(facetName)) {
|
|
1981
2151
|
return [];
|
|
1982
2152
|
}
|
|
@@ -1987,7 +2157,7 @@
|
|
|
1987
2157
|
* @param {string} facetName name of the attribute used for faceting
|
|
1988
2158
|
* @return {string[]} list of refinements
|
|
1989
2159
|
*/
|
|
1990
|
-
getHierarchicalRefinement: function
|
|
2160
|
+
getHierarchicalRefinement: function (facetName) {
|
|
1991
2161
|
// we send an array but we currently do not support multiple
|
|
1992
2162
|
// hierarchicalRefinements for a hierarchicalFacet
|
|
1993
2163
|
return this.hierarchicalFacetsRefinements[facetName] || [];
|
|
@@ -1997,12 +2167,13 @@
|
|
|
1997
2167
|
* @param {string} facetName name of the attribute used for faceting
|
|
1998
2168
|
* @return {string[]} list of refinements
|
|
1999
2169
|
*/
|
|
2000
|
-
getExcludeRefinements: function
|
|
2170
|
+
getExcludeRefinements: function (facetName) {
|
|
2001
2171
|
if (!this.isConjunctiveFacet(facetName)) {
|
|
2002
2172
|
return [];
|
|
2003
2173
|
}
|
|
2004
2174
|
return this.facetsExcludes[facetName] || [];
|
|
2005
2175
|
},
|
|
2176
|
+
|
|
2006
2177
|
/**
|
|
2007
2178
|
* Remove all the numeric filter for a given (attribute, operator)
|
|
2008
2179
|
* @method
|
|
@@ -2011,30 +2182,41 @@
|
|
|
2011
2182
|
* @param {number} [number] the value to be removed
|
|
2012
2183
|
* @return {SearchParameters} new instance
|
|
2013
2184
|
*/
|
|
2014
|
-
removeNumericRefinement: function
|
|
2185
|
+
removeNumericRefinement: function (attribute, operator, number) {
|
|
2015
2186
|
var paramValue = number;
|
|
2016
2187
|
if (paramValue !== undefined) {
|
|
2017
2188
|
if (!this.isNumericRefined(attribute, operator, paramValue)) {
|
|
2018
2189
|
return this;
|
|
2019
2190
|
}
|
|
2020
2191
|
return this.setQueryParameters({
|
|
2021
|
-
numericRefinements: this._clearNumericRefinements(function (
|
|
2022
|
-
|
|
2023
|
-
|
|
2192
|
+
numericRefinements: this._clearNumericRefinements(function (
|
|
2193
|
+
value,
|
|
2194
|
+
key
|
|
2195
|
+
) {
|
|
2196
|
+
return (
|
|
2197
|
+
key === attribute &&
|
|
2198
|
+
value.op === operator &&
|
|
2199
|
+
isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
|
|
2200
|
+
);
|
|
2201
|
+
}),
|
|
2024
2202
|
});
|
|
2025
2203
|
} else if (operator !== undefined) {
|
|
2026
2204
|
if (!this.isNumericRefined(attribute, operator)) return this;
|
|
2027
2205
|
return this.setQueryParameters({
|
|
2028
|
-
numericRefinements: this._clearNumericRefinements(function (
|
|
2206
|
+
numericRefinements: this._clearNumericRefinements(function (
|
|
2207
|
+
value,
|
|
2208
|
+
key
|
|
2209
|
+
) {
|
|
2029
2210
|
return key === attribute && value.op === operator;
|
|
2030
|
-
})
|
|
2211
|
+
}),
|
|
2031
2212
|
});
|
|
2032
2213
|
}
|
|
2214
|
+
|
|
2033
2215
|
if (!this.isNumericRefined(attribute)) return this;
|
|
2034
2216
|
return this.setQueryParameters({
|
|
2035
2217
|
numericRefinements: this._clearNumericRefinements(function (value, key) {
|
|
2036
2218
|
return key === attribute;
|
|
2037
|
-
})
|
|
2219
|
+
}),
|
|
2038
2220
|
});
|
|
2039
2221
|
},
|
|
2040
2222
|
/**
|
|
@@ -2042,7 +2224,7 @@
|
|
|
2042
2224
|
* @param {string} facetName name of the attribute used for faceting
|
|
2043
2225
|
* @return {SearchParameters.OperatorList} list of refinements
|
|
2044
2226
|
*/
|
|
2045
|
-
getNumericRefinements: function
|
|
2227
|
+
getNumericRefinements: function (facetName) {
|
|
2046
2228
|
return this.numericRefinements[facetName] || {};
|
|
2047
2229
|
},
|
|
2048
2230
|
/**
|
|
@@ -2051,8 +2233,11 @@
|
|
|
2051
2233
|
* @param {string} operator operator applied on the refined values
|
|
2052
2234
|
* @return {Array.<number|number[]>} refined values
|
|
2053
2235
|
*/
|
|
2054
|
-
getNumericRefinement: function
|
|
2055
|
-
return
|
|
2236
|
+
getNumericRefinement: function (attribute, operator) {
|
|
2237
|
+
return (
|
|
2238
|
+
this.numericRefinements[attribute] &&
|
|
2239
|
+
this.numericRefinements[attribute][operator]
|
|
2240
|
+
);
|
|
2056
2241
|
},
|
|
2057
2242
|
/**
|
|
2058
2243
|
* Clear numeric filters.
|
|
@@ -2075,28 +2260,36 @@
|
|
|
2075
2260
|
} else if (typeof attribute === 'function') {
|
|
2076
2261
|
var hasChanged = false;
|
|
2077
2262
|
var numericRefinements = this.numericRefinements;
|
|
2078
|
-
var newNumericRefinements = Object.keys(numericRefinements).reduce(
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
var
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
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;
|
|
2091
2284
|
});
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2285
|
+
|
|
2286
|
+
memo[key] = operatorList;
|
|
2287
|
+
|
|
2288
|
+
return memo;
|
|
2289
|
+
},
|
|
2290
|
+
{}
|
|
2291
|
+
);
|
|
2292
|
+
|
|
2100
2293
|
if (hasChanged) return newNumericRefinements;
|
|
2101
2294
|
return this.numericRefinements;
|
|
2102
2295
|
}
|
|
@@ -2116,8 +2309,9 @@
|
|
|
2116
2309
|
if (this.isConjunctiveFacet(facet)) {
|
|
2117
2310
|
return this;
|
|
2118
2311
|
}
|
|
2312
|
+
|
|
2119
2313
|
return this.setQueryParameters({
|
|
2120
|
-
facets: this.facets.concat([facet])
|
|
2314
|
+
facets: this.facets.concat([facet]),
|
|
2121
2315
|
});
|
|
2122
2316
|
},
|
|
2123
2317
|
/**
|
|
@@ -2131,8 +2325,9 @@
|
|
|
2131
2325
|
if (this.isDisjunctiveFacet(facet)) {
|
|
2132
2326
|
return this;
|
|
2133
2327
|
}
|
|
2328
|
+
|
|
2134
2329
|
return this.setQueryParameters({
|
|
2135
|
-
disjunctiveFacets: this.disjunctiveFacets.concat([facet])
|
|
2330
|
+
disjunctiveFacets: this.disjunctiveFacets.concat([facet]),
|
|
2136
2331
|
});
|
|
2137
2332
|
},
|
|
2138
2333
|
/**
|
|
@@ -2145,10 +2340,15 @@
|
|
|
2145
2340
|
*/
|
|
2146
2341
|
addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
|
|
2147
2342
|
if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
|
|
2148
|
-
throw new Error(
|
|
2343
|
+
throw new Error(
|
|
2344
|
+
'Cannot declare two hierarchical facets with the same name: `' +
|
|
2345
|
+
hierarchicalFacet.name +
|
|
2346
|
+
'`'
|
|
2347
|
+
);
|
|
2149
2348
|
}
|
|
2349
|
+
|
|
2150
2350
|
return this.setQueryParameters({
|
|
2151
|
-
hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
|
|
2351
|
+
hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet]),
|
|
2152
2352
|
});
|
|
2153
2353
|
},
|
|
2154
2354
|
/**
|
|
@@ -2160,11 +2360,20 @@
|
|
|
2160
2360
|
*/
|
|
2161
2361
|
addFacetRefinement: function addFacetRefinement(facet, value) {
|
|
2162
2362
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2163
|
-
throw new Error(
|
|
2363
|
+
throw new Error(
|
|
2364
|
+
facet +
|
|
2365
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2366
|
+
);
|
|
2164
2367
|
}
|
|
2165
|
-
if (RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2368
|
+
if (RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2369
|
+
return this;
|
|
2370
|
+
|
|
2166
2371
|
return this.setQueryParameters({
|
|
2167
|
-
facetsRefinements: RefinementList.addRefinement(
|
|
2372
|
+
facetsRefinements: RefinementList.addRefinement(
|
|
2373
|
+
this.facetsRefinements,
|
|
2374
|
+
facet,
|
|
2375
|
+
value
|
|
2376
|
+
),
|
|
2168
2377
|
});
|
|
2169
2378
|
},
|
|
2170
2379
|
/**
|
|
@@ -2176,11 +2385,20 @@
|
|
|
2176
2385
|
*/
|
|
2177
2386
|
addExcludeRefinement: function addExcludeRefinement(facet, value) {
|
|
2178
2387
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2179
|
-
throw new Error(
|
|
2388
|
+
throw new Error(
|
|
2389
|
+
facet +
|
|
2390
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2391
|
+
);
|
|
2180
2392
|
}
|
|
2181
|
-
if (RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2393
|
+
if (RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2394
|
+
return this;
|
|
2395
|
+
|
|
2182
2396
|
return this.setQueryParameters({
|
|
2183
|
-
facetsExcludes: RefinementList.addRefinement(
|
|
2397
|
+
facetsExcludes: RefinementList.addRefinement(
|
|
2398
|
+
this.facetsExcludes,
|
|
2399
|
+
facet,
|
|
2400
|
+
value
|
|
2401
|
+
),
|
|
2184
2402
|
});
|
|
2185
2403
|
},
|
|
2186
2404
|
/**
|
|
@@ -2190,13 +2408,28 @@
|
|
|
2190
2408
|
* @param {string} value value of the attribute (will be converted to string)
|
|
2191
2409
|
* @return {SearchParameters} new instance
|
|
2192
2410
|
*/
|
|
2193
|
-
addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
|
|
2411
|
+
addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
|
|
2412
|
+
facet,
|
|
2413
|
+
value
|
|
2414
|
+
) {
|
|
2194
2415
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2195
|
-
throw new Error(
|
|
2416
|
+
throw new Error(
|
|
2417
|
+
facet +
|
|
2418
|
+
' is not defined in the disjunctiveFacets attribute of the helper configuration'
|
|
2419
|
+
);
|
|
2196
2420
|
}
|
|
2197
|
-
|
|
2421
|
+
|
|
2422
|
+
if (
|
|
2423
|
+
RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
|
|
2424
|
+
)
|
|
2425
|
+
return this;
|
|
2426
|
+
|
|
2198
2427
|
return this.setQueryParameters({
|
|
2199
|
-
disjunctiveFacetsRefinements: RefinementList.addRefinement(
|
|
2428
|
+
disjunctiveFacetsRefinements: RefinementList.addRefinement(
|
|
2429
|
+
this.disjunctiveFacetsRefinements,
|
|
2430
|
+
facet,
|
|
2431
|
+
value
|
|
2432
|
+
),
|
|
2200
2433
|
});
|
|
2201
2434
|
},
|
|
2202
2435
|
/**
|
|
@@ -2206,9 +2439,11 @@
|
|
|
2206
2439
|
*/
|
|
2207
2440
|
addTagRefinement: function addTagRefinement(tag) {
|
|
2208
2441
|
if (this.isTagRefined(tag)) return this;
|
|
2442
|
+
|
|
2209
2443
|
var modification = {
|
|
2210
|
-
tagRefinements: this.tagRefinements.concat(tag)
|
|
2444
|
+
tagRefinements: this.tagRefinements.concat(tag),
|
|
2211
2445
|
};
|
|
2446
|
+
|
|
2212
2447
|
return this.setQueryParameters(modification);
|
|
2213
2448
|
},
|
|
2214
2449
|
/**
|
|
@@ -2222,10 +2457,11 @@
|
|
|
2222
2457
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2223
2458
|
return this;
|
|
2224
2459
|
}
|
|
2460
|
+
|
|
2225
2461
|
return this.clearRefinements(facet).setQueryParameters({
|
|
2226
2462
|
facets: this.facets.filter(function (f) {
|
|
2227
2463
|
return f !== facet;
|
|
2228
|
-
})
|
|
2464
|
+
}),
|
|
2229
2465
|
});
|
|
2230
2466
|
},
|
|
2231
2467
|
/**
|
|
@@ -2239,10 +2475,11 @@
|
|
|
2239
2475
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2240
2476
|
return this;
|
|
2241
2477
|
}
|
|
2478
|
+
|
|
2242
2479
|
return this.clearRefinements(facet).setQueryParameters({
|
|
2243
2480
|
disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
|
|
2244
2481
|
return f !== facet;
|
|
2245
|
-
})
|
|
2482
|
+
}),
|
|
2246
2483
|
});
|
|
2247
2484
|
},
|
|
2248
2485
|
/**
|
|
@@ -2256,10 +2493,11 @@
|
|
|
2256
2493
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2257
2494
|
return this;
|
|
2258
2495
|
}
|
|
2496
|
+
|
|
2259
2497
|
return this.clearRefinements(facet).setQueryParameters({
|
|
2260
2498
|
hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
|
|
2261
2499
|
return f.name !== facet;
|
|
2262
|
-
})
|
|
2500
|
+
}),
|
|
2263
2501
|
});
|
|
2264
2502
|
},
|
|
2265
2503
|
/**
|
|
@@ -2273,11 +2511,20 @@
|
|
|
2273
2511
|
*/
|
|
2274
2512
|
removeFacetRefinement: function removeFacetRefinement(facet, value) {
|
|
2275
2513
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2276
|
-
throw new Error(
|
|
2514
|
+
throw new Error(
|
|
2515
|
+
facet +
|
|
2516
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2517
|
+
);
|
|
2277
2518
|
}
|
|
2278
|
-
if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2519
|
+
if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
|
|
2520
|
+
return this;
|
|
2521
|
+
|
|
2279
2522
|
return this.setQueryParameters({
|
|
2280
|
-
facetsRefinements: RefinementList.removeRefinement(
|
|
2523
|
+
facetsRefinements: RefinementList.removeRefinement(
|
|
2524
|
+
this.facetsRefinements,
|
|
2525
|
+
facet,
|
|
2526
|
+
value
|
|
2527
|
+
),
|
|
2281
2528
|
});
|
|
2282
2529
|
},
|
|
2283
2530
|
/**
|
|
@@ -2289,11 +2536,20 @@
|
|
|
2289
2536
|
*/
|
|
2290
2537
|
removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
|
|
2291
2538
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2292
|
-
throw new Error(
|
|
2539
|
+
throw new Error(
|
|
2540
|
+
facet +
|
|
2541
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2542
|
+
);
|
|
2293
2543
|
}
|
|
2294
|
-
if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2544
|
+
if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
|
|
2545
|
+
return this;
|
|
2546
|
+
|
|
2295
2547
|
return this.setQueryParameters({
|
|
2296
|
-
facetsExcludes: RefinementList.removeRefinement(
|
|
2548
|
+
facetsExcludes: RefinementList.removeRefinement(
|
|
2549
|
+
this.facetsExcludes,
|
|
2550
|
+
facet,
|
|
2551
|
+
value
|
|
2552
|
+
),
|
|
2297
2553
|
});
|
|
2298
2554
|
},
|
|
2299
2555
|
/**
|
|
@@ -2303,13 +2559,27 @@
|
|
|
2303
2559
|
* @param {string} value value used to filter
|
|
2304
2560
|
* @return {SearchParameters} new instance
|
|
2305
2561
|
*/
|
|
2306
|
-
removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
|
|
2562
|
+
removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
|
|
2563
|
+
facet,
|
|
2564
|
+
value
|
|
2565
|
+
) {
|
|
2307
2566
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2308
|
-
throw new Error(
|
|
2309
|
-
|
|
2310
|
-
|
|
2567
|
+
throw new Error(
|
|
2568
|
+
facet +
|
|
2569
|
+
' is not defined in the disjunctiveFacets attribute of the helper configuration'
|
|
2570
|
+
);
|
|
2571
|
+
}
|
|
2572
|
+
if (
|
|
2573
|
+
!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
|
|
2574
|
+
)
|
|
2575
|
+
return this;
|
|
2576
|
+
|
|
2311
2577
|
return this.setQueryParameters({
|
|
2312
|
-
disjunctiveFacetsRefinements: RefinementList.removeRefinement(
|
|
2578
|
+
disjunctiveFacetsRefinements: RefinementList.removeRefinement(
|
|
2579
|
+
this.disjunctiveFacetsRefinements,
|
|
2580
|
+
facet,
|
|
2581
|
+
value
|
|
2582
|
+
),
|
|
2313
2583
|
});
|
|
2314
2584
|
},
|
|
2315
2585
|
/**
|
|
@@ -2320,11 +2590,13 @@
|
|
|
2320
2590
|
*/
|
|
2321
2591
|
removeTagRefinement: function removeTagRefinement(tag) {
|
|
2322
2592
|
if (!this.isTagRefined(tag)) return this;
|
|
2593
|
+
|
|
2323
2594
|
var modification = {
|
|
2324
2595
|
tagRefinements: this.tagRefinements.filter(function (t) {
|
|
2325
2596
|
return t !== tag;
|
|
2326
|
-
})
|
|
2597
|
+
}),
|
|
2327
2598
|
};
|
|
2599
|
+
|
|
2328
2600
|
return this.setQueryParameters(modification);
|
|
2329
2601
|
},
|
|
2330
2602
|
/**
|
|
@@ -2355,7 +2627,12 @@
|
|
|
2355
2627
|
} else if (this.isDisjunctiveFacet(facet)) {
|
|
2356
2628
|
return this.toggleDisjunctiveFacetRefinement(facet, value);
|
|
2357
2629
|
}
|
|
2358
|
-
|
|
2630
|
+
|
|
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
|
+
);
|
|
2359
2636
|
},
|
|
2360
2637
|
/**
|
|
2361
2638
|
* Switch the refinement applied over a facet/value
|
|
@@ -2364,12 +2641,23 @@
|
|
|
2364
2641
|
* @param {value} value value used for filtering
|
|
2365
2642
|
* @return {SearchParameters} new instance
|
|
2366
2643
|
*/
|
|
2367
|
-
toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
|
|
2644
|
+
toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
|
|
2645
|
+
facet,
|
|
2646
|
+
value
|
|
2647
|
+
) {
|
|
2368
2648
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2369
|
-
throw new Error(
|
|
2649
|
+
throw new Error(
|
|
2650
|
+
facet +
|
|
2651
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2652
|
+
);
|
|
2370
2653
|
}
|
|
2654
|
+
|
|
2371
2655
|
return this.setQueryParameters({
|
|
2372
|
-
facetsRefinements: RefinementList.toggleRefinement(
|
|
2656
|
+
facetsRefinements: RefinementList.toggleRefinement(
|
|
2657
|
+
this.facetsRefinements,
|
|
2658
|
+
facet,
|
|
2659
|
+
value
|
|
2660
|
+
),
|
|
2373
2661
|
});
|
|
2374
2662
|
},
|
|
2375
2663
|
/**
|
|
@@ -2379,12 +2667,23 @@
|
|
|
2379
2667
|
* @param {value} value value used for filtering
|
|
2380
2668
|
* @return {SearchParameters} new instance
|
|
2381
2669
|
*/
|
|
2382
|
-
toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
|
|
2670
|
+
toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
|
|
2671
|
+
facet,
|
|
2672
|
+
value
|
|
2673
|
+
) {
|
|
2383
2674
|
if (!this.isConjunctiveFacet(facet)) {
|
|
2384
|
-
throw new Error(
|
|
2675
|
+
throw new Error(
|
|
2676
|
+
facet +
|
|
2677
|
+
' is not defined in the facets attribute of the helper configuration'
|
|
2678
|
+
);
|
|
2385
2679
|
}
|
|
2680
|
+
|
|
2386
2681
|
return this.setQueryParameters({
|
|
2387
|
-
facetsExcludes: RefinementList.toggleRefinement(
|
|
2682
|
+
facetsExcludes: RefinementList.toggleRefinement(
|
|
2683
|
+
this.facetsExcludes,
|
|
2684
|
+
facet,
|
|
2685
|
+
value
|
|
2686
|
+
),
|
|
2388
2687
|
});
|
|
2389
2688
|
},
|
|
2390
2689
|
/**
|
|
@@ -2394,12 +2693,23 @@
|
|
|
2394
2693
|
* @param {value} value value used for filtering
|
|
2395
2694
|
* @return {SearchParameters} new instance
|
|
2396
2695
|
*/
|
|
2397
|
-
toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
|
|
2696
|
+
toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
|
|
2697
|
+
facet,
|
|
2698
|
+
value
|
|
2699
|
+
) {
|
|
2398
2700
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2399
|
-
throw new Error(
|
|
2701
|
+
throw new Error(
|
|
2702
|
+
facet +
|
|
2703
|
+
' is not defined in the disjunctiveFacets attribute of the helper configuration'
|
|
2704
|
+
);
|
|
2400
2705
|
}
|
|
2706
|
+
|
|
2401
2707
|
return this.setQueryParameters({
|
|
2402
|
-
disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
|
|
2708
|
+
disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
|
|
2709
|
+
this.disjunctiveFacetsRefinements,
|
|
2710
|
+
facet,
|
|
2711
|
+
value
|
|
2712
|
+
),
|
|
2403
2713
|
});
|
|
2404
2714
|
},
|
|
2405
2715
|
/**
|
|
@@ -2409,21 +2719,37 @@
|
|
|
2409
2719
|
* @param {value} value value used for filtering
|
|
2410
2720
|
* @return {SearchParameters} new instance
|
|
2411
2721
|
*/
|
|
2412
|
-
toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
|
|
2722
|
+
toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
|
|
2723
|
+
facet,
|
|
2724
|
+
value
|
|
2725
|
+
) {
|
|
2413
2726
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2414
|
-
throw new Error(
|
|
2727
|
+
throw new Error(
|
|
2728
|
+
facet +
|
|
2729
|
+
' is not defined in the hierarchicalFacets attribute of the helper configuration'
|
|
2730
|
+
);
|
|
2415
2731
|
}
|
|
2416
|
-
|
|
2732
|
+
|
|
2733
|
+
var separator = this._getHierarchicalFacetSeparator(
|
|
2734
|
+
this.getHierarchicalFacetByName(facet)
|
|
2735
|
+
);
|
|
2736
|
+
|
|
2417
2737
|
var mod = {};
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2738
|
+
|
|
2739
|
+
var upOneOrMultipleLevel =
|
|
2740
|
+
this.hierarchicalFacetsRefinements[facet] !== undefined &&
|
|
2741
|
+
this.hierarchicalFacetsRefinements[facet].length > 0 &&
|
|
2742
|
+
// remove current refinement:
|
|
2743
|
+
// refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
|
|
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);
|
|
2752
|
+
|
|
2427
2753
|
if (upOneOrMultipleLevel) {
|
|
2428
2754
|
if (value.indexOf(separator) === -1) {
|
|
2429
2755
|
// go back to root level
|
|
@@ -2434,10 +2760,16 @@
|
|
|
2434
2760
|
} else {
|
|
2435
2761
|
mod[facet] = [value];
|
|
2436
2762
|
}
|
|
2763
|
+
|
|
2437
2764
|
return this.setQueryParameters({
|
|
2438
|
-
hierarchicalFacetsRefinements: defaultsPure(
|
|
2765
|
+
hierarchicalFacetsRefinements: defaultsPure(
|
|
2766
|
+
{},
|
|
2767
|
+
mod,
|
|
2768
|
+
this.hierarchicalFacetsRefinements
|
|
2769
|
+
),
|
|
2439
2770
|
});
|
|
2440
2771
|
},
|
|
2772
|
+
|
|
2441
2773
|
/**
|
|
2442
2774
|
* Adds a refinement on a hierarchical facet.
|
|
2443
2775
|
* @param {string} facet the facet name
|
|
@@ -2445,33 +2777,45 @@
|
|
|
2445
2777
|
* @return {SearchParameter} the new state
|
|
2446
2778
|
* @throws Error if the facet is not defined or if the facet is refined
|
|
2447
2779
|
*/
|
|
2448
|
-
addHierarchicalFacetRefinement: function
|
|
2780
|
+
addHierarchicalFacetRefinement: function (facet, path) {
|
|
2449
2781
|
if (this.isHierarchicalFacetRefined(facet)) {
|
|
2450
2782
|
throw new Error(facet + ' is already refined.');
|
|
2451
2783
|
}
|
|
2452
2784
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2453
|
-
throw new Error(
|
|
2785
|
+
throw new Error(
|
|
2786
|
+
facet +
|
|
2787
|
+
' is not defined in the hierarchicalFacets attribute of the helper configuration.'
|
|
2788
|
+
);
|
|
2454
2789
|
}
|
|
2455
2790
|
var mod = {};
|
|
2456
2791
|
mod[facet] = [path];
|
|
2457
2792
|
return this.setQueryParameters({
|
|
2458
|
-
hierarchicalFacetsRefinements: defaultsPure(
|
|
2793
|
+
hierarchicalFacetsRefinements: defaultsPure(
|
|
2794
|
+
{},
|
|
2795
|
+
mod,
|
|
2796
|
+
this.hierarchicalFacetsRefinements
|
|
2797
|
+
),
|
|
2459
2798
|
});
|
|
2460
2799
|
},
|
|
2800
|
+
|
|
2461
2801
|
/**
|
|
2462
2802
|
* Removes the refinement set on a hierarchical facet.
|
|
2463
2803
|
* @param {string} facet the facet name
|
|
2464
2804
|
* @return {SearchParameter} the new state
|
|
2465
2805
|
* @throws Error if the facet is not defined or if the facet is not refined
|
|
2466
2806
|
*/
|
|
2467
|
-
removeHierarchicalFacetRefinement: function
|
|
2807
|
+
removeHierarchicalFacetRefinement: function (facet) {
|
|
2468
2808
|
if (!this.isHierarchicalFacetRefined(facet)) {
|
|
2469
2809
|
return this;
|
|
2470
2810
|
}
|
|
2471
2811
|
var mod = {};
|
|
2472
2812
|
mod[facet] = [];
|
|
2473
2813
|
return this.setQueryParameters({
|
|
2474
|
-
hierarchicalFacetsRefinements: defaultsPure(
|
|
2814
|
+
hierarchicalFacetsRefinements: defaultsPure(
|
|
2815
|
+
{},
|
|
2816
|
+
mod,
|
|
2817
|
+
this.hierarchicalFacetsRefinements
|
|
2818
|
+
),
|
|
2475
2819
|
});
|
|
2476
2820
|
},
|
|
2477
2821
|
/**
|
|
@@ -2484,6 +2828,7 @@
|
|
|
2484
2828
|
if (this.isTagRefined(tag)) {
|
|
2485
2829
|
return this.removeTagRefinement(tag);
|
|
2486
2830
|
}
|
|
2831
|
+
|
|
2487
2832
|
return this.addTagRefinement(tag);
|
|
2488
2833
|
},
|
|
2489
2834
|
/**
|
|
@@ -2492,7 +2837,7 @@
|
|
|
2492
2837
|
* @param {string} facet facet name to test
|
|
2493
2838
|
* @return {boolean} true if facet is a disjunctive facet
|
|
2494
2839
|
*/
|
|
2495
|
-
isDisjunctiveFacet: function
|
|
2840
|
+
isDisjunctiveFacet: function (facet) {
|
|
2496
2841
|
return this.disjunctiveFacets.indexOf(facet) > -1;
|
|
2497
2842
|
},
|
|
2498
2843
|
/**
|
|
@@ -2501,7 +2846,7 @@
|
|
|
2501
2846
|
* @param {string} facetName facet name to test
|
|
2502
2847
|
* @return {boolean} true if facetName is a hierarchical facet
|
|
2503
2848
|
*/
|
|
2504
|
-
isHierarchicalFacet: function
|
|
2849
|
+
isHierarchicalFacet: function (facetName) {
|
|
2505
2850
|
return this.getHierarchicalFacetByName(facetName) !== undefined;
|
|
2506
2851
|
},
|
|
2507
2852
|
/**
|
|
@@ -2510,7 +2855,7 @@
|
|
|
2510
2855
|
* @param {string} facet facet name to test
|
|
2511
2856
|
* @return {boolean} true if facet is a conjunctive facet
|
|
2512
2857
|
*/
|
|
2513
|
-
isConjunctiveFacet: function
|
|
2858
|
+
isConjunctiveFacet: function (facet) {
|
|
2514
2859
|
return this.facets.indexOf(facet) > -1;
|
|
2515
2860
|
},
|
|
2516
2861
|
/**
|
|
@@ -2557,7 +2902,11 @@
|
|
|
2557
2902
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
2558
2903
|
return false;
|
|
2559
2904
|
}
|
|
2560
|
-
return RefinementList.isRefined(
|
|
2905
|
+
return RefinementList.isRefined(
|
|
2906
|
+
this.disjunctiveFacetsRefinements,
|
|
2907
|
+
facet,
|
|
2908
|
+
value
|
|
2909
|
+
);
|
|
2561
2910
|
},
|
|
2562
2911
|
/**
|
|
2563
2912
|
* Returns true if the facet contains a refinement, or if a value passed is a
|
|
@@ -2568,14 +2917,20 @@
|
|
|
2568
2917
|
* if there is one, otherwise will test if the facet contains any refinement
|
|
2569
2918
|
* @return {boolean} true if the facet is refined
|
|
2570
2919
|
*/
|
|
2571
|
-
isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
|
|
2920
|
+
isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
|
|
2921
|
+
facet,
|
|
2922
|
+
value
|
|
2923
|
+
) {
|
|
2572
2924
|
if (!this.isHierarchicalFacet(facet)) {
|
|
2573
2925
|
return false;
|
|
2574
2926
|
}
|
|
2927
|
+
|
|
2575
2928
|
var refinements = this.getHierarchicalRefinement(facet);
|
|
2929
|
+
|
|
2576
2930
|
if (!value) {
|
|
2577
2931
|
return refinements.length > 0;
|
|
2578
2932
|
}
|
|
2933
|
+
|
|
2579
2934
|
return refinements.indexOf(value) !== -1;
|
|
2580
2935
|
},
|
|
2581
2936
|
/**
|
|
@@ -2592,12 +2947,20 @@
|
|
|
2592
2947
|
if (value === undefined && operator === undefined) {
|
|
2593
2948
|
return Boolean(this.numericRefinements[attribute]);
|
|
2594
2949
|
}
|
|
2595
|
-
|
|
2950
|
+
|
|
2951
|
+
var isOperatorDefined =
|
|
2952
|
+
this.numericRefinements[attribute] &&
|
|
2953
|
+
this.numericRefinements[attribute][operator] !== undefined;
|
|
2954
|
+
|
|
2596
2955
|
if (value === undefined || !isOperatorDefined) {
|
|
2597
2956
|
return isOperatorDefined;
|
|
2598
2957
|
}
|
|
2958
|
+
|
|
2599
2959
|
var parsedValue = valToNumber_1(value);
|
|
2600
|
-
var isAttributeValueDefined =
|
|
2960
|
+
var isAttributeValueDefined =
|
|
2961
|
+
findArray(this.numericRefinements[attribute][operator], parsedValue) !==
|
|
2962
|
+
undefined;
|
|
2963
|
+
|
|
2601
2964
|
return isOperatorDefined && isAttributeValueDefined;
|
|
2602
2965
|
},
|
|
2603
2966
|
/**
|
|
@@ -2621,12 +2984,19 @@
|
|
|
2621
2984
|
var self = this;
|
|
2622
2985
|
|
|
2623
2986
|
// attributes used for numeric filter can also be disjunctive
|
|
2624
|
-
var disjunctiveNumericRefinedFacets = intersection_1(
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2987
|
+
var disjunctiveNumericRefinedFacets = intersection_1(
|
|
2988
|
+
Object.keys(this.numericRefinements).filter(function (facet) {
|
|
2989
|
+
return Object.keys(self.numericRefinements[facet]).length > 0;
|
|
2990
|
+
}),
|
|
2991
|
+
this.disjunctiveFacets
|
|
2992
|
+
);
|
|
2993
|
+
|
|
2994
|
+
return Object.keys(this.disjunctiveFacetsRefinements)
|
|
2995
|
+
.filter(function (facet) {
|
|
2996
|
+
return self.disjunctiveFacetsRefinements[facet].length > 0;
|
|
2997
|
+
})
|
|
2998
|
+
.concat(disjunctiveNumericRefinedFacets)
|
|
2999
|
+
.concat(this.getRefinedHierarchicalFacets());
|
|
2630
3000
|
},
|
|
2631
3001
|
/**
|
|
2632
3002
|
* Returns the list of all disjunctive facets refined
|
|
@@ -2639,38 +3009,61 @@
|
|
|
2639
3009
|
// eslint-disable-next-line consistent-this
|
|
2640
3010
|
var self = this;
|
|
2641
3011
|
return intersection_1(
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
3012
|
+
// enforce the order between the two arrays,
|
|
3013
|
+
// so that refinement name index === hierarchical facet index
|
|
3014
|
+
this.hierarchicalFacets.map(function (facet) {
|
|
3015
|
+
return facet.name;
|
|
3016
|
+
}),
|
|
3017
|
+
Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
|
|
3018
|
+
return self.hierarchicalFacetsRefinements[facet].length > 0;
|
|
3019
|
+
})
|
|
3020
|
+
);
|
|
2649
3021
|
},
|
|
2650
3022
|
/**
|
|
2651
3023
|
* Returned the list of all disjunctive facets not refined
|
|
2652
3024
|
* @method
|
|
2653
3025
|
* @return {string[]} returns the list of facets that are not refined
|
|
2654
3026
|
*/
|
|
2655
|
-
getUnrefinedDisjunctiveFacets: function
|
|
3027
|
+
getUnrefinedDisjunctiveFacets: function () {
|
|
2656
3028
|
var refinedFacets = this.getRefinedDisjunctiveFacets();
|
|
3029
|
+
|
|
2657
3030
|
return this.disjunctiveFacets.filter(function (f) {
|
|
2658
3031
|
return refinedFacets.indexOf(f) === -1;
|
|
2659
3032
|
});
|
|
2660
3033
|
},
|
|
2661
|
-
|
|
3034
|
+
|
|
3035
|
+
managedParameters: [
|
|
3036
|
+
'index',
|
|
3037
|
+
|
|
3038
|
+
'facets',
|
|
3039
|
+
'disjunctiveFacets',
|
|
3040
|
+
'facetsRefinements',
|
|
3041
|
+
'hierarchicalFacets',
|
|
3042
|
+
'facetsExcludes',
|
|
3043
|
+
|
|
3044
|
+
'disjunctiveFacetsRefinements',
|
|
3045
|
+
'numericRefinements',
|
|
3046
|
+
'tagRefinements',
|
|
3047
|
+
'hierarchicalFacetsRefinements',
|
|
3048
|
+
],
|
|
3049
|
+
|
|
2662
3050
|
getQueryParams: function getQueryParams() {
|
|
2663
3051
|
var managedParameters = this.managedParameters;
|
|
3052
|
+
|
|
2664
3053
|
var queryParams = {};
|
|
2665
3054
|
|
|
2666
3055
|
// eslint-disable-next-line consistent-this
|
|
2667
3056
|
var self = this;
|
|
2668
3057
|
Object.keys(this).forEach(function (paramName) {
|
|
2669
3058
|
var paramValue = self[paramName];
|
|
2670
|
-
if (
|
|
3059
|
+
if (
|
|
3060
|
+
managedParameters.indexOf(paramName) === -1 &&
|
|
3061
|
+
paramValue !== undefined
|
|
3062
|
+
) {
|
|
2671
3063
|
queryParams[paramName] = paramValue;
|
|
2672
3064
|
}
|
|
2673
3065
|
});
|
|
3066
|
+
|
|
2674
3067
|
return queryParams;
|
|
2675
3068
|
},
|
|
2676
3069
|
/**
|
|
@@ -2685,8 +3078,11 @@
|
|
|
2685
3078
|
*/
|
|
2686
3079
|
setQueryParameter: function setParameter(parameter, value) {
|
|
2687
3080
|
if (this[parameter] === value) return this;
|
|
3081
|
+
|
|
2688
3082
|
var modification = {};
|
|
3083
|
+
|
|
2689
3084
|
modification[parameter] = value;
|
|
3085
|
+
|
|
2690
3086
|
return this.setQueryParameters(modification);
|
|
2691
3087
|
},
|
|
2692
3088
|
/**
|
|
@@ -2697,7 +3093,9 @@
|
|
|
2697
3093
|
*/
|
|
2698
3094
|
setQueryParameters: function setQueryParameters(params) {
|
|
2699
3095
|
if (!params) return this;
|
|
3096
|
+
|
|
2700
3097
|
var error = SearchParameters.validate(this, params);
|
|
3098
|
+
|
|
2701
3099
|
if (error) {
|
|
2702
3100
|
throw error;
|
|
2703
3101
|
}
|
|
@@ -2709,99 +3107,121 @@
|
|
|
2709
3107
|
acc[key] = self[key];
|
|
2710
3108
|
return acc;
|
|
2711
3109
|
}, {});
|
|
2712
|
-
|
|
3110
|
+
|
|
3111
|
+
var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (
|
|
3112
|
+
previous,
|
|
3113
|
+
key
|
|
3114
|
+
) {
|
|
2713
3115
|
var isPreviousValueDefined = previous[key] !== undefined;
|
|
2714
3116
|
var isNextValueDefined = nextWithNumbers[key] !== undefined;
|
|
3117
|
+
|
|
2715
3118
|
if (isPreviousValueDefined && !isNextValueDefined) {
|
|
2716
3119
|
return omit$1(previous, [key]);
|
|
2717
3120
|
}
|
|
3121
|
+
|
|
2718
3122
|
if (isNextValueDefined) {
|
|
2719
3123
|
previous[key] = nextWithNumbers[key];
|
|
2720
3124
|
}
|
|
3125
|
+
|
|
2721
3126
|
return previous;
|
|
2722
|
-
},
|
|
3127
|
+
},
|
|
3128
|
+
previousPlainObject);
|
|
3129
|
+
|
|
2723
3130
|
return new this.constructor(nextPlainObject);
|
|
2724
3131
|
},
|
|
3132
|
+
|
|
2725
3133
|
/**
|
|
2726
3134
|
* Returns a new instance with the page reset. Two scenarios possible:
|
|
2727
3135
|
* the page is omitted -> return the given instance
|
|
2728
3136
|
* the page is set -> return a new instance with a page of 0
|
|
2729
3137
|
* @return {SearchParameters} a new updated instance
|
|
2730
3138
|
*/
|
|
2731
|
-
resetPage: function
|
|
3139
|
+
resetPage: function () {
|
|
2732
3140
|
if (this.page === undefined) {
|
|
2733
3141
|
return this;
|
|
2734
3142
|
}
|
|
3143
|
+
|
|
2735
3144
|
return this.setPage(0);
|
|
2736
3145
|
},
|
|
3146
|
+
|
|
2737
3147
|
/**
|
|
2738
3148
|
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
|
|
2739
3149
|
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2740
3150
|
* @return {string} returns the hierarchicalFacet.separator or `>` as default
|
|
2741
3151
|
*/
|
|
2742
|
-
_getHierarchicalFacetSortBy: function
|
|
3152
|
+
_getHierarchicalFacetSortBy: function (hierarchicalFacet) {
|
|
2743
3153
|
return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
|
|
2744
3154
|
},
|
|
3155
|
+
|
|
2745
3156
|
/**
|
|
2746
3157
|
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
|
|
2747
3158
|
* @private
|
|
2748
3159
|
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2749
3160
|
* @return {string} returns the hierarchicalFacet.separator or `>` as default
|
|
2750
3161
|
*/
|
|
2751
|
-
_getHierarchicalFacetSeparator: function
|
|
3162
|
+
_getHierarchicalFacetSeparator: function (hierarchicalFacet) {
|
|
2752
3163
|
return hierarchicalFacet.separator || ' > ';
|
|
2753
3164
|
},
|
|
3165
|
+
|
|
2754
3166
|
/**
|
|
2755
3167
|
* Helper function to get the hierarchicalFacet prefix path or null
|
|
2756
3168
|
* @private
|
|
2757
3169
|
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2758
3170
|
* @return {string} returns the hierarchicalFacet.rootPath or null as default
|
|
2759
3171
|
*/
|
|
2760
|
-
_getHierarchicalRootPath: function
|
|
3172
|
+
_getHierarchicalRootPath: function (hierarchicalFacet) {
|
|
2761
3173
|
return hierarchicalFacet.rootPath || null;
|
|
2762
3174
|
},
|
|
3175
|
+
|
|
2763
3176
|
/**
|
|
2764
3177
|
* Helper function to check if we show the parent level of the hierarchicalFacet
|
|
2765
3178
|
* @private
|
|
2766
3179
|
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
2767
3180
|
* @return {string} returns the hierarchicalFacet.showParentLevel or true as default
|
|
2768
3181
|
*/
|
|
2769
|
-
_getHierarchicalShowParentLevel: function
|
|
3182
|
+
_getHierarchicalShowParentLevel: function (hierarchicalFacet) {
|
|
2770
3183
|
if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
|
|
2771
3184
|
return hierarchicalFacet.showParentLevel;
|
|
2772
3185
|
}
|
|
2773
3186
|
return true;
|
|
2774
3187
|
},
|
|
3188
|
+
|
|
2775
3189
|
/**
|
|
2776
3190
|
* Helper function to get the hierarchicalFacet by it's name
|
|
2777
3191
|
* @param {string} hierarchicalFacetName the hierarchicalFacet name
|
|
2778
3192
|
* @return {object} a hierarchicalFacet
|
|
2779
3193
|
*/
|
|
2780
|
-
getHierarchicalFacetByName: function
|
|
3194
|
+
getHierarchicalFacetByName: function (hierarchicalFacetName) {
|
|
2781
3195
|
return find$1(this.hierarchicalFacets, function (f) {
|
|
2782
3196
|
return f.name === hierarchicalFacetName;
|
|
2783
3197
|
});
|
|
2784
3198
|
},
|
|
3199
|
+
|
|
2785
3200
|
/**
|
|
2786
3201
|
* Get the current breadcrumb for a hierarchical facet, as an array
|
|
2787
3202
|
* @param {string} facetName Hierarchical facet name
|
|
2788
3203
|
* @return {array.<string>} the path as an array of string
|
|
2789
3204
|
*/
|
|
2790
|
-
getHierarchicalFacetBreadcrumb: function
|
|
3205
|
+
getHierarchicalFacetBreadcrumb: function (facetName) {
|
|
2791
3206
|
if (!this.isHierarchicalFacet(facetName)) {
|
|
2792
3207
|
return [];
|
|
2793
3208
|
}
|
|
3209
|
+
|
|
2794
3210
|
var refinement = this.getHierarchicalRefinement(facetName)[0];
|
|
2795
3211
|
if (!refinement) return [];
|
|
2796
|
-
|
|
3212
|
+
|
|
3213
|
+
var separator = this._getHierarchicalFacetSeparator(
|
|
3214
|
+
this.getHierarchicalFacetByName(facetName)
|
|
3215
|
+
);
|
|
2797
3216
|
var path = refinement.split(separator);
|
|
2798
3217
|
return path.map(function (part) {
|
|
2799
3218
|
return part.trim();
|
|
2800
3219
|
});
|
|
2801
3220
|
},
|
|
2802
|
-
|
|
3221
|
+
|
|
3222
|
+
toString: function () {
|
|
2803
3223
|
return JSON.stringify(this, null, 2);
|
|
2804
|
-
}
|
|
3224
|
+
},
|
|
2805
3225
|
};
|
|
2806
3226
|
|
|
2807
3227
|
/**
|
|
@@ -2819,12 +3239,22 @@
|
|
|
2819
3239
|
if (value !== other) {
|
|
2820
3240
|
var valIsDefined = value !== undefined;
|
|
2821
3241
|
var valIsNull = value === null;
|
|
3242
|
+
|
|
2822
3243
|
var othIsDefined = other !== undefined;
|
|
2823
3244
|
var othIsNull = other === null;
|
|
2824
|
-
|
|
3245
|
+
|
|
3246
|
+
if (
|
|
3247
|
+
(!othIsNull && value > other) ||
|
|
3248
|
+
(valIsNull && othIsDefined) ||
|
|
3249
|
+
!valIsDefined
|
|
3250
|
+
) {
|
|
2825
3251
|
return 1;
|
|
2826
3252
|
}
|
|
2827
|
-
if (
|
|
3253
|
+
if (
|
|
3254
|
+
(!valIsNull && value < other) ||
|
|
3255
|
+
(othIsNull && valIsDefined) ||
|
|
3256
|
+
!othIsDefined
|
|
3257
|
+
) {
|
|
2828
3258
|
return -1;
|
|
2829
3259
|
}
|
|
2830
3260
|
}
|
|
@@ -2841,20 +3271,24 @@
|
|
|
2841
3271
|
if (!Array.isArray(collection)) {
|
|
2842
3272
|
return [];
|
|
2843
3273
|
}
|
|
3274
|
+
|
|
2844
3275
|
if (!Array.isArray(orders)) {
|
|
2845
3276
|
orders = [];
|
|
2846
3277
|
}
|
|
3278
|
+
|
|
2847
3279
|
var result = collection.map(function (value, index) {
|
|
2848
3280
|
return {
|
|
2849
3281
|
criteria: iteratees.map(function (iteratee) {
|
|
2850
3282
|
return value[iteratee];
|
|
2851
3283
|
}),
|
|
2852
3284
|
index: index,
|
|
2853
|
-
value: value
|
|
3285
|
+
value: value,
|
|
2854
3286
|
};
|
|
2855
3287
|
});
|
|
3288
|
+
|
|
2856
3289
|
result.sort(function comparer(object, other) {
|
|
2857
3290
|
var index = -1;
|
|
3291
|
+
|
|
2858
3292
|
while (++index < object.criteria.length) {
|
|
2859
3293
|
var res = compareAscending(object.criteria[index], other.criteria[index]);
|
|
2860
3294
|
if (res) {
|
|
@@ -2872,16 +3306,19 @@
|
|
|
2872
3306
|
// See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
|
|
2873
3307
|
return object.index - other.index;
|
|
2874
3308
|
});
|
|
3309
|
+
|
|
2875
3310
|
return result.map(function (res) {
|
|
2876
3311
|
return res.value;
|
|
2877
3312
|
});
|
|
2878
3313
|
}
|
|
3314
|
+
|
|
2879
3315
|
var orderBy_1 = orderBy;
|
|
2880
3316
|
|
|
2881
3317
|
var compact = function compact(array) {
|
|
2882
3318
|
if (!Array.isArray(array)) {
|
|
2883
3319
|
return [];
|
|
2884
3320
|
}
|
|
3321
|
+
|
|
2885
3322
|
return array.filter(Boolean);
|
|
2886
3323
|
};
|
|
2887
3324
|
|
|
@@ -2890,6 +3327,7 @@
|
|
|
2890
3327
|
if (!Array.isArray(array)) {
|
|
2891
3328
|
return -1;
|
|
2892
3329
|
}
|
|
3330
|
+
|
|
2893
3331
|
for (var i = 0; i < array.length; i++) {
|
|
2894
3332
|
if (comparator(array[i])) {
|
|
2895
3333
|
return i;
|
|
@@ -2908,20 +3346,30 @@
|
|
|
2908
3346
|
var defaultInstructions = (defaults || []).map(function (sort) {
|
|
2909
3347
|
return sort.split(':');
|
|
2910
3348
|
});
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
3349
|
+
|
|
3350
|
+
return sortBy.reduce(
|
|
3351
|
+
function preparePredicate(out, sort) {
|
|
3352
|
+
var sortInstruction = sort.split(':');
|
|
3353
|
+
|
|
3354
|
+
var matchingDefault = find$1(
|
|
3355
|
+
defaultInstructions,
|
|
3356
|
+
function (defaultInstruction) {
|
|
3357
|
+
return defaultInstruction[0] === sortInstruction[0];
|
|
3358
|
+
}
|
|
3359
|
+
);
|
|
3360
|
+
|
|
3361
|
+
if (sortInstruction.length > 1 || !matchingDefault) {
|
|
3362
|
+
out[0].push(sortInstruction[0]);
|
|
3363
|
+
out[1].push(sortInstruction[1]);
|
|
3364
|
+
return out;
|
|
3365
|
+
}
|
|
3366
|
+
|
|
3367
|
+
out[0].push(matchingDefault[0]);
|
|
3368
|
+
out[1].push(matchingDefault[1]);
|
|
2919
3369
|
return out;
|
|
2920
|
-
}
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
return out;
|
|
2924
|
-
}, [[], []]);
|
|
3370
|
+
},
|
|
3371
|
+
[[], []]
|
|
3372
|
+
);
|
|
2925
3373
|
};
|
|
2926
3374
|
|
|
2927
3375
|
/**
|
|
@@ -2932,6 +3380,7 @@
|
|
|
2932
3380
|
*/
|
|
2933
3381
|
function escapeFacetValue(value) {
|
|
2934
3382
|
if (typeof value !== 'string') return value;
|
|
3383
|
+
|
|
2935
3384
|
return String(value).replace(/^-/, '\\-');
|
|
2936
3385
|
}
|
|
2937
3386
|
|
|
@@ -2943,11 +3392,13 @@
|
|
|
2943
3392
|
*/
|
|
2944
3393
|
function unescapeFacetValue$1(value) {
|
|
2945
3394
|
if (typeof value !== 'string') return value;
|
|
3395
|
+
|
|
2946
3396
|
return value.replace(/^\\-/, '-');
|
|
2947
3397
|
}
|
|
3398
|
+
|
|
2948
3399
|
var escapeFacetValue_1 = {
|
|
2949
3400
|
escapeFacetValue: escapeFacetValue,
|
|
2950
|
-
unescapeFacetValue: unescapeFacetValue$1
|
|
3401
|
+
unescapeFacetValue: unescapeFacetValue$1,
|
|
2951
3402
|
};
|
|
2952
3403
|
|
|
2953
3404
|
var generateHierarchicalTree_1 = generateTrees;
|
|
@@ -2955,44 +3406,78 @@
|
|
|
2955
3406
|
|
|
2956
3407
|
|
|
2957
3408
|
|
|
3409
|
+
|
|
2958
3410
|
var escapeFacetValue$1 = escapeFacetValue_1.escapeFacetValue;
|
|
2959
3411
|
var unescapeFacetValue$2 = escapeFacetValue_1.unescapeFacetValue;
|
|
3412
|
+
|
|
2960
3413
|
function generateTrees(state) {
|
|
2961
3414
|
return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
|
|
2962
3415
|
var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
|
|
2963
|
-
var hierarchicalFacetRefinement =
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
var
|
|
3416
|
+
var hierarchicalFacetRefinement =
|
|
3417
|
+
(state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
|
|
3418
|
+
state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
|
|
3419
|
+
'';
|
|
3420
|
+
var hierarchicalSeparator =
|
|
3421
|
+
state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
3422
|
+
var hierarchicalRootPath =
|
|
3423
|
+
state._getHierarchicalRootPath(hierarchicalFacet);
|
|
3424
|
+
var hierarchicalShowParentLevel =
|
|
3425
|
+
state._getHierarchicalShowParentLevel(hierarchicalFacet);
|
|
3426
|
+
var sortBy = formatSort(
|
|
3427
|
+
state._getHierarchicalFacetSortBy(hierarchicalFacet)
|
|
3428
|
+
);
|
|
3429
|
+
|
|
2968
3430
|
var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
|
|
2969
3431
|
return facetResult.exhaustive;
|
|
2970
3432
|
});
|
|
2971
|
-
|
|
3433
|
+
|
|
3434
|
+
var generateTreeFn = generateHierarchicalTree(
|
|
3435
|
+
sortBy,
|
|
3436
|
+
hierarchicalSeparator,
|
|
3437
|
+
hierarchicalRootPath,
|
|
3438
|
+
hierarchicalShowParentLevel,
|
|
3439
|
+
hierarchicalFacetRefinement
|
|
3440
|
+
);
|
|
3441
|
+
|
|
2972
3442
|
var results = hierarchicalFacetResult;
|
|
3443
|
+
|
|
2973
3444
|
if (hierarchicalRootPath) {
|
|
2974
|
-
results = hierarchicalFacetResult.slice(
|
|
3445
|
+
results = hierarchicalFacetResult.slice(
|
|
3446
|
+
hierarchicalRootPath.split(hierarchicalSeparator).length
|
|
3447
|
+
);
|
|
2975
3448
|
}
|
|
3449
|
+
|
|
2976
3450
|
return results.reduce(generateTreeFn, {
|
|
2977
3451
|
name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
|
|
2978
|
-
count: null,
|
|
2979
|
-
// root level,
|
|
2980
|
-
|
|
2981
|
-
// root level, always refined
|
|
2982
|
-
path: null,
|
|
2983
|
-
// root level, no path
|
|
3452
|
+
count: null, // root level, no count
|
|
3453
|
+
isRefined: true, // root level, always refined
|
|
3454
|
+
path: null, // root level, no path
|
|
2984
3455
|
escapedValue: null,
|
|
2985
3456
|
exhaustive: rootExhaustive,
|
|
2986
|
-
data: null
|
|
3457
|
+
data: null,
|
|
2987
3458
|
});
|
|
2988
3459
|
};
|
|
2989
3460
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
3461
|
+
|
|
3462
|
+
function generateHierarchicalTree(
|
|
3463
|
+
sortBy,
|
|
3464
|
+
hierarchicalSeparator,
|
|
3465
|
+
hierarchicalRootPath,
|
|
3466
|
+
hierarchicalShowParentLevel,
|
|
3467
|
+
currentRefinement
|
|
3468
|
+
) {
|
|
3469
|
+
return function generateTree(
|
|
3470
|
+
hierarchicalTree,
|
|
3471
|
+
hierarchicalFacetResult,
|
|
3472
|
+
currentHierarchicalLevel
|
|
3473
|
+
) {
|
|
2992
3474
|
var parent = hierarchicalTree;
|
|
3475
|
+
|
|
2993
3476
|
if (currentHierarchicalLevel > 0) {
|
|
2994
3477
|
var level = 0;
|
|
3478
|
+
|
|
2995
3479
|
parent = hierarchicalTree;
|
|
3480
|
+
|
|
2996
3481
|
while (level < currentHierarchicalLevel) {
|
|
2997
3482
|
/**
|
|
2998
3483
|
* @type {object[]]} hierarchical data
|
|
@@ -3018,51 +3503,102 @@
|
|
|
3018
3503
|
// If parent refinement is `beers`, then we do not want to have `bières > Belges`
|
|
3019
3504
|
// showing up
|
|
3020
3505
|
|
|
3021
|
-
var picked = Object.keys(hierarchicalFacetResult.data)
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3506
|
+
var picked = Object.keys(hierarchicalFacetResult.data)
|
|
3507
|
+
.map(function (facetValue) {
|
|
3508
|
+
return [facetValue, hierarchicalFacetResult.data[facetValue]];
|
|
3509
|
+
})
|
|
3510
|
+
.filter(function (tuple) {
|
|
3511
|
+
var facetValue = tuple[0];
|
|
3512
|
+
return onlyMatchingTree(
|
|
3513
|
+
facetValue,
|
|
3514
|
+
parent.path || hierarchicalRootPath,
|
|
3515
|
+
currentRefinement,
|
|
3516
|
+
hierarchicalSeparator,
|
|
3517
|
+
hierarchicalRootPath,
|
|
3518
|
+
hierarchicalShowParentLevel
|
|
3519
|
+
);
|
|
3520
|
+
});
|
|
3521
|
+
|
|
3522
|
+
parent.data = orderBy_1(
|
|
3523
|
+
picked.map(function (tuple) {
|
|
3524
|
+
var facetValue = tuple[0];
|
|
3525
|
+
var facetCount = tuple[1];
|
|
3526
|
+
|
|
3527
|
+
return format(
|
|
3528
|
+
facetCount,
|
|
3529
|
+
facetValue,
|
|
3530
|
+
hierarchicalSeparator,
|
|
3531
|
+
unescapeFacetValue$2(currentRefinement),
|
|
3532
|
+
hierarchicalFacetResult.exhaustive
|
|
3533
|
+
);
|
|
3534
|
+
}),
|
|
3535
|
+
sortBy[0],
|
|
3536
|
+
sortBy[1]
|
|
3537
|
+
);
|
|
3032
3538
|
}
|
|
3539
|
+
|
|
3033
3540
|
return hierarchicalTree;
|
|
3034
3541
|
};
|
|
3035
3542
|
}
|
|
3036
3543
|
|
|
3037
3544
|
// eslint-disable-next-line max-params
|
|
3038
|
-
function onlyMatchingTree(
|
|
3545
|
+
function onlyMatchingTree(
|
|
3546
|
+
facetValue,
|
|
3547
|
+
parentPath,
|
|
3548
|
+
currentRefinement,
|
|
3549
|
+
hierarchicalSeparator,
|
|
3550
|
+
hierarchicalRootPath,
|
|
3551
|
+
hierarchicalShowParentLevel
|
|
3552
|
+
) {
|
|
3039
3553
|
// we want the facetValue is a child of hierarchicalRootPath
|
|
3040
|
-
if (
|
|
3554
|
+
if (
|
|
3555
|
+
hierarchicalRootPath &&
|
|
3556
|
+
(facetValue.indexOf(hierarchicalRootPath) !== 0 ||
|
|
3557
|
+
hierarchicalRootPath === facetValue)
|
|
3558
|
+
) {
|
|
3041
3559
|
return false;
|
|
3042
3560
|
}
|
|
3043
3561
|
|
|
3044
3562
|
// we always want root levels (only when there is no prefix path)
|
|
3045
|
-
return
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3563
|
+
return (
|
|
3564
|
+
(!hierarchicalRootPath &&
|
|
3565
|
+
facetValue.indexOf(hierarchicalSeparator) === -1) ||
|
|
3566
|
+
// if there is a rootPath, being root level mean 1 level under rootPath
|
|
3567
|
+
(hierarchicalRootPath &&
|
|
3568
|
+
facetValue.split(hierarchicalSeparator).length -
|
|
3569
|
+
hierarchicalRootPath.split(hierarchicalSeparator).length ===
|
|
3570
|
+
1) ||
|
|
3571
|
+
// if current refinement is a root level and current facetValue is a root level,
|
|
3572
|
+
// keep the facetValue
|
|
3573
|
+
(facetValue.indexOf(hierarchicalSeparator) === -1 &&
|
|
3574
|
+
currentRefinement.indexOf(hierarchicalSeparator) === -1) ||
|
|
3575
|
+
// currentRefinement is a child of the facet value
|
|
3576
|
+
currentRefinement.indexOf(facetValue) === 0 ||
|
|
3577
|
+
// facetValue is a child of the current parent, add it
|
|
3578
|
+
(facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
|
|
3579
|
+
(hierarchicalShowParentLevel ||
|
|
3580
|
+
facetValue.indexOf(currentRefinement) === 0))
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
function format(
|
|
3585
|
+
facetCount,
|
|
3586
|
+
facetValue,
|
|
3587
|
+
hierarchicalSeparator,
|
|
3588
|
+
currentRefinement,
|
|
3589
|
+
exhaustive
|
|
3590
|
+
) {
|
|
3057
3591
|
var parts = facetValue.split(hierarchicalSeparator);
|
|
3058
3592
|
return {
|
|
3059
3593
|
name: parts[parts.length - 1].trim(),
|
|
3060
3594
|
path: facetValue,
|
|
3061
3595
|
escapedValue: escapeFacetValue$1(facetValue),
|
|
3062
3596
|
count: facetCount,
|
|
3063
|
-
isRefined:
|
|
3597
|
+
isRefined:
|
|
3598
|
+
currentRefinement === facetValue ||
|
|
3599
|
+
currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
|
|
3064
3600
|
exhaustive: exhaustive,
|
|
3065
|
-
data: null
|
|
3601
|
+
data: null,
|
|
3066
3602
|
};
|
|
3067
3603
|
}
|
|
3068
3604
|
|
|
@@ -3070,6 +3606,7 @@
|
|
|
3070
3606
|
var unescapeFacetValue$3 = escapeFacetValue_1.unescapeFacetValue;
|
|
3071
3607
|
|
|
3072
3608
|
|
|
3609
|
+
|
|
3073
3610
|
/**
|
|
3074
3611
|
* @typedef SearchResults.Facet
|
|
3075
3612
|
* @type {object}
|
|
@@ -3118,11 +3655,14 @@
|
|
|
3118
3655
|
*/
|
|
3119
3656
|
function getIndices(attributes) {
|
|
3120
3657
|
var indices = {};
|
|
3658
|
+
|
|
3121
3659
|
attributes.forEach(function (val, idx) {
|
|
3122
3660
|
indices[val] = idx;
|
|
3123
3661
|
});
|
|
3662
|
+
|
|
3124
3663
|
return indices;
|
|
3125
3664
|
}
|
|
3665
|
+
|
|
3126
3666
|
function assignFacetStats(dest, facetStats, key) {
|
|
3127
3667
|
if (facetStats && facetStats[key]) {
|
|
3128
3668
|
dest.stats = facetStats[key];
|
|
@@ -3140,11 +3680,17 @@
|
|
|
3140
3680
|
* @param {string} hierarchicalAttributeName The name of the hierarchical attribute
|
|
3141
3681
|
* @return {HierarchicalFacet} The hierarchical facet matching the attribute name
|
|
3142
3682
|
*/
|
|
3143
|
-
function findMatchingHierarchicalFacetFromAttributeName(
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3683
|
+
function findMatchingHierarchicalFacetFromAttributeName(
|
|
3684
|
+
hierarchicalFacets,
|
|
3685
|
+
hierarchicalAttributeName
|
|
3686
|
+
) {
|
|
3687
|
+
return find$1(
|
|
3688
|
+
hierarchicalFacets,
|
|
3689
|
+
function facetKeyMatchesAttribute(hierarchicalFacet) {
|
|
3690
|
+
var facetNames = hierarchicalFacet.attributes || [];
|
|
3691
|
+
return facetNames.indexOf(hierarchicalAttributeName) > -1;
|
|
3692
|
+
}
|
|
3693
|
+
);
|
|
3148
3694
|
}
|
|
3149
3695
|
|
|
3150
3696
|
// eslint-disable-next-line valid-jsdoc
|
|
@@ -3280,6 +3826,7 @@
|
|
|
3280
3826
|
**/
|
|
3281
3827
|
function SearchResults(state, results, options) {
|
|
3282
3828
|
var mainSubResponse = results[0];
|
|
3829
|
+
|
|
3283
3830
|
this._rawResults = results;
|
|
3284
3831
|
|
|
3285
3832
|
// eslint-disable-next-line consistent-this
|
|
@@ -3436,7 +3983,9 @@
|
|
|
3436
3983
|
* @instance
|
|
3437
3984
|
*/
|
|
3438
3985
|
this.processingTimeMS = results.reduce(function (sum, result) {
|
|
3439
|
-
return result.processingTimeMS === undefined
|
|
3986
|
+
return result.processingTimeMS === undefined
|
|
3987
|
+
? sum
|
|
3988
|
+
: sum + result.processingTimeMS;
|
|
3440
3989
|
}, 0);
|
|
3441
3990
|
|
|
3442
3991
|
/**
|
|
@@ -3448,15 +3997,19 @@
|
|
|
3448
3997
|
* disjunctive facets results
|
|
3449
3998
|
* @member {SearchResults.HierarchicalFacet[]}
|
|
3450
3999
|
*/
|
|
3451
|
-
this.hierarchicalFacets = state.hierarchicalFacets.map(
|
|
3452
|
-
|
|
3453
|
-
|
|
4000
|
+
this.hierarchicalFacets = state.hierarchicalFacets.map(
|
|
4001
|
+
function initFutureTree() {
|
|
4002
|
+
return [];
|
|
4003
|
+
}
|
|
4004
|
+
);
|
|
3454
4005
|
/**
|
|
3455
4006
|
* other facets results
|
|
3456
4007
|
* @member {SearchResults.Facet[]}
|
|
3457
4008
|
*/
|
|
3458
4009
|
this.facets = [];
|
|
4010
|
+
|
|
3459
4011
|
var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
|
|
4012
|
+
|
|
3460
4013
|
var facetsIndices = getIndices(state.facets);
|
|
3461
4014
|
var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
|
|
3462
4015
|
var nextDisjunctiveResult = 1;
|
|
@@ -3465,9 +4018,15 @@
|
|
|
3465
4018
|
// we get the facets information from the first, general, response.
|
|
3466
4019
|
|
|
3467
4020
|
var mainFacets = mainSubResponse.facets || {};
|
|
4021
|
+
|
|
3468
4022
|
Object.keys(mainFacets).forEach(function (facetKey) {
|
|
3469
4023
|
var facetValueObject = mainFacets[facetKey];
|
|
3470
|
-
|
|
4024
|
+
|
|
4025
|
+
var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
|
|
4026
|
+
state.hierarchicalFacets,
|
|
4027
|
+
facetKey
|
|
4028
|
+
);
|
|
4029
|
+
|
|
3471
4030
|
if (hierarchicalFacet) {
|
|
3472
4031
|
// Place the hierarchicalFacet data at the correct index depending on
|
|
3473
4032
|
// the attributes order that was defined at the helper initialization
|
|
@@ -3478,29 +4037,38 @@
|
|
|
3478
4037
|
self.hierarchicalFacets[idxAttributeName][facetIndex] = {
|
|
3479
4038
|
attribute: facetKey,
|
|
3480
4039
|
data: facetValueObject,
|
|
3481
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4040
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3482
4041
|
};
|
|
3483
4042
|
} else {
|
|
3484
4043
|
var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
|
|
3485
4044
|
var isFacetConjunctive = state.facets.indexOf(facetKey) !== -1;
|
|
3486
4045
|
var position;
|
|
4046
|
+
|
|
3487
4047
|
if (isFacetDisjunctive) {
|
|
3488
4048
|
position = disjunctiveFacetsIndices[facetKey];
|
|
3489
4049
|
self.disjunctiveFacets[position] = {
|
|
3490
4050
|
name: facetKey,
|
|
3491
4051
|
data: facetValueObject,
|
|
3492
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4052
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3493
4053
|
};
|
|
3494
|
-
assignFacetStats(
|
|
4054
|
+
assignFacetStats(
|
|
4055
|
+
self.disjunctiveFacets[position],
|
|
4056
|
+
mainSubResponse.facets_stats,
|
|
4057
|
+
facetKey
|
|
4058
|
+
);
|
|
3495
4059
|
}
|
|
3496
4060
|
if (isFacetConjunctive) {
|
|
3497
4061
|
position = facetsIndices[facetKey];
|
|
3498
4062
|
self.facets[position] = {
|
|
3499
4063
|
name: facetKey,
|
|
3500
4064
|
data: facetValueObject,
|
|
3501
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4065
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3502
4066
|
};
|
|
3503
|
-
assignFacetStats(
|
|
4067
|
+
assignFacetStats(
|
|
4068
|
+
self.facets[position],
|
|
4069
|
+
mainSubResponse.facets_stats,
|
|
4070
|
+
facetKey
|
|
4071
|
+
);
|
|
3504
4072
|
}
|
|
3505
4073
|
}
|
|
3506
4074
|
});
|
|
@@ -3517,33 +4085,58 @@
|
|
|
3517
4085
|
// There should be only item in facets.
|
|
3518
4086
|
Object.keys(facets).forEach(function (dfacet) {
|
|
3519
4087
|
var facetResults = facets[dfacet];
|
|
4088
|
+
|
|
3520
4089
|
var position;
|
|
4090
|
+
|
|
3521
4091
|
if (hierarchicalFacet) {
|
|
3522
4092
|
position = findIndex(state.hierarchicalFacets, function (f) {
|
|
3523
4093
|
return f.name === hierarchicalFacet.name;
|
|
3524
4094
|
});
|
|
3525
|
-
var attributeIndex = findIndex(
|
|
3526
|
-
|
|
3527
|
-
|
|
4095
|
+
var attributeIndex = findIndex(
|
|
4096
|
+
self.hierarchicalFacets[position],
|
|
4097
|
+
function (f) {
|
|
4098
|
+
return f.attribute === dfacet;
|
|
4099
|
+
}
|
|
4100
|
+
);
|
|
3528
4101
|
|
|
3529
4102
|
// previous refinements and no results so not able to find it
|
|
3530
4103
|
if (attributeIndex === -1) {
|
|
3531
4104
|
return;
|
|
3532
4105
|
}
|
|
3533
|
-
|
|
4106
|
+
|
|
4107
|
+
self.hierarchicalFacets[position][attributeIndex].data = merge_1(
|
|
4108
|
+
{},
|
|
4109
|
+
self.hierarchicalFacets[position][attributeIndex].data,
|
|
4110
|
+
facetResults
|
|
4111
|
+
);
|
|
3534
4112
|
} else {
|
|
3535
4113
|
position = disjunctiveFacetsIndices[dfacet];
|
|
3536
|
-
|
|
4114
|
+
|
|
4115
|
+
var dataFromMainRequest =
|
|
4116
|
+
(mainSubResponse.facets && mainSubResponse.facets[dfacet]) || {};
|
|
4117
|
+
|
|
3537
4118
|
self.disjunctiveFacets[position] = {
|
|
3538
4119
|
name: dfacet,
|
|
3539
4120
|
data: defaultsPure({}, facetResults, dataFromMainRequest),
|
|
3540
|
-
exhaustive: result.exhaustiveFacetsCount
|
|
4121
|
+
exhaustive: result.exhaustiveFacetsCount,
|
|
3541
4122
|
};
|
|
3542
|
-
assignFacetStats(
|
|
4123
|
+
assignFacetStats(
|
|
4124
|
+
self.disjunctiveFacets[position],
|
|
4125
|
+
result.facets_stats,
|
|
4126
|
+
dfacet
|
|
4127
|
+
);
|
|
4128
|
+
|
|
3543
4129
|
if (state.disjunctiveFacetsRefinements[dfacet]) {
|
|
3544
|
-
state.disjunctiveFacetsRefinements[dfacet].forEach(function (
|
|
4130
|
+
state.disjunctiveFacetsRefinements[dfacet].forEach(function (
|
|
4131
|
+
refinementValue
|
|
4132
|
+
) {
|
|
3545
4133
|
// add the disjunctive refinements if it is no more retrieved
|
|
3546
|
-
if (
|
|
4134
|
+
if (
|
|
4135
|
+
!self.disjunctiveFacets[position].data[refinementValue] &&
|
|
4136
|
+
state.disjunctiveFacetsRefinements[dfacet].indexOf(
|
|
4137
|
+
unescapeFacetValue$3(refinementValue)
|
|
4138
|
+
) > -1
|
|
4139
|
+
) {
|
|
3547
4140
|
self.disjunctiveFacets[position].data[refinementValue] = 0;
|
|
3548
4141
|
}
|
|
3549
4142
|
});
|
|
@@ -3557,22 +4150,31 @@
|
|
|
3557
4150
|
state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
|
|
3558
4151
|
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
|
|
3559
4152
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
4153
|
+
|
|
3560
4154
|
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
|
|
3561
4155
|
// if we are already at a root refinement (or no refinement at all), there is no
|
|
3562
4156
|
// root level values request
|
|
3563
|
-
if (
|
|
4157
|
+
if (
|
|
4158
|
+
currentRefinement.length === 0 ||
|
|
4159
|
+
currentRefinement[0].split(separator).length < 2
|
|
4160
|
+
) {
|
|
3564
4161
|
return;
|
|
3565
4162
|
}
|
|
4163
|
+
|
|
3566
4164
|
results.slice(nextDisjunctiveResult).forEach(function (result) {
|
|
3567
4165
|
var facets = result && result.facets ? result.facets : {};
|
|
4166
|
+
|
|
3568
4167
|
Object.keys(facets).forEach(function (dfacet) {
|
|
3569
4168
|
var facetResults = facets[dfacet];
|
|
3570
4169
|
var position = findIndex(state.hierarchicalFacets, function (f) {
|
|
3571
4170
|
return f.name === hierarchicalFacet.name;
|
|
3572
4171
|
});
|
|
3573
|
-
var attributeIndex = findIndex(
|
|
3574
|
-
|
|
3575
|
-
|
|
4172
|
+
var attributeIndex = findIndex(
|
|
4173
|
+
self.hierarchicalFacets[position],
|
|
4174
|
+
function (f) {
|
|
4175
|
+
return f.attribute === dfacet;
|
|
4176
|
+
}
|
|
4177
|
+
);
|
|
3576
4178
|
|
|
3577
4179
|
// previous refinements and no results so not able to find it
|
|
3578
4180
|
if (attributeIndex === -1) {
|
|
@@ -3588,12 +4190,20 @@
|
|
|
3588
4190
|
// | beers (5)
|
|
3589
4191
|
// > IPA (5)
|
|
3590
4192
|
var defaultData = {};
|
|
4193
|
+
|
|
3591
4194
|
if (currentRefinement.length > 0) {
|
|
3592
4195
|
var root = currentRefinement[0].split(separator)[0];
|
|
3593
|
-
defaultData[root] =
|
|
4196
|
+
defaultData[root] =
|
|
4197
|
+
self.hierarchicalFacets[position][attributeIndex].data[root];
|
|
3594
4198
|
}
|
|
3595
|
-
|
|
4199
|
+
|
|
4200
|
+
self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
|
|
4201
|
+
defaultData,
|
|
4202
|
+
facetResults,
|
|
4203
|
+
self.hierarchicalFacets[position][attributeIndex].data
|
|
4204
|
+
);
|
|
3596
4205
|
});
|
|
4206
|
+
|
|
3597
4207
|
nextDisjunctiveResult++;
|
|
3598
4208
|
});
|
|
3599
4209
|
});
|
|
@@ -3602,15 +4212,14 @@
|
|
|
3602
4212
|
Object.keys(state.facetsExcludes).forEach(function (facetName) {
|
|
3603
4213
|
var excludes = state.facetsExcludes[facetName];
|
|
3604
4214
|
var position = facetsIndices[facetName];
|
|
4215
|
+
|
|
3605
4216
|
self.facets[position] = {
|
|
3606
4217
|
name: facetName,
|
|
3607
4218
|
data: mainFacets[facetName],
|
|
3608
|
-
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
4219
|
+
exhaustive: mainSubResponse.exhaustiveFacetsCount,
|
|
3609
4220
|
};
|
|
3610
4221
|
excludes.forEach(function (facetValue) {
|
|
3611
|
-
self.facets[position] = self.facets[position] || {
|
|
3612
|
-
name: facetName
|
|
3613
|
-
};
|
|
4222
|
+
self.facets[position] = self.facets[position] || { name: facetName };
|
|
3614
4223
|
self.facets[position].data = self.facets[position].data || {};
|
|
3615
4224
|
self.facets[position].data[facetValue] = 0;
|
|
3616
4225
|
});
|
|
@@ -3619,7 +4228,9 @@
|
|
|
3619
4228
|
/**
|
|
3620
4229
|
* @type {Array}
|
|
3621
4230
|
*/
|
|
3622
|
-
this.hierarchicalFacets = this.hierarchicalFacets.map(
|
|
4231
|
+
this.hierarchicalFacets = this.hierarchicalFacets.map(
|
|
4232
|
+
generateHierarchicalTree_1(state)
|
|
4233
|
+
);
|
|
3623
4234
|
|
|
3624
4235
|
/**
|
|
3625
4236
|
* @type {Array}
|
|
@@ -3629,6 +4240,7 @@
|
|
|
3629
4240
|
* @type {Array}
|
|
3630
4241
|
*/
|
|
3631
4242
|
this.disjunctiveFacets = compact(this.disjunctiveFacets);
|
|
4243
|
+
|
|
3632
4244
|
this._state = state;
|
|
3633
4245
|
}
|
|
3634
4246
|
|
|
@@ -3642,7 +4254,12 @@
|
|
|
3642
4254
|
function predicate(facet) {
|
|
3643
4255
|
return facet.name === name;
|
|
3644
4256
|
}
|
|
3645
|
-
|
|
4257
|
+
|
|
4258
|
+
return (
|
|
4259
|
+
find$1(this.facets, predicate) ||
|
|
4260
|
+
find$1(this.disjunctiveFacets, predicate) ||
|
|
4261
|
+
find$1(this.hierarchicalFacets, predicate)
|
|
4262
|
+
);
|
|
3646
4263
|
};
|
|
3647
4264
|
|
|
3648
4265
|
/**
|
|
@@ -3656,9 +4273,11 @@
|
|
|
3656
4273
|
function predicate(facet) {
|
|
3657
4274
|
return facet.name === attribute;
|
|
3658
4275
|
}
|
|
4276
|
+
|
|
3659
4277
|
if (results._state.isConjunctiveFacet(attribute)) {
|
|
3660
4278
|
var facet = find$1(results.facets, predicate);
|
|
3661
4279
|
if (!facet) return [];
|
|
4280
|
+
|
|
3662
4281
|
return Object.keys(facet.data).map(function (name) {
|
|
3663
4282
|
var value = escapeFacetValue$2(name);
|
|
3664
4283
|
return {
|
|
@@ -3666,35 +4285,49 @@
|
|
|
3666
4285
|
escapedValue: value,
|
|
3667
4286
|
count: facet.data[name],
|
|
3668
4287
|
isRefined: results._state.isFacetRefined(attribute, value),
|
|
3669
|
-
isExcluded: results._state.isExcludeRefined(attribute, name)
|
|
4288
|
+
isExcluded: results._state.isExcludeRefined(attribute, name),
|
|
3670
4289
|
};
|
|
3671
4290
|
});
|
|
3672
4291
|
} else if (results._state.isDisjunctiveFacet(attribute)) {
|
|
3673
4292
|
var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
|
|
3674
4293
|
if (!disjunctiveFacet) return [];
|
|
4294
|
+
|
|
3675
4295
|
return Object.keys(disjunctiveFacet.data).map(function (name) {
|
|
3676
4296
|
var value = escapeFacetValue$2(name);
|
|
3677
4297
|
return {
|
|
3678
4298
|
name: name,
|
|
3679
4299
|
escapedValue: value,
|
|
3680
4300
|
count: disjunctiveFacet.data[name],
|
|
3681
|
-
isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
|
|
4301
|
+
isRefined: results._state.isDisjunctiveFacetRefined(attribute, value),
|
|
3682
4302
|
};
|
|
3683
4303
|
});
|
|
3684
4304
|
} else if (results._state.isHierarchicalFacet(attribute)) {
|
|
3685
4305
|
var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
|
|
3686
4306
|
if (!hierarchicalFacetValues) return hierarchicalFacetValues;
|
|
3687
|
-
|
|
3688
|
-
var
|
|
3689
|
-
|
|
4307
|
+
|
|
4308
|
+
var hierarchicalFacet =
|
|
4309
|
+
results._state.getHierarchicalFacetByName(attribute);
|
|
4310
|
+
var separator =
|
|
4311
|
+
results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
4312
|
+
var currentRefinement = unescapeFacetValue$3(
|
|
4313
|
+
results._state.getHierarchicalRefinement(attribute)[0] || ''
|
|
4314
|
+
);
|
|
4315
|
+
|
|
3690
4316
|
if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
|
|
3691
|
-
currentRefinement = currentRefinement.replace(
|
|
4317
|
+
currentRefinement = currentRefinement.replace(
|
|
4318
|
+
hierarchicalFacet.rootPath + separator,
|
|
4319
|
+
''
|
|
4320
|
+
);
|
|
3692
4321
|
}
|
|
4322
|
+
|
|
3693
4323
|
var currentRefinementSplit = currentRefinement.split(separator);
|
|
3694
4324
|
currentRefinementSplit.unshift(attribute);
|
|
4325
|
+
|
|
3695
4326
|
setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
|
|
4327
|
+
|
|
3696
4328
|
return hierarchicalFacetValues;
|
|
3697
4329
|
}
|
|
4330
|
+
|
|
3698
4331
|
return undefined;
|
|
3699
4332
|
}
|
|
3700
4333
|
|
|
@@ -3725,22 +4358,25 @@
|
|
|
3725
4358
|
*/
|
|
3726
4359
|
function recSort(sortFn, node, names, level) {
|
|
3727
4360
|
level = level || 0;
|
|
4361
|
+
|
|
3728
4362
|
if (Array.isArray(node)) {
|
|
3729
4363
|
return sortFn(node, names[level]);
|
|
3730
4364
|
}
|
|
4365
|
+
|
|
3731
4366
|
if (!node.data || node.data.length === 0) {
|
|
3732
4367
|
return node;
|
|
3733
4368
|
}
|
|
4369
|
+
|
|
3734
4370
|
var children = node.data.map(function (childNode) {
|
|
3735
4371
|
return recSort(sortFn, childNode, names, level + 1);
|
|
3736
4372
|
});
|
|
3737
4373
|
var sortedChildren = sortFn(children, names[level]);
|
|
3738
|
-
var newNode = defaultsPure({
|
|
3739
|
-
data: sortedChildren
|
|
3740
|
-
}, node);
|
|
4374
|
+
var newNode = defaultsPure({ data: sortedChildren }, node);
|
|
3741
4375
|
return newNode;
|
|
3742
4376
|
}
|
|
4377
|
+
|
|
3743
4378
|
SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
|
|
4379
|
+
|
|
3744
4380
|
function vanillaSortFn(order, data) {
|
|
3745
4381
|
return data.sort(order);
|
|
3746
4382
|
}
|
|
@@ -3761,6 +4397,7 @@
|
|
|
3761
4397
|
function sortViaFacetOrdering(facetValues, facetOrdering) {
|
|
3762
4398
|
var orderedFacets = [];
|
|
3763
4399
|
var remainingFacets = [];
|
|
4400
|
+
|
|
3764
4401
|
var order = facetOrdering.order || [];
|
|
3765
4402
|
/**
|
|
3766
4403
|
* an object with the keys being the values in order, the values their index:
|
|
@@ -3770,6 +4407,7 @@
|
|
|
3770
4407
|
acc[name] = i;
|
|
3771
4408
|
return acc;
|
|
3772
4409
|
}, {});
|
|
4410
|
+
|
|
3773
4411
|
facetValues.forEach(function (item) {
|
|
3774
4412
|
// hierarchical facets get sorted using their raw name
|
|
3775
4413
|
var name = item.path || item.name;
|
|
@@ -3779,19 +4417,27 @@
|
|
|
3779
4417
|
remainingFacets.push(item);
|
|
3780
4418
|
}
|
|
3781
4419
|
});
|
|
4420
|
+
|
|
3782
4421
|
orderedFacets = orderedFacets.filter(function (facet) {
|
|
3783
4422
|
return facet;
|
|
3784
4423
|
});
|
|
4424
|
+
|
|
3785
4425
|
var sortRemainingBy = facetOrdering.sortRemainingBy;
|
|
3786
4426
|
var ordering;
|
|
3787
4427
|
if (sortRemainingBy === 'hidden') {
|
|
3788
4428
|
return orderedFacets;
|
|
3789
4429
|
} else if (sortRemainingBy === 'alpha') {
|
|
3790
|
-
ordering = [
|
|
4430
|
+
ordering = [
|
|
4431
|
+
['path', 'name'],
|
|
4432
|
+
['asc', 'asc'],
|
|
4433
|
+
];
|
|
3791
4434
|
} else {
|
|
3792
4435
|
ordering = [['count'], ['desc']];
|
|
3793
4436
|
}
|
|
3794
|
-
|
|
4437
|
+
|
|
4438
|
+
return orderedFacets.concat(
|
|
4439
|
+
orderBy_1(remainingFacets, ordering[0], ordering[1])
|
|
4440
|
+
);
|
|
3795
4441
|
}
|
|
3796
4442
|
|
|
3797
4443
|
/**
|
|
@@ -3800,7 +4446,12 @@
|
|
|
3800
4446
|
* @returns {FacetOrdering | undefined} the facet ordering
|
|
3801
4447
|
*/
|
|
3802
4448
|
function getFacetOrdering(results, attribute) {
|
|
3803
|
-
return
|
|
4449
|
+
return (
|
|
4450
|
+
results.renderingContent &&
|
|
4451
|
+
results.renderingContent.facetOrdering &&
|
|
4452
|
+
results.renderingContent.facetOrdering.values &&
|
|
4453
|
+
results.renderingContent.facetOrdering.values[attribute]
|
|
4454
|
+
);
|
|
3804
4455
|
}
|
|
3805
4456
|
|
|
3806
4457
|
/**
|
|
@@ -3856,11 +4507,12 @@
|
|
|
3856
4507
|
if (!facetValues) {
|
|
3857
4508
|
return undefined;
|
|
3858
4509
|
}
|
|
4510
|
+
|
|
3859
4511
|
var options = defaultsPure({}, opts, {
|
|
3860
4512
|
sortBy: SearchResults.DEFAULT_SORT,
|
|
3861
4513
|
// if no sortBy is given, attempt to sort based on facetOrdering
|
|
3862
4514
|
// if it is given, we still allow to sort via facet ordering first
|
|
3863
|
-
facetOrdering: !(opts && opts.sortBy)
|
|
4515
|
+
facetOrdering: !(opts && opts.sortBy),
|
|
3864
4516
|
});
|
|
3865
4517
|
|
|
3866
4518
|
// eslint-disable-next-line consistent-this
|
|
@@ -3872,21 +4524,30 @@
|
|
|
3872
4524
|
var config = results._state.getHierarchicalFacetByName(facetValues.name);
|
|
3873
4525
|
attributes = config.attributes;
|
|
3874
4526
|
}
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
if (facetOrdering) {
|
|
3879
|
-
|
|
4527
|
+
|
|
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
|
+
}
|
|
3880
4535
|
}
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
4536
|
+
|
|
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
|
+
);
|
|
3890
4551
|
};
|
|
3891
4552
|
|
|
3892
4553
|
/**
|
|
@@ -3901,6 +4562,7 @@
|
|
|
3901
4562
|
} else if (this._state.isDisjunctiveFacet(attribute)) {
|
|
3902
4563
|
return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
|
|
3903
4564
|
}
|
|
4565
|
+
|
|
3904
4566
|
return undefined;
|
|
3905
4567
|
};
|
|
3906
4568
|
|
|
@@ -3938,26 +4600,54 @@
|
|
|
3938
4600
|
// eslint-disable-next-line consistent-this
|
|
3939
4601
|
var results = this;
|
|
3940
4602
|
var res = [];
|
|
4603
|
+
|
|
3941
4604
|
Object.keys(state.facetsRefinements).forEach(function (attributeName) {
|
|
3942
4605
|
state.facetsRefinements[attributeName].forEach(function (name) {
|
|
3943
|
-
res.push(
|
|
4606
|
+
res.push(
|
|
4607
|
+
getRefinement(state, 'facet', attributeName, name, results.facets)
|
|
4608
|
+
);
|
|
3944
4609
|
});
|
|
3945
4610
|
});
|
|
4611
|
+
|
|
3946
4612
|
Object.keys(state.facetsExcludes).forEach(function (attributeName) {
|
|
3947
4613
|
state.facetsExcludes[attributeName].forEach(function (name) {
|
|
3948
|
-
res.push(
|
|
4614
|
+
res.push(
|
|
4615
|
+
getRefinement(state, 'exclude', attributeName, name, results.facets)
|
|
4616
|
+
);
|
|
3949
4617
|
});
|
|
3950
4618
|
});
|
|
3951
|
-
|
|
4619
|
+
|
|
4620
|
+
Object.keys(state.disjunctiveFacetsRefinements).forEach(function (
|
|
4621
|
+
attributeName
|
|
4622
|
+
) {
|
|
3952
4623
|
state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
|
|
3953
|
-
res.push(
|
|
4624
|
+
res.push(
|
|
4625
|
+
getRefinement(
|
|
4626
|
+
state,
|
|
4627
|
+
'disjunctive',
|
|
4628
|
+
attributeName,
|
|
4629
|
+
name,
|
|
4630
|
+
results.disjunctiveFacets
|
|
4631
|
+
)
|
|
4632
|
+
);
|
|
3954
4633
|
});
|
|
3955
4634
|
});
|
|
3956
|
-
|
|
4635
|
+
|
|
4636
|
+
Object.keys(state.hierarchicalFacetsRefinements).forEach(function (
|
|
4637
|
+
attributeName
|
|
4638
|
+
) {
|
|
3957
4639
|
state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
|
|
3958
|
-
res.push(
|
|
4640
|
+
res.push(
|
|
4641
|
+
getHierarchicalRefinement(
|
|
4642
|
+
state,
|
|
4643
|
+
attributeName,
|
|
4644
|
+
name,
|
|
4645
|
+
results.hierarchicalFacets
|
|
4646
|
+
)
|
|
4647
|
+
);
|
|
3959
4648
|
});
|
|
3960
4649
|
});
|
|
4650
|
+
|
|
3961
4651
|
Object.keys(state.numericRefinements).forEach(function (attributeName) {
|
|
3962
4652
|
var operators = state.numericRefinements[attributeName];
|
|
3963
4653
|
Object.keys(operators).forEach(function (operator) {
|
|
@@ -3967,18 +4657,16 @@
|
|
|
3967
4657
|
attributeName: attributeName,
|
|
3968
4658
|
name: value,
|
|
3969
4659
|
numericValue: value,
|
|
3970
|
-
operator: operator
|
|
4660
|
+
operator: operator,
|
|
3971
4661
|
});
|
|
3972
4662
|
});
|
|
3973
4663
|
});
|
|
3974
4664
|
});
|
|
4665
|
+
|
|
3975
4666
|
state.tagRefinements.forEach(function (name) {
|
|
3976
|
-
res.push({
|
|
3977
|
-
type: 'tag',
|
|
3978
|
-
attributeName: '_tags',
|
|
3979
|
-
name: name
|
|
3980
|
-
});
|
|
4667
|
+
res.push({ type: 'tag', attributeName: '_tags', name: name });
|
|
3981
4668
|
});
|
|
4669
|
+
|
|
3982
4670
|
return res;
|
|
3983
4671
|
};
|
|
3984
4672
|
|
|
@@ -4002,13 +4690,14 @@
|
|
|
4002
4690
|
return f.name === attributeName;
|
|
4003
4691
|
});
|
|
4004
4692
|
var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
|
|
4005
|
-
var exhaustive = facet && facet.exhaustive || false;
|
|
4693
|
+
var exhaustive = (facet && facet.exhaustive) || false;
|
|
4694
|
+
|
|
4006
4695
|
return {
|
|
4007
4696
|
type: type,
|
|
4008
4697
|
attributeName: attributeName,
|
|
4009
4698
|
name: name,
|
|
4010
4699
|
count: count,
|
|
4011
|
-
exhaustive: exhaustive
|
|
4700
|
+
exhaustive: exhaustive,
|
|
4012
4701
|
};
|
|
4013
4702
|
}
|
|
4014
4703
|
|
|
@@ -4026,23 +4715,29 @@
|
|
|
4026
4715
|
var rootFacet = find$1(resultsFacets, function (facet) {
|
|
4027
4716
|
return facet.name === attributeName;
|
|
4028
4717
|
});
|
|
4718
|
+
|
|
4029
4719
|
var facet = split.reduce(function (intermediateFacet, part) {
|
|
4030
|
-
var newFacet =
|
|
4031
|
-
|
|
4032
|
-
|
|
4720
|
+
var newFacet =
|
|
4721
|
+
intermediateFacet &&
|
|
4722
|
+
find$1(intermediateFacet.data, function (f) {
|
|
4723
|
+
return f.name === part;
|
|
4724
|
+
});
|
|
4033
4725
|
return newFacet !== undefined ? newFacet : intermediateFacet;
|
|
4034
4726
|
}, rootFacet);
|
|
4035
|
-
|
|
4036
|
-
var
|
|
4037
|
-
var
|
|
4727
|
+
|
|
4728
|
+
var count = (facet && facet.count) || 0;
|
|
4729
|
+
var exhaustive = (facet && facet.exhaustive) || false;
|
|
4730
|
+
var path = (facet && facet.path) || '';
|
|
4731
|
+
|
|
4038
4732
|
return {
|
|
4039
4733
|
type: 'hierarchical',
|
|
4040
4734
|
attributeName: attributeName,
|
|
4041
4735
|
name: path,
|
|
4042
4736
|
count: count,
|
|
4043
|
-
exhaustive: exhaustive
|
|
4737
|
+
exhaustive: exhaustive,
|
|
4044
4738
|
};
|
|
4045
4739
|
}
|
|
4740
|
+
|
|
4046
4741
|
var SearchResults_1 = SearchResults;
|
|
4047
4742
|
|
|
4048
4743
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
@@ -4354,10 +5049,11 @@
|
|
|
4354
5049
|
value: ctor,
|
|
4355
5050
|
enumerable: false,
|
|
4356
5051
|
writable: true,
|
|
4357
|
-
configurable: true
|
|
4358
|
-
}
|
|
5052
|
+
configurable: true,
|
|
5053
|
+
},
|
|
4359
5054
|
});
|
|
4360
5055
|
}
|
|
5056
|
+
|
|
4361
5057
|
var inherits_1 = inherits;
|
|
4362
5058
|
|
|
4363
5059
|
/**
|
|
@@ -4377,6 +5073,7 @@
|
|
|
4377
5073
|
this.fn = fn;
|
|
4378
5074
|
this.lastResults = null;
|
|
4379
5075
|
}
|
|
5076
|
+
|
|
4380
5077
|
inherits_1(DerivedHelper, events);
|
|
4381
5078
|
|
|
4382
5079
|
/**
|
|
@@ -4388,19 +5085,24 @@
|
|
|
4388
5085
|
this.removeAllListeners();
|
|
4389
5086
|
this.main.detachDerivedHelper(this);
|
|
4390
5087
|
};
|
|
5088
|
+
|
|
4391
5089
|
DerivedHelper.prototype.getModifiedState = function (parameters) {
|
|
4392
5090
|
return this.fn(parameters);
|
|
4393
5091
|
};
|
|
5092
|
+
|
|
4394
5093
|
var DerivedHelper_1 = DerivedHelper;
|
|
4395
5094
|
|
|
4396
5095
|
function sortObject(obj) {
|
|
4397
|
-
return Object.keys(obj)
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
5096
|
+
return Object.keys(obj)
|
|
5097
|
+
.sort(function (a, b) {
|
|
5098
|
+
return a.localeCompare(b);
|
|
5099
|
+
})
|
|
5100
|
+
.reduce(function (acc, curr) {
|
|
5101
|
+
acc[curr] = obj[curr];
|
|
5102
|
+
return acc;
|
|
5103
|
+
}, {});
|
|
4403
5104
|
}
|
|
5105
|
+
|
|
4404
5106
|
var requestBuilder = {
|
|
4405
5107
|
/**
|
|
4406
5108
|
* Get all the queries to send to the client, those queries can used directly
|
|
@@ -4416,14 +5118,17 @@
|
|
|
4416
5118
|
// One query for the hits
|
|
4417
5119
|
queries.push({
|
|
4418
5120
|
indexName: index,
|
|
4419
|
-
params: requestBuilder._getHitsSearchParams(state)
|
|
5121
|
+
params: requestBuilder._getHitsSearchParams(state),
|
|
4420
5122
|
});
|
|
4421
5123
|
|
|
4422
5124
|
// One for each disjunctive facets
|
|
4423
5125
|
state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
|
|
4424
5126
|
queries.push({
|
|
4425
5127
|
indexName: index,
|
|
4426
|
-
params: requestBuilder._getDisjunctiveFacetSearchParams(
|
|
5128
|
+
params: requestBuilder._getDisjunctiveFacetSearchParams(
|
|
5129
|
+
state,
|
|
5130
|
+
refinedFacet
|
|
5131
|
+
),
|
|
4427
5132
|
});
|
|
4428
5133
|
});
|
|
4429
5134
|
|
|
@@ -4435,16 +5140,30 @@
|
|
|
4435
5140
|
|
|
4436
5141
|
// If we are deeper than level 0 (starting from `beer > IPA`)
|
|
4437
5142
|
// we want to get all parent values
|
|
4438
|
-
if (
|
|
5143
|
+
if (
|
|
5144
|
+
currentRefinement.length > 0 &&
|
|
5145
|
+
currentRefinement[0].split(separator).length > 1
|
|
5146
|
+
) {
|
|
4439
5147
|
// We generate a map of the filters we will use for our facet values queries
|
|
4440
|
-
var filtersMap = currentRefinement[0]
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
5148
|
+
var filtersMap = currentRefinement[0]
|
|
5149
|
+
.split(separator)
|
|
5150
|
+
.slice(0, -1)
|
|
5151
|
+
.reduce(function createFiltersMap(map, segment, level) {
|
|
5152
|
+
return map.concat({
|
|
5153
|
+
attribute: hierarchicalFacet.attributes[level],
|
|
5154
|
+
value:
|
|
5155
|
+
level === 0
|
|
5156
|
+
? segment
|
|
5157
|
+
: [map[map.length - 1].value, segment].join(separator),
|
|
5158
|
+
});
|
|
5159
|
+
}, []);
|
|
5160
|
+
|
|
4446
5161
|
filtersMap.forEach(function (filter, level) {
|
|
4447
|
-
var params = requestBuilder._getDisjunctiveFacetSearchParams(
|
|
5162
|
+
var params = requestBuilder._getDisjunctiveFacetSearchParams(
|
|
5163
|
+
state,
|
|
5164
|
+
filter.attribute,
|
|
5165
|
+
level === 0
|
|
5166
|
+
);
|
|
4448
5167
|
|
|
4449
5168
|
// Keep facet filters unrelated to current hierarchical attributes
|
|
4450
5169
|
function hasHierarchicalFacetFilter(value) {
|
|
@@ -4452,58 +5171,81 @@
|
|
|
4452
5171
|
return attribute === value.split(':')[0];
|
|
4453
5172
|
});
|
|
4454
5173
|
}
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
5174
|
+
|
|
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
|
+
});
|
|
5181
|
+
|
|
5182
|
+
if (filtered.length > 0) {
|
|
5183
|
+
acc.push(filtered);
|
|
5184
|
+
}
|
|
4462
5185
|
}
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
5186
|
+
|
|
5187
|
+
if (
|
|
5188
|
+
typeof facetFilter === 'string' &&
|
|
5189
|
+
!hasHierarchicalFacetFilter(facetFilter)
|
|
5190
|
+
) {
|
|
5191
|
+
acc.push(facetFilter);
|
|
5192
|
+
}
|
|
5193
|
+
|
|
5194
|
+
return acc;
|
|
5195
|
+
},
|
|
5196
|
+
[]
|
|
5197
|
+
);
|
|
5198
|
+
|
|
4469
5199
|
var parent = filtersMap[level - 1];
|
|
4470
5200
|
if (level > 0) {
|
|
4471
|
-
params.facetFilters = filteredFacetFilters.concat(
|
|
5201
|
+
params.facetFilters = filteredFacetFilters.concat(
|
|
5202
|
+
parent.attribute + ':' + parent.value
|
|
5203
|
+
);
|
|
4472
5204
|
} else {
|
|
4473
|
-
params.facetFilters =
|
|
5205
|
+
params.facetFilters =
|
|
5206
|
+
filteredFacetFilters.length > 0
|
|
5207
|
+
? filteredFacetFilters
|
|
5208
|
+
: undefined;
|
|
4474
5209
|
}
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
params: params
|
|
4478
|
-
});
|
|
5210
|
+
|
|
5211
|
+
queries.push({ indexName: index, params: params });
|
|
4479
5212
|
});
|
|
4480
5213
|
}
|
|
4481
5214
|
});
|
|
5215
|
+
|
|
4482
5216
|
return queries;
|
|
4483
5217
|
},
|
|
5218
|
+
|
|
4484
5219
|
/**
|
|
4485
5220
|
* Build search parameters used to fetch hits
|
|
4486
5221
|
* @private
|
|
4487
5222
|
* @param {SearchParameters} state The state from which to get the queries
|
|
4488
5223
|
* @return {object.<string, any>} The search parameters for hits
|
|
4489
5224
|
*/
|
|
4490
|
-
_getHitsSearchParams: function
|
|
4491
|
-
var facets = state.facets
|
|
5225
|
+
_getHitsSearchParams: function (state) {
|
|
5226
|
+
var facets = state.facets
|
|
5227
|
+
.concat(state.disjunctiveFacets)
|
|
5228
|
+
.concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
|
|
5229
|
+
|
|
4492
5230
|
var facetFilters = requestBuilder._getFacetFilters(state);
|
|
4493
5231
|
var numericFilters = requestBuilder._getNumericFilters(state);
|
|
4494
5232
|
var tagFilters = requestBuilder._getTagFilters(state);
|
|
4495
5233
|
var additionalParams = {
|
|
4496
5234
|
facets: facets.indexOf('*') > -1 ? ['*'] : facets,
|
|
4497
|
-
tagFilters: tagFilters
|
|
5235
|
+
tagFilters: tagFilters,
|
|
4498
5236
|
};
|
|
5237
|
+
|
|
4499
5238
|
if (facetFilters.length > 0) {
|
|
4500
5239
|
additionalParams.facetFilters = facetFilters;
|
|
4501
5240
|
}
|
|
5241
|
+
|
|
4502
5242
|
if (numericFilters.length > 0) {
|
|
4503
5243
|
additionalParams.numericFilters = numericFilters;
|
|
4504
5244
|
}
|
|
4505
|
-
|
|
5245
|
+
|
|
5246
|
+
return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
|
|
4506
5247
|
},
|
|
5248
|
+
|
|
4507
5249
|
/**
|
|
4508
5250
|
* Build search parameters used to fetch a disjunctive facet
|
|
4509
5251
|
* @private
|
|
@@ -4512,33 +5254,53 @@
|
|
|
4512
5254
|
* @param {boolean} hierarchicalRootLevel ?? FIXME
|
|
4513
5255
|
* @return {object} The search parameters for a disjunctive facet
|
|
4514
5256
|
*/
|
|
4515
|
-
_getDisjunctiveFacetSearchParams: function
|
|
4516
|
-
|
|
5257
|
+
_getDisjunctiveFacetSearchParams: function (
|
|
5258
|
+
state,
|
|
5259
|
+
facet,
|
|
5260
|
+
hierarchicalRootLevel
|
|
5261
|
+
) {
|
|
5262
|
+
var facetFilters = requestBuilder._getFacetFilters(
|
|
5263
|
+
state,
|
|
5264
|
+
facet,
|
|
5265
|
+
hierarchicalRootLevel
|
|
5266
|
+
);
|
|
4517
5267
|
var numericFilters = requestBuilder._getNumericFilters(state, facet);
|
|
4518
5268
|
var tagFilters = requestBuilder._getTagFilters(state);
|
|
4519
5269
|
var additionalParams = {
|
|
4520
5270
|
hitsPerPage: 0,
|
|
4521
5271
|
page: 0,
|
|
4522
5272
|
analytics: false,
|
|
4523
|
-
clickAnalytics: false
|
|
5273
|
+
clickAnalytics: false,
|
|
4524
5274
|
};
|
|
5275
|
+
|
|
4525
5276
|
if (tagFilters.length > 0) {
|
|
4526
5277
|
additionalParams.tagFilters = tagFilters;
|
|
4527
5278
|
}
|
|
5279
|
+
|
|
4528
5280
|
var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
|
|
5281
|
+
|
|
4529
5282
|
if (hierarchicalFacet) {
|
|
4530
|
-
additionalParams.facets =
|
|
5283
|
+
additionalParams.facets =
|
|
5284
|
+
requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
|
|
5285
|
+
state,
|
|
5286
|
+
hierarchicalFacet,
|
|
5287
|
+
hierarchicalRootLevel
|
|
5288
|
+
);
|
|
4531
5289
|
} else {
|
|
4532
5290
|
additionalParams.facets = facet;
|
|
4533
5291
|
}
|
|
5292
|
+
|
|
4534
5293
|
if (numericFilters.length > 0) {
|
|
4535
5294
|
additionalParams.numericFilters = numericFilters;
|
|
4536
5295
|
}
|
|
5296
|
+
|
|
4537
5297
|
if (facetFilters.length > 0) {
|
|
4538
5298
|
additionalParams.facetFilters = facetFilters;
|
|
4539
5299
|
}
|
|
4540
|
-
|
|
5300
|
+
|
|
5301
|
+
return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
|
|
4541
5302
|
},
|
|
5303
|
+
|
|
4542
5304
|
/**
|
|
4543
5305
|
* Return the numeric filters in an algolia request fashion
|
|
4544
5306
|
* @private
|
|
@@ -4546,11 +5308,13 @@
|
|
|
4546
5308
|
* @param {string} [facetName] the name of the attribute for which the filters should be excluded
|
|
4547
5309
|
* @return {string[]} the numeric filters in the algolia format
|
|
4548
5310
|
*/
|
|
4549
|
-
_getNumericFilters: function
|
|
5311
|
+
_getNumericFilters: function (state, facetName) {
|
|
4550
5312
|
if (state.numericFilters) {
|
|
4551
5313
|
return state.numericFilters;
|
|
4552
5314
|
}
|
|
5315
|
+
|
|
4553
5316
|
var numericFilters = [];
|
|
5317
|
+
|
|
4554
5318
|
Object.keys(state.numericRefinements).forEach(function (attribute) {
|
|
4555
5319
|
var operators = state.numericRefinements[attribute] || {};
|
|
4556
5320
|
Object.keys(operators).forEach(function (operator) {
|
|
@@ -4569,20 +5333,24 @@
|
|
|
4569
5333
|
}
|
|
4570
5334
|
});
|
|
4571
5335
|
});
|
|
5336
|
+
|
|
4572
5337
|
return numericFilters;
|
|
4573
5338
|
},
|
|
5339
|
+
|
|
4574
5340
|
/**
|
|
4575
5341
|
* Return the tags filters depending on which format is used, either tagFilters or tagRefinements
|
|
4576
5342
|
* @private
|
|
4577
5343
|
* @param {SearchParameters} state the state from which to get the filters
|
|
4578
5344
|
* @return {string} Tag filters in a single string
|
|
4579
5345
|
*/
|
|
4580
|
-
_getTagFilters: function
|
|
5346
|
+
_getTagFilters: function (state) {
|
|
4581
5347
|
if (state.tagFilters) {
|
|
4582
5348
|
return state.tagFilters;
|
|
4583
5349
|
}
|
|
5350
|
+
|
|
4584
5351
|
return state.tagRefinements.join(',');
|
|
4585
5352
|
},
|
|
5353
|
+
|
|
4586
5354
|
/**
|
|
4587
5355
|
* Build facetFilters parameter based on current refinements. The array returned
|
|
4588
5356
|
* contains strings representing the facet filters in the algolia format.
|
|
@@ -4592,8 +5360,9 @@
|
|
|
4592
5360
|
* @param {boolean} [hierarchicalRootLevel] ?? FIXME
|
|
4593
5361
|
* @return {array.<string>} The facet filters in the algolia format
|
|
4594
5362
|
*/
|
|
4595
|
-
_getFacetFilters: function
|
|
5363
|
+
_getFacetFilters: function (state, facet, hierarchicalRootLevel) {
|
|
4596
5364
|
var facetFilters = [];
|
|
5365
|
+
|
|
4597
5366
|
var facetsRefinements = state.facetsRefinements || {};
|
|
4598
5367
|
Object.keys(facetsRefinements).forEach(function (facetName) {
|
|
4599
5368
|
var facetValues = facetsRefinements[facetName] || [];
|
|
@@ -4601,6 +5370,7 @@
|
|
|
4601
5370
|
facetFilters.push(facetName + ':' + facetValue);
|
|
4602
5371
|
});
|
|
4603
5372
|
});
|
|
5373
|
+
|
|
4604
5374
|
var facetsExcludes = state.facetsExcludes || {};
|
|
4605
5375
|
Object.keys(facetsExcludes).forEach(function (facetName) {
|
|
4606
5376
|
var facetValues = facetsExcludes[facetName] || [];
|
|
@@ -4608,6 +5378,7 @@
|
|
|
4608
5378
|
facetFilters.push(facetName + ':-' + facetValue);
|
|
4609
5379
|
});
|
|
4610
5380
|
});
|
|
5381
|
+
|
|
4611
5382
|
var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
|
|
4612
5383
|
Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
|
|
4613
5384
|
var facetValues = disjunctiveFacetsRefinements[facetName] || [];
|
|
@@ -4615,18 +5386,24 @@
|
|
|
4615
5386
|
return;
|
|
4616
5387
|
}
|
|
4617
5388
|
var orFilters = [];
|
|
5389
|
+
|
|
4618
5390
|
facetValues.forEach(function (facetValue) {
|
|
4619
5391
|
orFilters.push(facetName + ':' + facetValue);
|
|
4620
5392
|
});
|
|
5393
|
+
|
|
4621
5394
|
facetFilters.push(orFilters);
|
|
4622
5395
|
});
|
|
4623
|
-
|
|
5396
|
+
|
|
5397
|
+
var hierarchicalFacetsRefinements =
|
|
5398
|
+
state.hierarchicalFacetsRefinements || {};
|
|
4624
5399
|
Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
|
|
4625
5400
|
var facetValues = hierarchicalFacetsRefinements[facetName] || [];
|
|
4626
5401
|
var facetValue = facetValues[0];
|
|
5402
|
+
|
|
4627
5403
|
if (facetValue === undefined) {
|
|
4628
5404
|
return;
|
|
4629
5405
|
}
|
|
5406
|
+
|
|
4630
5407
|
var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
|
|
4631
5408
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
4632
5409
|
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
|
|
@@ -4637,9 +5414,16 @@
|
|
|
4637
5414
|
if (facet === facetName) {
|
|
4638
5415
|
// if we are at the root level already, no need to ask for facet values, we get them from
|
|
4639
5416
|
// the hits query
|
|
4640
|
-
if (
|
|
5417
|
+
if (
|
|
5418
|
+
facetValue.indexOf(separator) === -1 ||
|
|
5419
|
+
(!rootPath && hierarchicalRootLevel === true) ||
|
|
5420
|
+
(rootPath &&
|
|
5421
|
+
rootPath.split(separator).length ===
|
|
5422
|
+
facetValue.split(separator).length)
|
|
5423
|
+
) {
|
|
4641
5424
|
return;
|
|
4642
5425
|
}
|
|
5426
|
+
|
|
4643
5427
|
if (!rootPath) {
|
|
4644
5428
|
attributesIndex = facetValue.split(separator).length - 2;
|
|
4645
5429
|
facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
|
|
@@ -4647,67 +5431,100 @@
|
|
|
4647
5431
|
attributesIndex = rootPath.split(separator).length - 1;
|
|
4648
5432
|
facetValue = rootPath;
|
|
4649
5433
|
}
|
|
5434
|
+
|
|
4650
5435
|
attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
|
|
4651
5436
|
} else {
|
|
4652
5437
|
attributesIndex = facetValue.split(separator).length - 1;
|
|
5438
|
+
|
|
4653
5439
|
attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
|
|
4654
5440
|
}
|
|
5441
|
+
|
|
4655
5442
|
if (attributeToRefine) {
|
|
4656
5443
|
facetFilters.push([attributeToRefine + ':' + facetValue]);
|
|
4657
5444
|
}
|
|
4658
5445
|
});
|
|
5446
|
+
|
|
4659
5447
|
return facetFilters;
|
|
4660
5448
|
},
|
|
4661
|
-
|
|
5449
|
+
|
|
5450
|
+
_getHitsHierarchicalFacetsAttributes: function (state) {
|
|
4662
5451
|
var out = [];
|
|
5452
|
+
|
|
4663
5453
|
return state.hierarchicalFacets.reduce(
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
5454
|
+
// ask for as much levels as there's hierarchical refinements
|
|
5455
|
+
function getHitsAttributesForHierarchicalFacet(
|
|
5456
|
+
allAttributes,
|
|
5457
|
+
hierarchicalFacet
|
|
5458
|
+
) {
|
|
5459
|
+
var hierarchicalRefinement = state.getHierarchicalRefinement(
|
|
5460
|
+
hierarchicalFacet.name
|
|
5461
|
+
)[0];
|
|
5462
|
+
|
|
5463
|
+
// if no refinement, ask for root level
|
|
5464
|
+
if (!hierarchicalRefinement) {
|
|
5465
|
+
allAttributes.push(hierarchicalFacet.attributes[0]);
|
|
5466
|
+
return allAttributes;
|
|
5467
|
+
}
|
|
5468
|
+
|
|
5469
|
+
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
5470
|
+
var level = hierarchicalRefinement.split(separator).length;
|
|
5471
|
+
var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
|
|
5472
|
+
|
|
5473
|
+
return allAttributes.concat(newAttributes);
|
|
5474
|
+
},
|
|
5475
|
+
out
|
|
5476
|
+
);
|
|
4678
5477
|
},
|
|
4679
|
-
|
|
5478
|
+
|
|
5479
|
+
_getDisjunctiveHierarchicalFacetAttribute: function (
|
|
5480
|
+
state,
|
|
5481
|
+
hierarchicalFacet,
|
|
5482
|
+
rootLevel
|
|
5483
|
+
) {
|
|
4680
5484
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
4681
5485
|
if (rootLevel === true) {
|
|
4682
5486
|
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
|
|
4683
5487
|
var attributeIndex = 0;
|
|
5488
|
+
|
|
4684
5489
|
if (rootPath) {
|
|
4685
5490
|
attributeIndex = rootPath.split(separator).length;
|
|
4686
5491
|
}
|
|
4687
5492
|
return [hierarchicalFacet.attributes[attributeIndex]];
|
|
4688
5493
|
}
|
|
4689
|
-
|
|
5494
|
+
|
|
5495
|
+
var hierarchicalRefinement =
|
|
5496
|
+
state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
|
|
4690
5497
|
// if refinement is 'beers > IPA > Flying dog',
|
|
4691
5498
|
// then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
|
|
4692
5499
|
|
|
4693
5500
|
var parentLevel = hierarchicalRefinement.split(separator).length - 1;
|
|
4694
5501
|
return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
|
|
4695
5502
|
},
|
|
4696
|
-
|
|
4697
|
-
|
|
5503
|
+
|
|
5504
|
+
getSearchForFacetQuery: function (facetName, query, maxFacetHits, state) {
|
|
5505
|
+
var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
|
|
5506
|
+
? state.clearRefinements(facetName)
|
|
5507
|
+
: state;
|
|
4698
5508
|
var searchForFacetSearchParameters = {
|
|
4699
5509
|
facetQuery: query,
|
|
4700
|
-
facetName: facetName
|
|
5510
|
+
facetName: facetName,
|
|
4701
5511
|
};
|
|
4702
5512
|
if (typeof maxFacetHits === 'number') {
|
|
4703
5513
|
searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
|
|
4704
5514
|
}
|
|
4705
|
-
return sortObject(
|
|
4706
|
-
|
|
5515
|
+
return sortObject(
|
|
5516
|
+
merge_1(
|
|
5517
|
+
{},
|
|
5518
|
+
requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
|
|
5519
|
+
searchForFacetSearchParameters
|
|
5520
|
+
)
|
|
5521
|
+
);
|
|
5522
|
+
},
|
|
4707
5523
|
};
|
|
5524
|
+
|
|
4708
5525
|
var requestBuilder_1 = requestBuilder;
|
|
4709
5526
|
|
|
4710
|
-
var version$1 = '3.13.
|
|
5527
|
+
var version$1 = '3.13.5';
|
|
4711
5528
|
|
|
4712
5529
|
var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
|
|
4713
5530
|
|
|
@@ -4818,6 +5635,7 @@
|
|
|
4818
5635
|
if (typeof client.addAlgoliaAgent === 'function') {
|
|
4819
5636
|
client.addAlgoliaAgent('JS Helper (' + version$1 + ')');
|
|
4820
5637
|
}
|
|
5638
|
+
|
|
4821
5639
|
this.setClient(client);
|
|
4822
5640
|
var opts = options || {};
|
|
4823
5641
|
opts.index = index;
|
|
@@ -4828,6 +5646,7 @@
|
|
|
4828
5646
|
this.derivedHelpers = [];
|
|
4829
5647
|
this._currentNbQueries = 0;
|
|
4830
5648
|
}
|
|
5649
|
+
|
|
4831
5650
|
inherits_1(AlgoliaSearchHelper, events);
|
|
4832
5651
|
|
|
4833
5652
|
/**
|
|
@@ -4842,15 +5661,12 @@
|
|
|
4842
5661
|
* @chainable
|
|
4843
5662
|
*/
|
|
4844
5663
|
AlgoliaSearchHelper.prototype.search = function () {
|
|
4845
|
-
this._search({
|
|
4846
|
-
onlyWithDerivedHelpers: false
|
|
4847
|
-
});
|
|
5664
|
+
this._search({ onlyWithDerivedHelpers: false });
|
|
4848
5665
|
return this;
|
|
4849
5666
|
};
|
|
5667
|
+
|
|
4850
5668
|
AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
|
|
4851
|
-
this._search({
|
|
4852
|
-
onlyWithDerivedHelpers: true
|
|
4853
|
-
});
|
|
5669
|
+
this._search({ onlyWithDerivedHelpers: true });
|
|
4854
5670
|
return this;
|
|
4855
5671
|
};
|
|
4856
5672
|
|
|
@@ -4901,43 +5717,58 @@
|
|
|
4901
5717
|
* }
|
|
4902
5718
|
*/
|
|
4903
5719
|
AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
|
|
4904
|
-
var tempState = !options
|
|
5720
|
+
var tempState = !options
|
|
5721
|
+
? this.state
|
|
5722
|
+
: this.state.setQueryParameters(options);
|
|
4905
5723
|
var queries = requestBuilder_1._getQueries(tempState.index, tempState);
|
|
4906
5724
|
// eslint-disable-next-line consistent-this
|
|
4907
5725
|
var self = this;
|
|
5726
|
+
|
|
4908
5727
|
this._currentNbQueries++;
|
|
5728
|
+
|
|
4909
5729
|
this.emit('searchOnce', {
|
|
4910
|
-
state: tempState
|
|
5730
|
+
state: tempState,
|
|
4911
5731
|
});
|
|
5732
|
+
|
|
4912
5733
|
if (cb) {
|
|
4913
|
-
this.client
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
self.
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
5734
|
+
this.client
|
|
5735
|
+
.search(queries)
|
|
5736
|
+
.then(function (content) {
|
|
5737
|
+
self._currentNbQueries--;
|
|
5738
|
+
if (self._currentNbQueries === 0) {
|
|
5739
|
+
self.emit('searchQueueEmpty');
|
|
5740
|
+
}
|
|
5741
|
+
|
|
5742
|
+
cb(null, new SearchResults_1(tempState, content.results), tempState);
|
|
5743
|
+
})
|
|
5744
|
+
.catch(function (err) {
|
|
5745
|
+
self._currentNbQueries--;
|
|
5746
|
+
if (self._currentNbQueries === 0) {
|
|
5747
|
+
self.emit('searchQueueEmpty');
|
|
5748
|
+
}
|
|
5749
|
+
|
|
5750
|
+
cb(err, null, tempState);
|
|
5751
|
+
});
|
|
5752
|
+
|
|
4926
5753
|
return undefined;
|
|
4927
5754
|
}
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
5755
|
+
|
|
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
|
+
);
|
|
4941
5772
|
};
|
|
4942
5773
|
|
|
4943
5774
|
/**
|
|
@@ -4960,13 +5791,23 @@
|
|
|
4960
5791
|
return Promise.resolve([]);
|
|
4961
5792
|
}
|
|
4962
5793
|
var derivedState = derivedHelper.getModifiedState(state);
|
|
4963
|
-
var data =
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
5794
|
+
var data = merge_1(
|
|
5795
|
+
{
|
|
5796
|
+
attributesForPrediction: options.attributesForPrediction,
|
|
5797
|
+
nbHits: options.nbHits,
|
|
5798
|
+
},
|
|
5799
|
+
{
|
|
5800
|
+
params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
|
|
5801
|
+
'attributesToSnippet',
|
|
5802
|
+
'hitsPerPage',
|
|
5803
|
+
'restrictSearchableAttributes',
|
|
5804
|
+
'snippetEllipsisText',
|
|
5805
|
+
]),
|
|
5806
|
+
}
|
|
5807
|
+
);
|
|
5808
|
+
|
|
5809
|
+
var errorMessage =
|
|
5810
|
+
'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
|
|
4970
5811
|
if (typeof this.client.initIndex !== 'function') {
|
|
4971
5812
|
throw new Error(errorMessage);
|
|
4972
5813
|
}
|
|
@@ -5011,60 +5852,93 @@
|
|
|
5011
5852
|
* it in the generated query.
|
|
5012
5853
|
* @return {promise.<FacetSearchResult>} the results of the search
|
|
5013
5854
|
*/
|
|
5014
|
-
AlgoliaSearchHelper.prototype.searchForFacetValues = function (
|
|
5855
|
+
AlgoliaSearchHelper.prototype.searchForFacetValues = function (
|
|
5856
|
+
facet,
|
|
5857
|
+
query,
|
|
5858
|
+
maxFacetHits,
|
|
5859
|
+
userState
|
|
5860
|
+
) {
|
|
5015
5861
|
var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
|
|
5016
5862
|
var clientHasInitIndex = typeof this.client.initIndex === 'function';
|
|
5017
|
-
if (
|
|
5018
|
-
|
|
5863
|
+
if (
|
|
5864
|
+
!clientHasSFFV &&
|
|
5865
|
+
!clientHasInitIndex &&
|
|
5866
|
+
typeof this.client.search !== 'function'
|
|
5867
|
+
) {
|
|
5868
|
+
throw new Error(
|
|
5869
|
+
'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
|
|
5870
|
+
);
|
|
5019
5871
|
}
|
|
5872
|
+
|
|
5020
5873
|
var state = this.state.setQueryParameters(userState || {});
|
|
5021
5874
|
var isDisjunctive = state.isDisjunctiveFacet(facet);
|
|
5022
|
-
var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
|
|
5875
|
+
var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
|
|
5876
|
+
facet,
|
|
5877
|
+
query,
|
|
5878
|
+
maxFacetHits,
|
|
5879
|
+
state
|
|
5880
|
+
);
|
|
5881
|
+
|
|
5023
5882
|
this._currentNbQueries++;
|
|
5024
5883
|
// eslint-disable-next-line consistent-this
|
|
5025
5884
|
var self = this;
|
|
5026
5885
|
var searchForFacetValuesPromise;
|
|
5027
5886
|
// newer algoliasearch ^3.27.1 - ~4.0.0
|
|
5028
5887
|
if (clientHasSFFV) {
|
|
5029
|
-
searchForFacetValuesPromise = this.client.searchForFacetValues([
|
|
5030
|
-
indexName: state.index,
|
|
5031
|
-
|
|
5032
|
-
}]);
|
|
5888
|
+
searchForFacetValuesPromise = this.client.searchForFacetValues([
|
|
5889
|
+
{ indexName: state.index, params: algoliaQuery },
|
|
5890
|
+
]);
|
|
5033
5891
|
// algoliasearch < 3.27.1
|
|
5034
5892
|
} else if (clientHasInitIndex) {
|
|
5035
|
-
searchForFacetValuesPromise = this.client
|
|
5893
|
+
searchForFacetValuesPromise = this.client
|
|
5894
|
+
.initIndex(state.index)
|
|
5895
|
+
.searchForFacetValues(algoliaQuery);
|
|
5036
5896
|
// algoliasearch ~5.0.0
|
|
5037
5897
|
} else {
|
|
5038
5898
|
// @MAJOR only use client.search
|
|
5039
5899
|
delete algoliaQuery.facetName;
|
|
5040
|
-
searchForFacetValuesPromise = this.client
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5900
|
+
searchForFacetValuesPromise = this.client
|
|
5901
|
+
.search([
|
|
5902
|
+
{
|
|
5903
|
+
type: 'facet',
|
|
5904
|
+
facet: facet,
|
|
5905
|
+
indexName: state.index,
|
|
5906
|
+
params: algoliaQuery,
|
|
5907
|
+
},
|
|
5908
|
+
])
|
|
5909
|
+
.then(function processResponse(response) {
|
|
5910
|
+
return response.results[0];
|
|
5911
|
+
});
|
|
5048
5912
|
}
|
|
5913
|
+
|
|
5049
5914
|
this.emit('searchForFacetValues', {
|
|
5050
5915
|
state: state,
|
|
5051
5916
|
facet: facet,
|
|
5052
|
-
query: query
|
|
5053
|
-
});
|
|
5054
|
-
return searchForFacetValuesPromise.then(function addIsRefined(content) {
|
|
5055
|
-
self._currentNbQueries--;
|
|
5056
|
-
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5057
|
-
content = Array.isArray(content) ? content[0] : content;
|
|
5058
|
-
content.facetHits.forEach(function (f) {
|
|
5059
|
-
f.escapedValue = escapeFacetValue$3(f.value);
|
|
5060
|
-
f.isRefined = isDisjunctive ? state.isDisjunctiveFacetRefined(facet, f.escapedValue) : state.isFacetRefined(facet, f.escapedValue);
|
|
5061
|
-
});
|
|
5062
|
-
return content;
|
|
5063
|
-
}, function (e) {
|
|
5064
|
-
self._currentNbQueries--;
|
|
5065
|
-
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5066
|
-
throw e;
|
|
5917
|
+
query: query,
|
|
5067
5918
|
});
|
|
5919
|
+
|
|
5920
|
+
return searchForFacetValuesPromise.then(
|
|
5921
|
+
function addIsRefined(content) {
|
|
5922
|
+
self._currentNbQueries--;
|
|
5923
|
+
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5924
|
+
|
|
5925
|
+
content = Array.isArray(content) ? content[0] : content;
|
|
5926
|
+
|
|
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
|
+
});
|
|
5933
|
+
|
|
5934
|
+
return content;
|
|
5935
|
+
},
|
|
5936
|
+
function (e) {
|
|
5937
|
+
self._currentNbQueries--;
|
|
5938
|
+
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
5939
|
+
throw e;
|
|
5940
|
+
}
|
|
5941
|
+
);
|
|
5068
5942
|
};
|
|
5069
5943
|
|
|
5070
5944
|
/**
|
|
@@ -5079,8 +5953,9 @@
|
|
|
5079
5953
|
AlgoliaSearchHelper.prototype.setQuery = function (q) {
|
|
5080
5954
|
this._change({
|
|
5081
5955
|
state: this.state.resetPage().setQuery(q),
|
|
5082
|
-
isPageReset: true
|
|
5956
|
+
isPageReset: true,
|
|
5083
5957
|
});
|
|
5958
|
+
|
|
5084
5959
|
return this;
|
|
5085
5960
|
};
|
|
5086
5961
|
|
|
@@ -5110,8 +5985,9 @@
|
|
|
5110
5985
|
AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
|
|
5111
5986
|
this._change({
|
|
5112
5987
|
state: this.state.resetPage().clearRefinements(name),
|
|
5113
|
-
isPageReset: true
|
|
5988
|
+
isPageReset: true,
|
|
5114
5989
|
});
|
|
5990
|
+
|
|
5115
5991
|
return this;
|
|
5116
5992
|
};
|
|
5117
5993
|
|
|
@@ -5126,8 +6002,9 @@
|
|
|
5126
6002
|
AlgoliaSearchHelper.prototype.clearTags = function () {
|
|
5127
6003
|
this._change({
|
|
5128
6004
|
state: this.state.resetPage().clearTags(),
|
|
5129
|
-
isPageReset: true
|
|
6005
|
+
isPageReset: true,
|
|
5130
6006
|
});
|
|
6007
|
+
|
|
5131
6008
|
return this;
|
|
5132
6009
|
};
|
|
5133
6010
|
|
|
@@ -5142,11 +6019,15 @@
|
|
|
5142
6019
|
* @fires change
|
|
5143
6020
|
* @chainable
|
|
5144
6021
|
*/
|
|
5145
|
-
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
|
|
6022
|
+
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
|
|
6023
|
+
facet,
|
|
6024
|
+
value
|
|
6025
|
+
) {
|
|
5146
6026
|
this._change({
|
|
5147
6027
|
state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
|
|
5148
|
-
isPageReset: true
|
|
6028
|
+
isPageReset: true,
|
|
5149
6029
|
});
|
|
6030
|
+
|
|
5150
6031
|
return this;
|
|
5151
6032
|
};
|
|
5152
6033
|
|
|
@@ -5171,11 +6052,15 @@
|
|
|
5171
6052
|
* @chainable
|
|
5172
6053
|
* @fires change
|
|
5173
6054
|
*/
|
|
5174
|
-
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
|
|
6055
|
+
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
|
|
6056
|
+
facet,
|
|
6057
|
+
path
|
|
6058
|
+
) {
|
|
5175
6059
|
this._change({
|
|
5176
6060
|
state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
|
|
5177
|
-
isPageReset: true
|
|
6061
|
+
isPageReset: true,
|
|
5178
6062
|
});
|
|
6063
|
+
|
|
5179
6064
|
return this;
|
|
5180
6065
|
};
|
|
5181
6066
|
|
|
@@ -5191,11 +6076,18 @@
|
|
|
5191
6076
|
* @fires change
|
|
5192
6077
|
* @chainable
|
|
5193
6078
|
*/
|
|
5194
|
-
AlgoliaSearchHelper.prototype.addNumericRefinement = function (
|
|
6079
|
+
AlgoliaSearchHelper.prototype.addNumericRefinement = function (
|
|
6080
|
+
attribute,
|
|
6081
|
+
operator,
|
|
6082
|
+
value
|
|
6083
|
+
) {
|
|
5195
6084
|
this._change({
|
|
5196
|
-
state: this.state
|
|
5197
|
-
|
|
6085
|
+
state: this.state
|
|
6086
|
+
.resetPage()
|
|
6087
|
+
.addNumericRefinement(attribute, operator, value),
|
|
6088
|
+
isPageReset: true,
|
|
5198
6089
|
});
|
|
6090
|
+
|
|
5199
6091
|
return this;
|
|
5200
6092
|
};
|
|
5201
6093
|
|
|
@@ -5213,8 +6105,9 @@
|
|
|
5213
6105
|
AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
|
|
5214
6106
|
this._change({
|
|
5215
6107
|
state: this.state.resetPage().addFacetRefinement(facet, value),
|
|
5216
|
-
isPageReset: true
|
|
6108
|
+
isPageReset: true,
|
|
5217
6109
|
});
|
|
6110
|
+
|
|
5218
6111
|
return this;
|
|
5219
6112
|
};
|
|
5220
6113
|
|
|
@@ -5240,8 +6133,9 @@
|
|
|
5240
6133
|
AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
|
|
5241
6134
|
this._change({
|
|
5242
6135
|
state: this.state.resetPage().addExcludeRefinement(facet, value),
|
|
5243
|
-
isPageReset: true
|
|
6136
|
+
isPageReset: true,
|
|
5244
6137
|
});
|
|
6138
|
+
|
|
5245
6139
|
return this;
|
|
5246
6140
|
};
|
|
5247
6141
|
|
|
@@ -5266,8 +6160,9 @@
|
|
|
5266
6160
|
AlgoliaSearchHelper.prototype.addTag = function (tag) {
|
|
5267
6161
|
this._change({
|
|
5268
6162
|
state: this.state.resetPage().addTagRefinement(tag),
|
|
5269
|
-
isPageReset: true
|
|
6163
|
+
isPageReset: true,
|
|
5270
6164
|
});
|
|
6165
|
+
|
|
5271
6166
|
return this;
|
|
5272
6167
|
};
|
|
5273
6168
|
|
|
@@ -5289,11 +6184,18 @@
|
|
|
5289
6184
|
* @fires change
|
|
5290
6185
|
* @chainable
|
|
5291
6186
|
*/
|
|
5292
|
-
AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
|
|
6187
|
+
AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
|
|
6188
|
+
attribute,
|
|
6189
|
+
operator,
|
|
6190
|
+
value
|
|
6191
|
+
) {
|
|
5293
6192
|
this._change({
|
|
5294
|
-
state: this.state
|
|
5295
|
-
|
|
6193
|
+
state: this.state
|
|
6194
|
+
.resetPage()
|
|
6195
|
+
.removeNumericRefinement(attribute, operator, value),
|
|
6196
|
+
isPageReset: true,
|
|
5296
6197
|
});
|
|
6198
|
+
|
|
5297
6199
|
return this;
|
|
5298
6200
|
};
|
|
5299
6201
|
|
|
@@ -5311,11 +6213,17 @@
|
|
|
5311
6213
|
* @fires change
|
|
5312
6214
|
* @chainable
|
|
5313
6215
|
*/
|
|
5314
|
-
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
|
|
6216
|
+
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
|
|
6217
|
+
facet,
|
|
6218
|
+
value
|
|
6219
|
+
) {
|
|
5315
6220
|
this._change({
|
|
5316
|
-
state: this.state
|
|
5317
|
-
|
|
6221
|
+
state: this.state
|
|
6222
|
+
.resetPage()
|
|
6223
|
+
.removeDisjunctiveFacetRefinement(facet, value),
|
|
6224
|
+
isPageReset: true,
|
|
5318
6225
|
});
|
|
6226
|
+
|
|
5319
6227
|
return this;
|
|
5320
6228
|
};
|
|
5321
6229
|
|
|
@@ -5335,11 +6243,14 @@
|
|
|
5335
6243
|
* @fires change
|
|
5336
6244
|
* @chainable
|
|
5337
6245
|
*/
|
|
5338
|
-
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
|
|
6246
|
+
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
|
|
6247
|
+
facet
|
|
6248
|
+
) {
|
|
5339
6249
|
this._change({
|
|
5340
6250
|
state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
|
|
5341
|
-
isPageReset: true
|
|
6251
|
+
isPageReset: true,
|
|
5342
6252
|
});
|
|
6253
|
+
|
|
5343
6254
|
return this;
|
|
5344
6255
|
};
|
|
5345
6256
|
|
|
@@ -5360,8 +6271,9 @@
|
|
|
5360
6271
|
AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
|
|
5361
6272
|
this._change({
|
|
5362
6273
|
state: this.state.resetPage().removeFacetRefinement(facet, value),
|
|
5363
|
-
isPageReset: true
|
|
6274
|
+
isPageReset: true,
|
|
5364
6275
|
});
|
|
6276
|
+
|
|
5365
6277
|
return this;
|
|
5366
6278
|
};
|
|
5367
6279
|
|
|
@@ -5390,8 +6302,9 @@
|
|
|
5390
6302
|
AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
|
|
5391
6303
|
this._change({
|
|
5392
6304
|
state: this.state.resetPage().removeExcludeRefinement(facet, value),
|
|
5393
|
-
isPageReset: true
|
|
6305
|
+
isPageReset: true,
|
|
5394
6306
|
});
|
|
6307
|
+
|
|
5395
6308
|
return this;
|
|
5396
6309
|
};
|
|
5397
6310
|
|
|
@@ -5416,8 +6329,9 @@
|
|
|
5416
6329
|
AlgoliaSearchHelper.prototype.removeTag = function (tag) {
|
|
5417
6330
|
this._change({
|
|
5418
6331
|
state: this.state.resetPage().removeTagRefinement(tag),
|
|
5419
|
-
isPageReset: true
|
|
6332
|
+
isPageReset: true,
|
|
5420
6333
|
});
|
|
6334
|
+
|
|
5421
6335
|
return this;
|
|
5422
6336
|
};
|
|
5423
6337
|
|
|
@@ -5435,8 +6349,9 @@
|
|
|
5435
6349
|
AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
|
|
5436
6350
|
this._change({
|
|
5437
6351
|
state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
|
|
5438
|
-
isPageReset: true
|
|
6352
|
+
isPageReset: true,
|
|
5439
6353
|
});
|
|
6354
|
+
|
|
5440
6355
|
return this;
|
|
5441
6356
|
};
|
|
5442
6357
|
|
|
@@ -5484,8 +6399,9 @@
|
|
|
5484
6399
|
AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
|
|
5485
6400
|
this._change({
|
|
5486
6401
|
state: this.state.resetPage().toggleFacetRefinement(facet, value),
|
|
5487
|
-
isPageReset: true
|
|
6402
|
+
isPageReset: true,
|
|
5488
6403
|
});
|
|
6404
|
+
|
|
5489
6405
|
return this;
|
|
5490
6406
|
};
|
|
5491
6407
|
|
|
@@ -5510,8 +6426,9 @@
|
|
|
5510
6426
|
AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
|
|
5511
6427
|
this._change({
|
|
5512
6428
|
state: this.state.resetPage().toggleTagRefinement(tag),
|
|
5513
|
-
isPageReset: true
|
|
6429
|
+
isPageReset: true,
|
|
5514
6430
|
});
|
|
6431
|
+
|
|
5515
6432
|
return this;
|
|
5516
6433
|
};
|
|
5517
6434
|
|
|
@@ -5552,10 +6469,12 @@
|
|
|
5552
6469
|
*/
|
|
5553
6470
|
function setCurrentPage(page) {
|
|
5554
6471
|
if (page < 0) throw new Error('Page requested below 0.');
|
|
6472
|
+
|
|
5555
6473
|
this._change({
|
|
5556
6474
|
state: this.state.setPage(page),
|
|
5557
|
-
isPageReset: false
|
|
6475
|
+
isPageReset: false,
|
|
5558
6476
|
});
|
|
6477
|
+
|
|
5559
6478
|
return this;
|
|
5560
6479
|
}
|
|
5561
6480
|
|
|
@@ -5591,8 +6510,9 @@
|
|
|
5591
6510
|
AlgoliaSearchHelper.prototype.setIndex = function (name) {
|
|
5592
6511
|
this._change({
|
|
5593
6512
|
state: this.state.resetPage().setIndex(name),
|
|
5594
|
-
isPageReset: true
|
|
6513
|
+
isPageReset: true,
|
|
5595
6514
|
});
|
|
6515
|
+
|
|
5596
6516
|
return this;
|
|
5597
6517
|
};
|
|
5598
6518
|
|
|
@@ -5616,8 +6536,9 @@
|
|
|
5616
6536
|
AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
|
|
5617
6537
|
this._change({
|
|
5618
6538
|
state: this.state.resetPage().setQueryParameter(parameter, value),
|
|
5619
|
-
isPageReset: true
|
|
6539
|
+
isPageReset: true,
|
|
5620
6540
|
});
|
|
6541
|
+
|
|
5621
6542
|
return this;
|
|
5622
6543
|
};
|
|
5623
6544
|
|
|
@@ -5631,8 +6552,9 @@
|
|
|
5631
6552
|
AlgoliaSearchHelper.prototype.setState = function (newState) {
|
|
5632
6553
|
this._change({
|
|
5633
6554
|
state: SearchParameters_1.make(newState),
|
|
5634
|
-
isPageReset: false
|
|
6555
|
+
isPageReset: false,
|
|
5635
6556
|
});
|
|
6557
|
+
|
|
5636
6558
|
return this;
|
|
5637
6559
|
};
|
|
5638
6560
|
|
|
@@ -5653,10 +6575,11 @@
|
|
|
5653
6575
|
* }
|
|
5654
6576
|
* @chainable
|
|
5655
6577
|
*/
|
|
5656
|
-
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
6578
|
+
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
|
|
6579
|
+
function (newState) {
|
|
6580
|
+
this.state = new SearchParameters_1(newState);
|
|
6581
|
+
return this;
|
|
6582
|
+
};
|
|
5660
6583
|
|
|
5661
6584
|
/**
|
|
5662
6585
|
* Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
|
|
@@ -5758,6 +6681,7 @@
|
|
|
5758
6681
|
AlgoliaSearchHelper.prototype.getIndex = function () {
|
|
5759
6682
|
return this.state.index;
|
|
5760
6683
|
};
|
|
6684
|
+
|
|
5761
6685
|
function getCurrentPage() {
|
|
5762
6686
|
return this.state.page;
|
|
5763
6687
|
}
|
|
@@ -5830,39 +6754,49 @@
|
|
|
5830
6754
|
*/
|
|
5831
6755
|
AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
|
|
5832
6756
|
var refinements = [];
|
|
6757
|
+
|
|
5833
6758
|
if (this.state.isConjunctiveFacet(facetName)) {
|
|
5834
6759
|
var conjRefinements = this.state.getConjunctiveRefinements(facetName);
|
|
6760
|
+
|
|
5835
6761
|
conjRefinements.forEach(function (r) {
|
|
5836
6762
|
refinements.push({
|
|
5837
6763
|
value: r,
|
|
5838
|
-
type: 'conjunctive'
|
|
6764
|
+
type: 'conjunctive',
|
|
5839
6765
|
});
|
|
5840
6766
|
});
|
|
6767
|
+
|
|
5841
6768
|
var excludeRefinements = this.state.getExcludeRefinements(facetName);
|
|
6769
|
+
|
|
5842
6770
|
excludeRefinements.forEach(function (r) {
|
|
5843
6771
|
refinements.push({
|
|
5844
6772
|
value: r,
|
|
5845
|
-
type: 'exclude'
|
|
6773
|
+
type: 'exclude',
|
|
5846
6774
|
});
|
|
5847
6775
|
});
|
|
5848
6776
|
} else if (this.state.isDisjunctiveFacet(facetName)) {
|
|
5849
|
-
var disjunctiveRefinements =
|
|
6777
|
+
var disjunctiveRefinements =
|
|
6778
|
+
this.state.getDisjunctiveRefinements(facetName);
|
|
6779
|
+
|
|
5850
6780
|
disjunctiveRefinements.forEach(function (r) {
|
|
5851
6781
|
refinements.push({
|
|
5852
6782
|
value: r,
|
|
5853
|
-
type: 'disjunctive'
|
|
6783
|
+
type: 'disjunctive',
|
|
5854
6784
|
});
|
|
5855
6785
|
});
|
|
5856
6786
|
}
|
|
6787
|
+
|
|
5857
6788
|
var numericRefinements = this.state.getNumericRefinements(facetName);
|
|
6789
|
+
|
|
5858
6790
|
Object.keys(numericRefinements).forEach(function (operator) {
|
|
5859
6791
|
var value = numericRefinements[operator];
|
|
6792
|
+
|
|
5860
6793
|
refinements.push({
|
|
5861
6794
|
value: value,
|
|
5862
6795
|
operator: operator,
|
|
5863
|
-
type: 'numeric'
|
|
6796
|
+
type: 'numeric',
|
|
5864
6797
|
});
|
|
5865
6798
|
});
|
|
6799
|
+
|
|
5866
6800
|
return refinements;
|
|
5867
6801
|
};
|
|
5868
6802
|
|
|
@@ -5872,7 +6806,10 @@
|
|
|
5872
6806
|
* @param {string} operator operator applied on the refined values
|
|
5873
6807
|
* @return {Array.<number|number[]>} refined values
|
|
5874
6808
|
*/
|
|
5875
|
-
AlgoliaSearchHelper.prototype.getNumericRefinement = function (
|
|
6809
|
+
AlgoliaSearchHelper.prototype.getNumericRefinement = function (
|
|
6810
|
+
attribute,
|
|
6811
|
+
operator
|
|
6812
|
+
) {
|
|
5876
6813
|
return this.state.getNumericRefinement(attribute, operator);
|
|
5877
6814
|
};
|
|
5878
6815
|
|
|
@@ -5881,7 +6818,9 @@
|
|
|
5881
6818
|
* @param {string} facetName Hierarchical facet name
|
|
5882
6819
|
* @return {array.<string>} the path as an array of string
|
|
5883
6820
|
*/
|
|
5884
|
-
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
|
|
6821
|
+
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
|
|
6822
|
+
facetName
|
|
6823
|
+
) {
|
|
5885
6824
|
return this.state.getHierarchicalFacetBreadcrumb(facetName);
|
|
5886
6825
|
};
|
|
5887
6826
|
|
|
@@ -5901,48 +6840,65 @@
|
|
|
5901
6840
|
var state = this.state;
|
|
5902
6841
|
var states = [];
|
|
5903
6842
|
var mainQueries = [];
|
|
6843
|
+
|
|
5904
6844
|
if (!options.onlyWithDerivedHelpers) {
|
|
5905
6845
|
mainQueries = requestBuilder_1._getQueries(state.index, state);
|
|
6846
|
+
|
|
5906
6847
|
states.push({
|
|
5907
6848
|
state: state,
|
|
5908
6849
|
queriesCount: mainQueries.length,
|
|
5909
|
-
helper: this
|
|
6850
|
+
helper: this,
|
|
5910
6851
|
});
|
|
6852
|
+
|
|
5911
6853
|
this.emit('search', {
|
|
5912
6854
|
state: state,
|
|
5913
|
-
results: this.lastResults
|
|
6855
|
+
results: this.lastResults,
|
|
5914
6856
|
});
|
|
5915
6857
|
}
|
|
6858
|
+
|
|
5916
6859
|
var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
|
|
5917
6860
|
var derivedState = derivedHelper.getModifiedState(state);
|
|
5918
|
-
var derivedStateQueries = derivedState.index
|
|
6861
|
+
var derivedStateQueries = derivedState.index
|
|
6862
|
+
? requestBuilder_1._getQueries(derivedState.index, derivedState)
|
|
6863
|
+
: [];
|
|
6864
|
+
|
|
5919
6865
|
states.push({
|
|
5920
6866
|
state: derivedState,
|
|
5921
6867
|
queriesCount: derivedStateQueries.length,
|
|
5922
|
-
helper: derivedHelper
|
|
6868
|
+
helper: derivedHelper,
|
|
5923
6869
|
});
|
|
6870
|
+
|
|
5924
6871
|
derivedHelper.emit('search', {
|
|
5925
6872
|
state: derivedState,
|
|
5926
|
-
results: derivedHelper.lastResults
|
|
6873
|
+
results: derivedHelper.lastResults,
|
|
5927
6874
|
});
|
|
6875
|
+
|
|
5928
6876
|
return derivedStateQueries;
|
|
5929
6877
|
});
|
|
6878
|
+
|
|
5930
6879
|
var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
|
|
6880
|
+
|
|
5931
6881
|
var queryId = this._queryId++;
|
|
5932
6882
|
this._currentNbQueries++;
|
|
6883
|
+
|
|
5933
6884
|
if (!queries.length) {
|
|
5934
|
-
return Promise.resolve({
|
|
5935
|
-
|
|
5936
|
-
|
|
6885
|
+
return Promise.resolve({ results: [] }).then(
|
|
6886
|
+
this._dispatchAlgoliaResponse.bind(this, states, queryId)
|
|
6887
|
+
);
|
|
5937
6888
|
}
|
|
6889
|
+
|
|
5938
6890
|
try {
|
|
5939
|
-
this.client
|
|
6891
|
+
this.client
|
|
6892
|
+
.search(queries)
|
|
6893
|
+
.then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
|
|
6894
|
+
.catch(this._dispatchAlgoliaError.bind(this, queryId));
|
|
5940
6895
|
} catch (error) {
|
|
5941
6896
|
// If we reach this part, we're in an internal error state
|
|
5942
6897
|
this.emit('error', {
|
|
5943
|
-
error: error
|
|
6898
|
+
error: error,
|
|
5944
6899
|
});
|
|
5945
6900
|
}
|
|
6901
|
+
|
|
5946
6902
|
return undefined;
|
|
5947
6903
|
};
|
|
5948
6904
|
|
|
@@ -5956,50 +6912,79 @@
|
|
|
5956
6912
|
* @param {object} content content of the response
|
|
5957
6913
|
* @return {undefined}
|
|
5958
6914
|
*/
|
|
5959
|
-
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
|
|
6915
|
+
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
|
|
6916
|
+
states,
|
|
6917
|
+
queryId,
|
|
6918
|
+
content
|
|
6919
|
+
) {
|
|
5960
6920
|
// @TODO remove the number of outdated queries discarded instead of just one
|
|
5961
6921
|
|
|
5962
6922
|
if (queryId < this._lastQueryIdReceived) {
|
|
5963
6923
|
// Outdated answer
|
|
5964
6924
|
return;
|
|
5965
6925
|
}
|
|
6926
|
+
|
|
5966
6927
|
this._currentNbQueries -= queryId - this._lastQueryIdReceived;
|
|
5967
6928
|
this._lastQueryIdReceived = queryId;
|
|
6929
|
+
|
|
5968
6930
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
6931
|
+
|
|
5969
6932
|
var results = content.results.slice();
|
|
6933
|
+
|
|
5970
6934
|
states.forEach(function (s) {
|
|
5971
6935
|
var state = s.state;
|
|
5972
6936
|
var queriesCount = s.queriesCount;
|
|
5973
6937
|
var helper = s.helper;
|
|
5974
6938
|
var specificResults = results.splice(0, queriesCount);
|
|
6939
|
+
|
|
5975
6940
|
if (!state.index) {
|
|
5976
6941
|
helper.emit('result', {
|
|
5977
6942
|
results: null,
|
|
5978
|
-
state: state
|
|
6943
|
+
state: state,
|
|
5979
6944
|
});
|
|
5980
6945
|
return;
|
|
5981
6946
|
}
|
|
6947
|
+
|
|
5982
6948
|
helper.lastResults = new SearchResults_1(state, specificResults);
|
|
6949
|
+
|
|
5983
6950
|
helper.emit('result', {
|
|
5984
6951
|
results: helper.lastResults,
|
|
5985
|
-
state: state
|
|
6952
|
+
state: state,
|
|
5986
6953
|
});
|
|
5987
6954
|
});
|
|
5988
6955
|
};
|
|
5989
|
-
|
|
6956
|
+
|
|
6957
|
+
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
|
|
6958
|
+
queryId,
|
|
6959
|
+
error
|
|
6960
|
+
) {
|
|
5990
6961
|
if (queryId < this._lastQueryIdReceived) {
|
|
5991
6962
|
// Outdated answer
|
|
5992
6963
|
return;
|
|
5993
6964
|
}
|
|
6965
|
+
|
|
5994
6966
|
this._currentNbQueries -= queryId - this._lastQueryIdReceived;
|
|
5995
6967
|
this._lastQueryIdReceived = queryId;
|
|
6968
|
+
|
|
5996
6969
|
this.emit('error', {
|
|
5997
|
-
error: error
|
|
6970
|
+
error: error,
|
|
5998
6971
|
});
|
|
6972
|
+
|
|
5999
6973
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
6000
6974
|
};
|
|
6001
|
-
|
|
6002
|
-
|
|
6975
|
+
|
|
6976
|
+
AlgoliaSearchHelper.prototype.containsRefinement = function (
|
|
6977
|
+
query,
|
|
6978
|
+
facetFilters,
|
|
6979
|
+
numericFilters,
|
|
6980
|
+
tagFilters
|
|
6981
|
+
) {
|
|
6982
|
+
return (
|
|
6983
|
+
query ||
|
|
6984
|
+
facetFilters.length !== 0 ||
|
|
6985
|
+
numericFilters.length !== 0 ||
|
|
6986
|
+
tagFilters.length !== 0
|
|
6987
|
+
);
|
|
6003
6988
|
};
|
|
6004
6989
|
|
|
6005
6990
|
/**
|
|
@@ -6009,17 +6994,23 @@
|
|
|
6009
6994
|
* @return {boolean} true if there are refinements on this attribute
|
|
6010
6995
|
*/
|
|
6011
6996
|
AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
|
|
6012
|
-
return
|
|
6997
|
+
return (
|
|
6998
|
+
this.state.disjunctiveRefinements[facet] &&
|
|
6999
|
+
this.state.disjunctiveRefinements[facet].length > 0
|
|
7000
|
+
);
|
|
6013
7001
|
};
|
|
7002
|
+
|
|
6014
7003
|
AlgoliaSearchHelper.prototype._change = function (event) {
|
|
6015
7004
|
var state = event.state;
|
|
6016
7005
|
var isPageReset = event.isPageReset;
|
|
7006
|
+
|
|
6017
7007
|
if (state !== this.state) {
|
|
6018
7008
|
this.state = state;
|
|
7009
|
+
|
|
6019
7010
|
this.emit('change', {
|
|
6020
7011
|
state: this.state,
|
|
6021
7012
|
results: this.lastResults,
|
|
6022
|
-
isPageReset: isPageReset
|
|
7013
|
+
isPageReset: isPageReset,
|
|
6023
7014
|
});
|
|
6024
7015
|
}
|
|
6025
7016
|
};
|
|
@@ -6041,10 +7032,12 @@
|
|
|
6041
7032
|
*/
|
|
6042
7033
|
AlgoliaSearchHelper.prototype.setClient = function (newClient) {
|
|
6043
7034
|
if (this.client === newClient) return this;
|
|
7035
|
+
|
|
6044
7036
|
if (typeof newClient.addAlgoliaAgent === 'function') {
|
|
6045
7037
|
newClient.addAlgoliaAgent('JS Helper (' + version$1 + ')');
|
|
6046
7038
|
}
|
|
6047
7039
|
this.client = newClient;
|
|
7040
|
+
|
|
6048
7041
|
return this;
|
|
6049
7042
|
};
|
|
6050
7043
|
|
|
@@ -6183,6 +7176,7 @@
|
|
|
6183
7176
|
* @type {SearchResults}
|
|
6184
7177
|
*/
|
|
6185
7178
|
algoliasearchHelper.SearchResults = SearchResults_1;
|
|
7179
|
+
|
|
6186
7180
|
var algoliasearchHelper_1 = algoliasearchHelper;
|
|
6187
7181
|
|
|
6188
7182
|
function createOptionalFilter(_ref) {
|