instantsearch.js 4.56.4 → 4.56.6
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/cjs/connectors/breadcrumb/connectBreadcrumb.js +31 -4
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +9 -3
- package/cjs/connectors/hits-per-page/connectHitsPerPage.js +12 -3
- package/cjs/connectors/menu/connectMenu.js +7 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +7 -1
- package/cjs/connectors/pagination/connectPagination.js +7 -5
- package/cjs/connectors/rating-menu/connectRatingMenu.js +12 -3
- package/cjs/connectors/refinement-list/connectRefinementList.js +7 -1
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +15 -3
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createRouterMiddleware.js +9 -1
- package/cjs/widgets/index/index.js +6 -3
- package/dist/instantsearch.development.d.ts +7 -3
- package/dist/instantsearch.development.js +795 -1256
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +7 -3
- package/dist/instantsearch.production.min.d.ts +7 -3
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/breadcrumb/connectBreadcrumb.js +31 -4
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +9 -3
- package/es/connectors/hits-per-page/connectHitsPerPage.d.ts +5 -1
- package/es/connectors/hits-per-page/connectHitsPerPage.js +12 -3
- package/es/connectors/menu/connectMenu.js +7 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +7 -1
- package/es/connectors/pagination/connectPagination.js +7 -5
- package/es/connectors/rating-menu/connectRatingMenu.js +12 -3
- package/es/connectors/refinement-list/connectRefinementList.js +7 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.d.ts +1 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +15 -3
- package/es/lib/utils/render-args.d.ts +222 -2
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createRouterMiddleware.js +9 -1
- package/es/types/widget.d.ts +1 -1
- package/es/widgets/index/index.d.ts +1 -1
- package/es/widgets/index/index.js +6 -3
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.56.
|
|
1
|
+
/*! InstantSearch.js 4.56.6 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -2395,6 +2395,7 @@
|
|
|
2395
2395
|
});
|
|
2396
2396
|
},
|
|
2397
2397
|
getWidgetRenderState: function getWidgetRenderState(_ref4) {
|
|
2398
|
+
var _this = this;
|
|
2398
2399
|
var results = _ref4.results,
|
|
2399
2400
|
state = _ref4.state,
|
|
2400
2401
|
createURL = _ref4.createURL,
|
|
@@ -2404,9 +2405,14 @@
|
|
|
2404
2405
|
var canToggleShowMore = false;
|
|
2405
2406
|
|
|
2406
2407
|
// Bind createURL to this specific attribute
|
|
2407
|
-
function _createURL(facetValue) {
|
|
2408
|
-
return createURL(
|
|
2409
|
-
|
|
2408
|
+
var _createURL = function _createURL(facetValue) {
|
|
2409
|
+
return createURL(function (uiState) {
|
|
2410
|
+
return _this.getWidgetUiState(uiState, {
|
|
2411
|
+
searchParameters: state.resetPage().toggleFacetRefinement(hierarchicalFacetName, facetValue),
|
|
2412
|
+
helper: helper
|
|
2413
|
+
});
|
|
2414
|
+
});
|
|
2415
|
+
};
|
|
2410
2416
|
if (!sendEvent) {
|
|
2411
2417
|
sendEvent = createSendEventForFacet({
|
|
2412
2418
|
instantSearchInstance: instantSearchInstance,
|
|
@@ -2843,9 +2849,16 @@
|
|
|
2843
2849
|
},
|
|
2844
2850
|
createURLFactory: function createURLFactory(_ref3) {
|
|
2845
2851
|
var state = _ref3.state,
|
|
2846
|
-
createURL = _ref3.createURL
|
|
2852
|
+
createURL = _ref3.createURL,
|
|
2853
|
+
getWidgetUiState = _ref3.getWidgetUiState,
|
|
2854
|
+
helper = _ref3.helper;
|
|
2847
2855
|
return function (value) {
|
|
2848
|
-
return createURL(
|
|
2856
|
+
return createURL(function (uiState) {
|
|
2857
|
+
return getWidgetUiState(uiState, {
|
|
2858
|
+
searchParameters: state.resetPage().setQueryParameter('hitsPerPage', !value && value !== 0 ? undefined : value),
|
|
2859
|
+
helper: helper
|
|
2860
|
+
});
|
|
2861
|
+
});
|
|
2849
2862
|
};
|
|
2850
2863
|
}
|
|
2851
2864
|
};
|
|
@@ -2900,7 +2913,9 @@
|
|
|
2900
2913
|
refine: connectorState.getRefine(helper),
|
|
2901
2914
|
createURL: connectorState.createURLFactory({
|
|
2902
2915
|
state: state,
|
|
2903
|
-
createURL: createURL
|
|
2916
|
+
createURL: createURL,
|
|
2917
|
+
getWidgetUiState: this.getWidgetUiState,
|
|
2918
|
+
helper: helper
|
|
2904
2919
|
}),
|
|
2905
2920
|
hasNoResults: !canRefine,
|
|
2906
2921
|
canRefine: canRefine,
|
|
@@ -3258,6 +3273,7 @@
|
|
|
3258
3273
|
});
|
|
3259
3274
|
},
|
|
3260
3275
|
getWidgetRenderState: function getWidgetRenderState(renderOptions) {
|
|
3276
|
+
var _this = this;
|
|
3261
3277
|
var results = renderOptions.results,
|
|
3262
3278
|
createURL = renderOptions.createURL,
|
|
3263
3279
|
instantSearchInstance = renderOptions.instantSearchInstance,
|
|
@@ -3274,7 +3290,12 @@
|
|
|
3274
3290
|
}
|
|
3275
3291
|
if (!_createURL) {
|
|
3276
3292
|
_createURL = function _createURL(facetValue) {
|
|
3277
|
-
return createURL(
|
|
3293
|
+
return createURL(function (uiState) {
|
|
3294
|
+
return _this.getWidgetUiState(uiState, {
|
|
3295
|
+
searchParameters: helper.state.resetPage().toggleFacetRefinement(attribute, facetValue),
|
|
3296
|
+
helper: helper
|
|
3297
|
+
});
|
|
3298
|
+
});
|
|
3278
3299
|
};
|
|
3279
3300
|
}
|
|
3280
3301
|
if (!_refine) {
|
|
@@ -3475,6 +3496,7 @@
|
|
|
3475
3496
|
});
|
|
3476
3497
|
},
|
|
3477
3498
|
getWidgetRenderState: function getWidgetRenderState(_ref7) {
|
|
3499
|
+
var _this = this;
|
|
3478
3500
|
var results = _ref7.results,
|
|
3479
3501
|
state = _ref7.state,
|
|
3480
3502
|
instantSearchInstance = _ref7.instantSearchInstance,
|
|
@@ -3490,7 +3512,12 @@
|
|
|
3490
3512
|
if (!connectorState.createURL) {
|
|
3491
3513
|
connectorState.createURL = function (newState) {
|
|
3492
3514
|
return function (facetValue) {
|
|
3493
|
-
return createURL(
|
|
3515
|
+
return createURL(function (uiState) {
|
|
3516
|
+
return _this.getWidgetUiState(uiState, {
|
|
3517
|
+
searchParameters: getRefinedState(newState, attribute, facetValue),
|
|
3518
|
+
helper: helper
|
|
3519
|
+
});
|
|
3520
|
+
});
|
|
3494
3521
|
};
|
|
3495
3522
|
};
|
|
3496
3523
|
}
|
|
@@ -3740,10 +3767,12 @@
|
|
|
3740
3767
|
};
|
|
3741
3768
|
}
|
|
3742
3769
|
if (!connectorState.createURL) {
|
|
3743
|
-
connectorState.createURL = function (
|
|
3744
|
-
return function (
|
|
3745
|
-
return
|
|
3746
|
-
|
|
3770
|
+
connectorState.createURL = function (page) {
|
|
3771
|
+
return createURL(function (uiState) {
|
|
3772
|
+
return _objectSpread2(_objectSpread2({}, uiState), {}, {
|
|
3773
|
+
page: page
|
|
3774
|
+
});
|
|
3775
|
+
});
|
|
3747
3776
|
};
|
|
3748
3777
|
}
|
|
3749
3778
|
var page = state.page || 0;
|
|
@@ -3753,7 +3782,7 @@
|
|
|
3753
3782
|
pager.currentPage = page;
|
|
3754
3783
|
pager.total = nbPages;
|
|
3755
3784
|
return {
|
|
3756
|
-
createURL: connectorState.createURL
|
|
3785
|
+
createURL: connectorState.createURL,
|
|
3757
3786
|
refine: connectorState.refine,
|
|
3758
3787
|
canRefine: nbPages > 1,
|
|
3759
3788
|
currentRefinement: page,
|
|
@@ -4196,6 +4225,7 @@
|
|
|
4196
4225
|
});
|
|
4197
4226
|
},
|
|
4198
4227
|
getWidgetRenderState: function getWidgetRenderState(renderOptions) {
|
|
4228
|
+
var _this = this;
|
|
4199
4229
|
var results = renderOptions.results,
|
|
4200
4230
|
state = renderOptions.state,
|
|
4201
4231
|
_createURL = renderOptions.createURL,
|
|
@@ -4249,7 +4279,12 @@
|
|
|
4249
4279
|
var canToggleShowMore = canShowLess || canShowMore;
|
|
4250
4280
|
return {
|
|
4251
4281
|
createURL: function createURL(facetValue) {
|
|
4252
|
-
return _createURL(
|
|
4282
|
+
return _createURL(function (uiState) {
|
|
4283
|
+
return _this.getWidgetUiState(uiState, {
|
|
4284
|
+
searchParameters: state.resetPage().toggleFacetRefinement(attribute, facetValue),
|
|
4285
|
+
helper: helper
|
|
4286
|
+
});
|
|
4287
|
+
});
|
|
4253
4288
|
},
|
|
4254
4289
|
items: items,
|
|
4255
4290
|
refine: triggerRefine,
|
|
@@ -4615,9 +4650,16 @@
|
|
|
4615
4650
|
},
|
|
4616
4651
|
createURLFactory: function createURLFactory(_ref4) {
|
|
4617
4652
|
var state = _ref4.state,
|
|
4618
|
-
createURL = _ref4.createURL
|
|
4653
|
+
createURL = _ref4.createURL,
|
|
4654
|
+
getWidgetUiState = _ref4.getWidgetUiState,
|
|
4655
|
+
helper = _ref4.helper;
|
|
4619
4656
|
return function (value) {
|
|
4620
|
-
return createURL(
|
|
4657
|
+
return createURL(function (uiState) {
|
|
4658
|
+
return getWidgetUiState(uiState, {
|
|
4659
|
+
searchParameters: getRefinedState(state, value),
|
|
4660
|
+
helper: helper
|
|
4661
|
+
});
|
|
4662
|
+
});
|
|
4621
4663
|
};
|
|
4622
4664
|
}
|
|
4623
4665
|
};
|
|
@@ -4713,7 +4755,9 @@
|
|
|
4713
4755
|
sendEvent: sendEvent,
|
|
4714
4756
|
createURL: connectorState.createURLFactory({
|
|
4715
4757
|
state: state,
|
|
4716
|
-
createURL: createURL
|
|
4758
|
+
createURL: createURL,
|
|
4759
|
+
helper: helper,
|
|
4760
|
+
getWidgetUiState: this.getWidgetUiState
|
|
4717
4761
|
}),
|
|
4718
4762
|
widgetParams: widgetParams
|
|
4719
4763
|
};
|
|
@@ -4925,7 +4969,9 @@
|
|
|
4925
4969
|
var connectorState = {
|
|
4926
4970
|
createURLFactory: function createURLFactory(isRefined, _ref4) {
|
|
4927
4971
|
var state = _ref4.state,
|
|
4928
|
-
createURL = _ref4.createURL
|
|
4972
|
+
createURL = _ref4.createURL,
|
|
4973
|
+
getWidgetUiState = _ref4.getWidgetUiState,
|
|
4974
|
+
helper = _ref4.helper;
|
|
4929
4975
|
return function () {
|
|
4930
4976
|
state = state.resetPage();
|
|
4931
4977
|
var valuesToRemove = isRefined ? on : off;
|
|
@@ -4940,7 +4986,12 @@
|
|
|
4940
4986
|
state = state.addDisjunctiveFacetRefinement(attribute, v);
|
|
4941
4987
|
});
|
|
4942
4988
|
}
|
|
4943
|
-
return createURL(
|
|
4989
|
+
return createURL(function (uiState) {
|
|
4990
|
+
return getWidgetUiState(uiState, {
|
|
4991
|
+
searchParameters: state,
|
|
4992
|
+
helper: helper
|
|
4993
|
+
});
|
|
4994
|
+
});
|
|
4944
4995
|
};
|
|
4945
4996
|
}
|
|
4946
4997
|
};
|
|
@@ -5045,7 +5096,9 @@
|
|
|
5045
5096
|
},
|
|
5046
5097
|
createURL: connectorState.createURLFactory(isRefined, {
|
|
5047
5098
|
state: state,
|
|
5048
|
-
createURL: createURL
|
|
5099
|
+
createURL: createURL,
|
|
5100
|
+
helper: helper,
|
|
5101
|
+
getWidgetUiState: this.getWidgetUiState
|
|
5049
5102
|
}),
|
|
5050
5103
|
sendEvent: sendEvent,
|
|
5051
5104
|
canRefine: Boolean(results ? nextRefinement.count : null),
|
|
@@ -5059,6 +5112,9 @@
|
|
|
5059
5112
|
return searchParameters.isDisjunctiveFacetRefined(attribute, v);
|
|
5060
5113
|
});
|
|
5061
5114
|
if (!isRefined) {
|
|
5115
|
+
var _uiState$toggle;
|
|
5116
|
+
// This needs to be done in the case `uiState` comes from `createURL`
|
|
5117
|
+
(_uiState$toggle = uiState.toggle) === null || _uiState$toggle === void 0 ? true : delete _uiState$toggle[attribute];
|
|
5062
5118
|
return uiState;
|
|
5063
5119
|
}
|
|
5064
5120
|
return _objectSpread2(_objectSpread2({}, uiState), {}, {
|
|
@@ -5157,6 +5213,7 @@
|
|
|
5157
5213
|
});
|
|
5158
5214
|
},
|
|
5159
5215
|
getWidgetRenderState: function getWidgetRenderState(_ref2) {
|
|
5216
|
+
var _this = this;
|
|
5160
5217
|
var helper = _ref2.helper,
|
|
5161
5218
|
createURL = _ref2.createURL,
|
|
5162
5219
|
results = _ref2.results,
|
|
@@ -5180,7 +5237,12 @@
|
|
|
5180
5237
|
var items = getItems();
|
|
5181
5238
|
if (!connectorState.createURL) {
|
|
5182
5239
|
connectorState.createURL = function (facetValue) {
|
|
5183
|
-
return createURL(
|
|
5240
|
+
return createURL(function (uiState) {
|
|
5241
|
+
return _this.getWidgetUiState(uiState, {
|
|
5242
|
+
searchParameters: getRefinedState(helper.state, facetValue),
|
|
5243
|
+
helper: helper
|
|
5244
|
+
});
|
|
5245
|
+
});
|
|
5184
5246
|
};
|
|
5185
5247
|
}
|
|
5186
5248
|
if (!connectorState.refine) {
|
|
@@ -5196,18 +5258,39 @@
|
|
|
5196
5258
|
widgetParams: widgetParams
|
|
5197
5259
|
};
|
|
5198
5260
|
},
|
|
5199
|
-
|
|
5261
|
+
getWidgetUiState: function getWidgetUiState(uiState, _ref3) {
|
|
5262
|
+
var searchParameters = _ref3.searchParameters;
|
|
5263
|
+
var path = searchParameters.getHierarchicalFacetBreadcrumb(hierarchicalFacetName);
|
|
5264
|
+
if (!path.length) {
|
|
5265
|
+
return uiState;
|
|
5266
|
+
}
|
|
5267
|
+
return _objectSpread2(_objectSpread2({}, uiState), {}, {
|
|
5268
|
+
hierarchicalMenu: _objectSpread2(_objectSpread2({}, uiState.hierarchicalMenu), {}, _defineProperty({}, hierarchicalFacetName, path))
|
|
5269
|
+
});
|
|
5270
|
+
},
|
|
5271
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref4) {
|
|
5272
|
+
var uiState = _ref4.uiState;
|
|
5273
|
+
var values = uiState.hierarchicalMenu && uiState.hierarchicalMenu[hierarchicalFacetName];
|
|
5274
|
+
if (searchParameters.isConjunctiveFacet(hierarchicalFacetName) || searchParameters.isDisjunctiveFacet(hierarchicalFacetName)) {
|
|
5275
|
+
_warning(false, "HierarchicalMenu: Attribute \"".concat(hierarchicalFacetName, "\" is already used by another widget applying conjunctive or disjunctive faceting.\nAs this is not supported, please make sure to remove this other widget or this HierarchicalMenu widget will not work at all.")) ;
|
|
5276
|
+
return searchParameters;
|
|
5277
|
+
}
|
|
5200
5278
|
if (searchParameters.isHierarchicalFacet(hierarchicalFacetName)) {
|
|
5201
5279
|
var facet = searchParameters.getHierarchicalFacetByName(hierarchicalFacetName);
|
|
5202
5280
|
_warning(isEqual(facet.attributes, attributes) && facet.separator === separator && facet.rootPath === rootPath, 'Using Breadcrumb and HierarchicalMenu on the same facet with different options overrides the configuration of the HierarchicalMenu.') ;
|
|
5203
|
-
return searchParameters;
|
|
5204
5281
|
}
|
|
5205
|
-
|
|
5282
|
+
var withFacetConfiguration = searchParameters.removeHierarchicalFacet(hierarchicalFacetName).addHierarchicalFacet({
|
|
5206
5283
|
name: hierarchicalFacetName,
|
|
5207
5284
|
attributes: attributes,
|
|
5208
5285
|
separator: separator,
|
|
5209
5286
|
rootPath: rootPath
|
|
5210
5287
|
});
|
|
5288
|
+
if (!values) {
|
|
5289
|
+
return withFacetConfiguration.setQueryParameters({
|
|
5290
|
+
hierarchicalFacetsRefinements: _objectSpread2(_objectSpread2({}, withFacetConfiguration.hierarchicalFacetsRefinements), {}, _defineProperty({}, hierarchicalFacetName, []))
|
|
5291
|
+
});
|
|
5292
|
+
}
|
|
5293
|
+
return withFacetConfiguration.addHierarchicalFacetRefinement(hierarchicalFacetName, values.join(separator));
|
|
5211
5294
|
}
|
|
5212
5295
|
};
|
|
5213
5296
|
};
|
|
@@ -5488,45 +5571,32 @@
|
|
|
5488
5571
|
};
|
|
5489
5572
|
|
|
5490
5573
|
function clone(value) {
|
|
5491
|
-
if (
|
|
5574
|
+
if (_typeof(value) === 'object' && value !== null) {
|
|
5492
5575
|
return _merge(Array.isArray(value) ? [] : {}, value);
|
|
5493
5576
|
}
|
|
5494
5577
|
return value;
|
|
5495
5578
|
}
|
|
5496
|
-
|
|
5497
5579
|
function isObjectOrArrayOrFunction(value) {
|
|
5498
|
-
return (
|
|
5499
|
-
typeof value === 'function' ||
|
|
5500
|
-
Array.isArray(value) ||
|
|
5501
|
-
Object.prototype.toString.call(value) === '[object Object]'
|
|
5502
|
-
);
|
|
5580
|
+
return typeof value === 'function' || Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]';
|
|
5503
5581
|
}
|
|
5504
|
-
|
|
5505
5582
|
function _merge(target, source) {
|
|
5506
5583
|
if (target === source) {
|
|
5507
5584
|
return target;
|
|
5508
5585
|
}
|
|
5509
5586
|
|
|
5587
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
5510
5588
|
for (var key in source) {
|
|
5511
|
-
if (
|
|
5512
|
-
|
|
5513
|
-
key === '__proto__' ||
|
|
5514
|
-
key === 'constructor'
|
|
5515
|
-
) {
|
|
5589
|
+
if (!Object.prototype.hasOwnProperty.call(source, key) || key === '__proto__' || key === 'constructor') {
|
|
5590
|
+
// eslint-disable-next-line no-continue
|
|
5516
5591
|
continue;
|
|
5517
5592
|
}
|
|
5518
|
-
|
|
5519
5593
|
var sourceVal = source[key];
|
|
5520
5594
|
var targetVal = target[key];
|
|
5521
|
-
|
|
5522
5595
|
if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
|
|
5596
|
+
// eslint-disable-next-line no-continue
|
|
5523
5597
|
continue;
|
|
5524
5598
|
}
|
|
5525
|
-
|
|
5526
|
-
if (
|
|
5527
|
-
isObjectOrArrayOrFunction(targetVal) &&
|
|
5528
|
-
isObjectOrArrayOrFunction(sourceVal)
|
|
5529
|
-
) {
|
|
5599
|
+
if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
|
|
5530
5600
|
target[key] = _merge(targetVal, sourceVal);
|
|
5531
5601
|
} else {
|
|
5532
5602
|
target[key] = clone(sourceVal);
|
|
@@ -5546,35 +5616,34 @@
|
|
|
5546
5616
|
* - treats sparse arrays as sparse
|
|
5547
5617
|
* - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
|
|
5548
5618
|
*
|
|
5549
|
-
* @param {Object}
|
|
5619
|
+
* @param {Object} target The destination object.
|
|
5550
5620
|
* @param {...Object} [sources] The source objects.
|
|
5551
5621
|
* @returns {Object} Returns `object`.
|
|
5552
5622
|
*/
|
|
5553
|
-
|
|
5554
5623
|
function merge(target) {
|
|
5555
5624
|
if (!isObjectOrArrayOrFunction(target)) {
|
|
5556
5625
|
target = {};
|
|
5557
5626
|
}
|
|
5558
|
-
|
|
5559
5627
|
for (var i = 1, l = arguments.length; i < l; i++) {
|
|
5560
5628
|
var source = arguments[i];
|
|
5561
|
-
|
|
5562
5629
|
if (isObjectOrArrayOrFunction(source)) {
|
|
5563
5630
|
_merge(target, source);
|
|
5564
5631
|
}
|
|
5565
5632
|
}
|
|
5566
5633
|
return target;
|
|
5567
5634
|
}
|
|
5635
|
+
module.exports = merge;
|
|
5568
5636
|
|
|
5569
|
-
var
|
|
5637
|
+
var merge$1 = /*#__PURE__*/Object.freeze({
|
|
5638
|
+
__proto__: null
|
|
5639
|
+
});
|
|
5570
5640
|
|
|
5571
5641
|
// NOTE: this behaves like lodash/defaults, but doesn't mutate the target
|
|
5572
5642
|
// it also preserve keys order
|
|
5573
5643
|
var defaultsPure = function defaultsPure() {
|
|
5574
5644
|
var sources = Array.prototype.slice.call(arguments);
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
Object.keys(Object(source)).forEach(function(key) {
|
|
5645
|
+
return sources.reduceRight(function (acc, source) {
|
|
5646
|
+
Object.keys(Object(source)).forEach(function (key) {
|
|
5578
5647
|
if (source[key] === undefined) {
|
|
5579
5648
|
return;
|
|
5580
5649
|
}
|
|
@@ -5589,11 +5658,8 @@
|
|
|
5589
5658
|
};
|
|
5590
5659
|
|
|
5591
5660
|
function intersection(arr1, arr2) {
|
|
5592
|
-
return arr1.filter(function(value, index) {
|
|
5593
|
-
return (
|
|
5594
|
-
arr2.indexOf(value) > -1 &&
|
|
5595
|
-
arr1.indexOf(value) === index /* skips duplicates */
|
|
5596
|
-
);
|
|
5661
|
+
return arr1.filter(function (value, index) {
|
|
5662
|
+
return arr2.indexOf(value) > -1 && arr1.indexOf(value) === index /* skips duplicates */;
|
|
5597
5663
|
});
|
|
5598
5664
|
}
|
|
5599
5665
|
|
|
@@ -5604,12 +5670,12 @@
|
|
|
5604
5670
|
if (!Array.isArray(array)) {
|
|
5605
5671
|
return undefined;
|
|
5606
5672
|
}
|
|
5607
|
-
|
|
5608
5673
|
for (var i = 0; i < array.length; i++) {
|
|
5609
5674
|
if (comparator(array[i])) {
|
|
5610
5675
|
return array[i];
|
|
5611
5676
|
}
|
|
5612
5677
|
}
|
|
5678
|
+
return undefined;
|
|
5613
5679
|
};
|
|
5614
5680
|
|
|
5615
5681
|
function valToNumber(v) {
|
|
@@ -5620,10 +5686,8 @@
|
|
|
5620
5686
|
} else if (Array.isArray(v)) {
|
|
5621
5687
|
return v.map(valToNumber);
|
|
5622
5688
|
}
|
|
5623
|
-
|
|
5624
5689
|
throw new Error('The value should be a number, a parsable string or an array of those.');
|
|
5625
5690
|
}
|
|
5626
|
-
|
|
5627
5691
|
var valToNumber_1 = valToNumber;
|
|
5628
5692
|
|
|
5629
5693
|
// https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
|
|
@@ -5635,18 +5699,17 @@
|
|
|
5635
5699
|
var i;
|
|
5636
5700
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
5637
5701
|
key = sourceKeys[i];
|
|
5702
|
+
// eslint-disable-next-line no-continue
|
|
5638
5703
|
if (excluded.indexOf(key) >= 0) continue;
|
|
5639
5704
|
target[key] = source[key];
|
|
5640
5705
|
}
|
|
5641
5706
|
return target;
|
|
5642
5707
|
}
|
|
5643
|
-
|
|
5644
5708
|
var omit$1 = _objectWithoutPropertiesLoose$1;
|
|
5645
5709
|
|
|
5646
5710
|
function objectHasKeys(obj) {
|
|
5647
5711
|
return obj && Object.keys(obj).length > 0;
|
|
5648
5712
|
}
|
|
5649
|
-
|
|
5650
5713
|
var objectHasKeys_1 = objectHasKeys;
|
|
5651
5714
|
|
|
5652
5715
|
var isValidUserToken = function isValidUserToken(userToken) {
|
|
@@ -5670,8 +5733,6 @@
|
|
|
5670
5733
|
|
|
5671
5734
|
|
|
5672
5735
|
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
5736
|
var lib = {
|
|
5676
5737
|
/**
|
|
5677
5738
|
* Adds a refinement to a RefinementList
|
|
@@ -5684,17 +5745,10 @@
|
|
|
5684
5745
|
if (lib.isRefined(refinementList, attribute, value)) {
|
|
5685
5746
|
return refinementList;
|
|
5686
5747
|
}
|
|
5687
|
-
|
|
5688
5748
|
var valueAsString = '' + value;
|
|
5689
|
-
|
|
5690
|
-
var facetRefinement = !refinementList[attribute] ?
|
|
5691
|
-
[valueAsString] :
|
|
5692
|
-
refinementList[attribute].concat(valueAsString);
|
|
5693
|
-
|
|
5749
|
+
var facetRefinement = !refinementList[attribute] ? [valueAsString] : refinementList[attribute].concat(valueAsString);
|
|
5694
5750
|
var mod = {};
|
|
5695
|
-
|
|
5696
5751
|
mod[attribute] = facetRefinement;
|
|
5697
|
-
|
|
5698
5752
|
return defaultsPure({}, mod, refinementList);
|
|
5699
5753
|
},
|
|
5700
5754
|
/**
|
|
@@ -5710,14 +5764,12 @@
|
|
|
5710
5764
|
if (value === undefined) {
|
|
5711
5765
|
// we use the "filter" form of clearRefinement, since it leaves empty values as-is
|
|
5712
5766
|
// the form with a string will remove the attribute completely
|
|
5713
|
-
return lib.clearRefinement(refinementList, function(v, f) {
|
|
5767
|
+
return lib.clearRefinement(refinementList, function (v, f) {
|
|
5714
5768
|
return attribute === f;
|
|
5715
5769
|
});
|
|
5716
5770
|
}
|
|
5717
|
-
|
|
5718
5771
|
var valueAsString = '' + value;
|
|
5719
|
-
|
|
5720
|
-
return lib.clearRefinement(refinementList, function(v, f) {
|
|
5772
|
+
return lib.clearRefinement(refinementList, function (v, f) {
|
|
5721
5773
|
return attribute === f && valueAsString === v;
|
|
5722
5774
|
});
|
|
5723
5775
|
},
|
|
@@ -5730,11 +5782,9 @@
|
|
|
5730
5782
|
*/
|
|
5731
5783
|
toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
|
|
5732
5784
|
if (value === undefined) throw new Error('toggleRefinement should be used with a value');
|
|
5733
|
-
|
|
5734
5785
|
if (lib.isRefined(refinementList, attribute, value)) {
|
|
5735
5786
|
return lib.removeRefinement(refinementList, attribute, value);
|
|
5736
5787
|
}
|
|
5737
|
-
|
|
5738
5788
|
return lib.addRefinement(refinementList, attribute, value);
|
|
5739
5789
|
},
|
|
5740
5790
|
/**
|
|
@@ -5750,6 +5800,8 @@
|
|
|
5750
5800
|
*/
|
|
5751
5801
|
clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
|
|
5752
5802
|
if (attribute === undefined) {
|
|
5803
|
+
// return the same object if the list is already empty
|
|
5804
|
+
// this is mainly for tests, as it doesn't have much impact on performance
|
|
5753
5805
|
if (!objectHasKeys_1(refinementList)) {
|
|
5754
5806
|
return refinementList;
|
|
5755
5807
|
}
|
|
@@ -5758,24 +5810,24 @@
|
|
|
5758
5810
|
return omit$1(refinementList, [attribute]);
|
|
5759
5811
|
} else if (typeof attribute === 'function') {
|
|
5760
5812
|
var hasChanged = false;
|
|
5761
|
-
|
|
5762
|
-
var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
|
|
5813
|
+
var newRefinementList = Object.keys(refinementList).reduce(function (memo, key) {
|
|
5763
5814
|
var values = refinementList[key] || [];
|
|
5764
|
-
var facetList = values.filter(function(value) {
|
|
5815
|
+
var facetList = values.filter(function (value) {
|
|
5765
5816
|
return !attribute(value, key, refinementType);
|
|
5766
5817
|
});
|
|
5767
|
-
|
|
5768
5818
|
if (facetList.length !== values.length) {
|
|
5769
5819
|
hasChanged = true;
|
|
5770
5820
|
}
|
|
5771
5821
|
memo[key] = facetList;
|
|
5772
|
-
|
|
5773
5822
|
return memo;
|
|
5774
5823
|
}, {});
|
|
5775
|
-
|
|
5776
5824
|
if (hasChanged) return newRefinementList;
|
|
5777
5825
|
return refinementList;
|
|
5778
5826
|
}
|
|
5827
|
+
|
|
5828
|
+
// We return nothing if the attribute is not undefined, a string or a function,
|
|
5829
|
+
// as it is not a valid value for a refinement
|
|
5830
|
+
return undefined;
|
|
5779
5831
|
},
|
|
5780
5832
|
/**
|
|
5781
5833
|
* Test if the refinement value is used for the attribute. If no refinement value
|
|
@@ -5784,22 +5836,17 @@
|
|
|
5784
5836
|
* @param {RefinementList} refinementList the list of refinement
|
|
5785
5837
|
* @param {string} attribute name of the attribute
|
|
5786
5838
|
* @param {string} [refinementValue] value of the filter/refinement
|
|
5787
|
-
* @return {boolean}
|
|
5839
|
+
* @return {boolean} true if the attribute is refined, false otherwise
|
|
5788
5840
|
*/
|
|
5789
5841
|
isRefined: function isRefined(refinementList, attribute, refinementValue) {
|
|
5790
|
-
var containsRefinements =
|
|
5791
|
-
refinementList[attribute].length > 0;
|
|
5792
|
-
|
|
5842
|
+
var containsRefinements = Boolean(refinementList[attribute]) && refinementList[attribute].length > 0;
|
|
5793
5843
|
if (refinementValue === undefined || !containsRefinements) {
|
|
5794
5844
|
return containsRefinements;
|
|
5795
5845
|
}
|
|
5796
|
-
|
|
5797
5846
|
var refinementValueAsString = '' + refinementValue;
|
|
5798
|
-
|
|
5799
5847
|
return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
|
|
5800
5848
|
}
|
|
5801
5849
|
};
|
|
5802
|
-
|
|
5803
5850
|
var RefinementList = lib;
|
|
5804
5851
|
|
|
5805
5852
|
/**
|
|
@@ -5808,15 +5855,15 @@
|
|
|
5808
5855
|
* - [5]
|
|
5809
5856
|
* - [[5]]
|
|
5810
5857
|
* - [[5,5],[4]]
|
|
5858
|
+
* @param {any} a numeric refinement value
|
|
5859
|
+
* @param {any} b numeric refinement value
|
|
5860
|
+
* @return {boolean} true if the values are equal
|
|
5811
5861
|
*/
|
|
5812
5862
|
function isEqualNumericRefinement(a, b) {
|
|
5813
5863
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
5814
|
-
return (
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
return isEqualNumericRefinement(b[i], el);
|
|
5818
|
-
})
|
|
5819
|
-
);
|
|
5864
|
+
return a.length === b.length && a.every(function (el, i) {
|
|
5865
|
+
return isEqualNumericRefinement(b[i], el);
|
|
5866
|
+
});
|
|
5820
5867
|
}
|
|
5821
5868
|
return a === b;
|
|
5822
5869
|
}
|
|
@@ -5830,7 +5877,7 @@
|
|
|
5830
5877
|
* @return {any} the searched value or undefined
|
|
5831
5878
|
*/
|
|
5832
5879
|
function findArray(array, searchedValue) {
|
|
5833
|
-
return find$1(array, function(currentValue) {
|
|
5880
|
+
return find$1(array, function (currentValue) {
|
|
5834
5881
|
return isEqualNumericRefinement(currentValue, searchedValue);
|
|
5835
5882
|
});
|
|
5836
5883
|
}
|
|
@@ -5884,8 +5931,8 @@
|
|
|
5884
5931
|
*/
|
|
5885
5932
|
function SearchParameters(newParameters) {
|
|
5886
5933
|
var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
|
|
5887
|
-
|
|
5888
5934
|
if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
|
|
5935
|
+
// eslint-disable-next-line no-console
|
|
5889
5936
|
console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
|
|
5890
5937
|
}
|
|
5891
5938
|
/**
|
|
@@ -5988,11 +6035,11 @@
|
|
|
5988
6035
|
*/
|
|
5989
6036
|
this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
|
|
5990
6037
|
|
|
6038
|
+
// eslint-disable-next-line consistent-this
|
|
5991
6039
|
var self = this;
|
|
5992
|
-
Object.keys(params).forEach(function(paramName) {
|
|
6040
|
+
Object.keys(params).forEach(function (paramName) {
|
|
5993
6041
|
var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
|
|
5994
6042
|
var isValueDefined = params[paramName] !== undefined;
|
|
5995
|
-
|
|
5996
6043
|
if (!isKeyKnown && isValueDefined) {
|
|
5997
6044
|
self[paramName] = params[paramName];
|
|
5998
6045
|
}
|
|
@@ -6011,27 +6058,12 @@
|
|
|
6011
6058
|
* @param {object} partialState full or part of a state
|
|
6012
6059
|
* @return {object} a new object with the number keys as number
|
|
6013
6060
|
*/
|
|
6014
|
-
SearchParameters._parseNumbers = function(partialState) {
|
|
6015
|
-
// Do not
|
|
6061
|
+
SearchParameters._parseNumbers = function (partialState) {
|
|
6062
|
+
// Do not parse numbers again in SearchParameters, they ought to be parsed already
|
|
6016
6063
|
if (partialState instanceof SearchParameters) return partialState;
|
|
6017
|
-
|
|
6018
6064
|
var numbers = {};
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
'aroundPrecision',
|
|
6022
|
-
'aroundRadius',
|
|
6023
|
-
'getRankingInfo',
|
|
6024
|
-
'minWordSizefor2Typos',
|
|
6025
|
-
'minWordSizefor1Typo',
|
|
6026
|
-
'page',
|
|
6027
|
-
'maxValuesPerFacet',
|
|
6028
|
-
'distinct',
|
|
6029
|
-
'minimumAroundRadius',
|
|
6030
|
-
'hitsPerPage',
|
|
6031
|
-
'minProximity'
|
|
6032
|
-
];
|
|
6033
|
-
|
|
6034
|
-
numberKeys.forEach(function(k) {
|
|
6065
|
+
var numberKeys = ['aroundPrecision', 'aroundRadius', 'getRankingInfo', 'minWordSizefor2Typos', 'minWordSizefor1Typo', 'page', 'maxValuesPerFacet', 'distinct', 'minimumAroundRadius', 'hitsPerPage', 'minProximity'];
|
|
6066
|
+
numberKeys.forEach(function (k) {
|
|
6035
6067
|
var value = partialState[k];
|
|
6036
6068
|
if (typeof value === 'string') {
|
|
6037
6069
|
var parsedValue = parseFloat(value);
|
|
@@ -6043,26 +6075,25 @@
|
|
|
6043
6075
|
// there's two formats of insideBoundingBox, we need to parse
|
|
6044
6076
|
// the one which is an array of float geo rectangles
|
|
6045
6077
|
if (Array.isArray(partialState.insideBoundingBox)) {
|
|
6046
|
-
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
|
|
6078
|
+
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (geoRect) {
|
|
6047
6079
|
if (Array.isArray(geoRect)) {
|
|
6048
|
-
return geoRect.map(function(value) {
|
|
6080
|
+
return geoRect.map(function (value) {
|
|
6049
6081
|
return parseFloat(value);
|
|
6050
6082
|
});
|
|
6051
6083
|
}
|
|
6052
6084
|
return geoRect;
|
|
6053
6085
|
});
|
|
6054
6086
|
}
|
|
6055
|
-
|
|
6056
6087
|
if (partialState.numericRefinements) {
|
|
6057
6088
|
var numericRefinements = {};
|
|
6058
|
-
Object.keys(partialState.numericRefinements).forEach(function(attribute) {
|
|
6089
|
+
Object.keys(partialState.numericRefinements).forEach(function (attribute) {
|
|
6059
6090
|
var operators = partialState.numericRefinements[attribute] || {};
|
|
6060
6091
|
numericRefinements[attribute] = {};
|
|
6061
|
-
Object.keys(operators).forEach(function(operator) {
|
|
6092
|
+
Object.keys(operators).forEach(function (operator) {
|
|
6062
6093
|
var values = operators[operator];
|
|
6063
|
-
var parsedValues = values.map(function(v) {
|
|
6094
|
+
var parsedValues = values.map(function (v) {
|
|
6064
6095
|
if (Array.isArray(v)) {
|
|
6065
|
-
return v.map(function(vPrime) {
|
|
6096
|
+
return v.map(function (vPrime) {
|
|
6066
6097
|
if (typeof vPrime === 'string') {
|
|
6067
6098
|
return parseFloat(vPrime);
|
|
6068
6099
|
}
|
|
@@ -6078,8 +6109,7 @@
|
|
|
6078
6109
|
});
|
|
6079
6110
|
numbers.numericRefinements = numericRefinements;
|
|
6080
6111
|
}
|
|
6081
|
-
|
|
6082
|
-
return merge_1({}, partialState, numbers);
|
|
6112
|
+
return merge$1({}, partialState, numbers);
|
|
6083
6113
|
};
|
|
6084
6114
|
|
|
6085
6115
|
/**
|
|
@@ -6090,12 +6120,10 @@
|
|
|
6090
6120
|
*/
|
|
6091
6121
|
SearchParameters.make = function makeSearchParameters(newParameters) {
|
|
6092
6122
|
var instance = new SearchParameters(newParameters);
|
|
6093
|
-
|
|
6094
6123
|
var hierarchicalFacets = newParameters.hierarchicalFacets || [];
|
|
6095
|
-
hierarchicalFacets.forEach(function(facet) {
|
|
6124
|
+
hierarchicalFacets.forEach(function (facet) {
|
|
6096
6125
|
if (facet.rootPath) {
|
|
6097
6126
|
var currentRefinement = instance.getHierarchicalRefinement(facet.name);
|
|
6098
|
-
|
|
6099
6127
|
if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
|
|
6100
6128
|
instance = instance.clearRefinements(facet.name);
|
|
6101
6129
|
}
|
|
@@ -6107,7 +6135,6 @@
|
|
|
6107
6135
|
}
|
|
6108
6136
|
}
|
|
6109
6137
|
});
|
|
6110
|
-
|
|
6111
6138
|
return instance;
|
|
6112
6139
|
};
|
|
6113
6140
|
|
|
@@ -6117,46 +6144,24 @@
|
|
|
6117
6144
|
* @param {object|SearchParameters} parameters the new parameters to set
|
|
6118
6145
|
* @return {Error|null} Error if the modification is invalid, null otherwise
|
|
6119
6146
|
*/
|
|
6120
|
-
SearchParameters.validate = function(currentState, parameters) {
|
|
6147
|
+
SearchParameters.validate = function (currentState, parameters) {
|
|
6121
6148
|
var params = parameters || {};
|
|
6122
|
-
|
|
6123
6149
|
if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
|
|
6124
|
-
return new Error(
|
|
6125
|
-
'[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
|
|
6126
|
-
'an error, if it is really what you want, you should first clear the tags with clearTags method.');
|
|
6150
|
+
return new Error('[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' + 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
|
|
6127
6151
|
}
|
|
6128
|
-
|
|
6129
6152
|
if (currentState.tagRefinements.length > 0 && params.tagFilters) {
|
|
6130
|
-
return new Error(
|
|
6131
|
-
'[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
|
|
6132
|
-
'an error, if it is not, you should first clear the tags with clearTags method.');
|
|
6153
|
+
return new Error('[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' + 'an error, if it is not, you should first clear the tags with clearTags method.');
|
|
6133
6154
|
}
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
currentState.numericFilters &&
|
|
6137
|
-
params.numericRefinements &&
|
|
6138
|
-
objectHasKeys_1(params.numericRefinements)
|
|
6139
|
-
) {
|
|
6140
|
-
return new Error(
|
|
6141
|
-
"[Numeric filters] Can't switch from the advanced to the managed API. It" +
|
|
6142
|
-
' is probably an error, if this is really what you want, you have to first' +
|
|
6143
|
-
' clear the numeric filters.'
|
|
6144
|
-
);
|
|
6155
|
+
if (currentState.numericFilters && params.numericRefinements && objectHasKeys_1(params.numericRefinements)) {
|
|
6156
|
+
return new Error("[Numeric filters] Can't switch from the advanced to the managed API. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
|
|
6145
6157
|
}
|
|
6146
|
-
|
|
6147
6158
|
if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
|
|
6148
|
-
return new Error(
|
|
6149
|
-
"[Numeric filters] Can't switch from the managed API to the advanced. It" +
|
|
6150
|
-
' is probably an error, if this is really what you want, you have to first' +
|
|
6151
|
-
' clear the numeric filters.');
|
|
6159
|
+
return new Error("[Numeric filters] Can't switch from the managed API to the advanced. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
|
|
6152
6160
|
}
|
|
6153
|
-
|
|
6154
6161
|
return null;
|
|
6155
6162
|
};
|
|
6156
|
-
|
|
6157
6163
|
SearchParameters.prototype = {
|
|
6158
6164
|
constructor: SearchParameters,
|
|
6159
|
-
|
|
6160
6165
|
/**
|
|
6161
6166
|
* Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
|
|
6162
6167
|
* @method
|
|
@@ -6164,39 +6169,17 @@
|
|
|
6164
6169
|
* - If not given, means to clear all the filters.
|
|
6165
6170
|
* - If `string`, means to clear all refinements for the `attribute` named filter.
|
|
6166
6171
|
* - If `function`, means to clear all the refinements that return truthy values.
|
|
6167
|
-
* @return {SearchParameters}
|
|
6172
|
+
* @return {SearchParameters} new instance with filters cleared
|
|
6168
6173
|
*/
|
|
6169
6174
|
clearRefinements: function clearRefinements(attribute) {
|
|
6170
6175
|
var patch = {
|
|
6171
6176
|
numericRefinements: this._clearNumericRefinements(attribute),
|
|
6172
|
-
facetsRefinements: RefinementList.clearRefinement(
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
),
|
|
6177
|
-
facetsExcludes: RefinementList.clearRefinement(
|
|
6178
|
-
this.facetsExcludes,
|
|
6179
|
-
attribute,
|
|
6180
|
-
'exclude'
|
|
6181
|
-
),
|
|
6182
|
-
disjunctiveFacetsRefinements: RefinementList.clearRefinement(
|
|
6183
|
-
this.disjunctiveFacetsRefinements,
|
|
6184
|
-
attribute,
|
|
6185
|
-
'disjunctiveFacet'
|
|
6186
|
-
),
|
|
6187
|
-
hierarchicalFacetsRefinements: RefinementList.clearRefinement(
|
|
6188
|
-
this.hierarchicalFacetsRefinements,
|
|
6189
|
-
attribute,
|
|
6190
|
-
'hierarchicalFacet'
|
|
6191
|
-
)
|
|
6177
|
+
facetsRefinements: RefinementList.clearRefinement(this.facetsRefinements, attribute, 'conjunctiveFacet'),
|
|
6178
|
+
facetsExcludes: RefinementList.clearRefinement(this.facetsExcludes, attribute, 'exclude'),
|
|
6179
|
+
disjunctiveFacetsRefinements: RefinementList.clearRefinement(this.disjunctiveFacetsRefinements, attribute, 'disjunctiveFacet'),
|
|
6180
|
+
hierarchicalFacetsRefinements: RefinementList.clearRefinement(this.hierarchicalFacetsRefinements, attribute, 'hierarchicalFacet')
|
|
6192
6181
|
};
|
|
6193
|
-
if (
|
|
6194
|
-
patch.numericRefinements === this.numericRefinements &&
|
|
6195
|
-
patch.facetsRefinements === this.facetsRefinements &&
|
|
6196
|
-
patch.facetsExcludes === this.facetsExcludes &&
|
|
6197
|
-
patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
|
|
6198
|
-
patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
|
|
6199
|
-
) {
|
|
6182
|
+
if (patch.numericRefinements === this.numericRefinements && patch.facetsRefinements === this.facetsRefinements && patch.facetsExcludes === this.facetsExcludes && patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements && patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements) {
|
|
6200
6183
|
return this;
|
|
6201
6184
|
}
|
|
6202
6185
|
return this.setQueryParameters(patch);
|
|
@@ -6204,11 +6187,10 @@
|
|
|
6204
6187
|
/**
|
|
6205
6188
|
* Remove all the refined tags from the SearchParameters
|
|
6206
6189
|
* @method
|
|
6207
|
-
* @return {SearchParameters}
|
|
6190
|
+
* @return {SearchParameters} new instance with tags cleared
|
|
6208
6191
|
*/
|
|
6209
6192
|
clearTags: function clearTags() {
|
|
6210
6193
|
if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
|
|
6211
|
-
|
|
6212
6194
|
return this.setQueryParameters({
|
|
6213
6195
|
tagFilters: undefined,
|
|
6214
6196
|
tagRefinements: []
|
|
@@ -6218,11 +6200,10 @@
|
|
|
6218
6200
|
* Set the index.
|
|
6219
6201
|
* @method
|
|
6220
6202
|
* @param {string} index the index name
|
|
6221
|
-
* @return {SearchParameters}
|
|
6203
|
+
* @return {SearchParameters} new instance
|
|
6222
6204
|
*/
|
|
6223
6205
|
setIndex: function setIndex(index) {
|
|
6224
6206
|
if (index === this.index) return this;
|
|
6225
|
-
|
|
6226
6207
|
return this.setQueryParameters({
|
|
6227
6208
|
index: index
|
|
6228
6209
|
});
|
|
@@ -6231,11 +6212,10 @@
|
|
|
6231
6212
|
* Query setter
|
|
6232
6213
|
* @method
|
|
6233
6214
|
* @param {string} newQuery value for the new query
|
|
6234
|
-
* @return {SearchParameters}
|
|
6215
|
+
* @return {SearchParameters} new instance
|
|
6235
6216
|
*/
|
|
6236
6217
|
setQuery: function setQuery(newQuery) {
|
|
6237
6218
|
if (newQuery === this.query) return this;
|
|
6238
|
-
|
|
6239
6219
|
return this.setQueryParameters({
|
|
6240
6220
|
query: newQuery
|
|
6241
6221
|
});
|
|
@@ -6244,11 +6224,10 @@
|
|
|
6244
6224
|
* Page setter
|
|
6245
6225
|
* @method
|
|
6246
6226
|
* @param {number} newPage new page number
|
|
6247
|
-
* @return {SearchParameters}
|
|
6227
|
+
* @return {SearchParameters} new instance
|
|
6248
6228
|
*/
|
|
6249
6229
|
setPage: function setPage(newPage) {
|
|
6250
6230
|
if (newPage === this.page) return this;
|
|
6251
|
-
|
|
6252
6231
|
return this.setQueryParameters({
|
|
6253
6232
|
page: newPage
|
|
6254
6233
|
});
|
|
@@ -6258,7 +6237,7 @@
|
|
|
6258
6237
|
* The facets are the simple facets, used for conjunctive (and) faceting.
|
|
6259
6238
|
* @method
|
|
6260
6239
|
* @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
|
|
6261
|
-
* @return {SearchParameters}
|
|
6240
|
+
* @return {SearchParameters} new instance
|
|
6262
6241
|
*/
|
|
6263
6242
|
setFacets: function setFacets(facets) {
|
|
6264
6243
|
return this.setQueryParameters({
|
|
@@ -6270,7 +6249,7 @@
|
|
|
6270
6249
|
* Change the list of disjunctive (or) facets the helper chan handle.
|
|
6271
6250
|
* @method
|
|
6272
6251
|
* @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
|
|
6273
|
-
* @return {SearchParameters}
|
|
6252
|
+
* @return {SearchParameters} new instance
|
|
6274
6253
|
*/
|
|
6275
6254
|
setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
|
|
6276
6255
|
return this.setQueryParameters({
|
|
@@ -6282,11 +6261,10 @@
|
|
|
6282
6261
|
* Hits per page represents the number of hits retrieved for this query
|
|
6283
6262
|
* @method
|
|
6284
6263
|
* @param {number} n number of hits retrieved per page of results
|
|
6285
|
-
* @return {SearchParameters}
|
|
6264
|
+
* @return {SearchParameters} new instance
|
|
6286
6265
|
*/
|
|
6287
6266
|
setHitsPerPage: function setHitsPerPage(n) {
|
|
6288
6267
|
if (this.hitsPerPage === n) return this;
|
|
6289
|
-
|
|
6290
6268
|
return this.setQueryParameters({
|
|
6291
6269
|
hitsPerPage: n
|
|
6292
6270
|
});
|
|
@@ -6296,11 +6274,10 @@
|
|
|
6296
6274
|
* Set the value of typoTolerance
|
|
6297
6275
|
* @method
|
|
6298
6276
|
* @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
|
|
6299
|
-
* @return {SearchParameters}
|
|
6277
|
+
* @return {SearchParameters} new instance
|
|
6300
6278
|
*/
|
|
6301
6279
|
setTypoTolerance: function setTypoTolerance(typoTolerance) {
|
|
6302
6280
|
if (this.typoTolerance === typoTolerance) return this;
|
|
6303
|
-
|
|
6304
6281
|
return this.setQueryParameters({
|
|
6305
6282
|
typoTolerance: typoTolerance
|
|
6306
6283
|
});
|
|
@@ -6313,33 +6290,28 @@
|
|
|
6313
6290
|
* @param {string} attribute attribute to set the filter on
|
|
6314
6291
|
* @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
|
|
6315
6292
|
* @param {number | number[]} value value of the filter
|
|
6316
|
-
* @return {SearchParameters}
|
|
6293
|
+
* @return {SearchParameters} new instance
|
|
6317
6294
|
* @example
|
|
6318
6295
|
* // for price = 50 or 40
|
|
6319
|
-
*
|
|
6296
|
+
* state.addNumericRefinement('price', '=', [50, 40]);
|
|
6320
6297
|
* @example
|
|
6321
6298
|
* // for size = 38 and 40
|
|
6322
|
-
*
|
|
6323
|
-
*
|
|
6299
|
+
* state.addNumericRefinement('size', '=', 38);
|
|
6300
|
+
* state.addNumericRefinement('size', '=', 40);
|
|
6324
6301
|
*/
|
|
6325
|
-
addNumericRefinement: function(attribute, operator,
|
|
6326
|
-
var
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
var mod = merge_1({}, this.numericRefinements);
|
|
6331
|
-
|
|
6332
|
-
mod[attribute] = merge_1({}, mod[attribute]);
|
|
6333
|
-
|
|
6302
|
+
addNumericRefinement: function addNumericRefinement(attribute, operator, value) {
|
|
6303
|
+
var val = valToNumber_1(value);
|
|
6304
|
+
if (this.isNumericRefined(attribute, operator, val)) return this;
|
|
6305
|
+
var mod = merge$1({}, this.numericRefinements);
|
|
6306
|
+
mod[attribute] = merge$1({}, mod[attribute]);
|
|
6334
6307
|
if (mod[attribute][operator]) {
|
|
6335
6308
|
// Array copy
|
|
6336
6309
|
mod[attribute][operator] = mod[attribute][operator].slice();
|
|
6337
6310
|
// Add the element. Concat can't be used here because value can be an array.
|
|
6338
|
-
mod[attribute][operator].push(
|
|
6311
|
+
mod[attribute][operator].push(val);
|
|
6339
6312
|
} else {
|
|
6340
|
-
mod[attribute][operator] = [
|
|
6313
|
+
mod[attribute][operator] = [val];
|
|
6341
6314
|
}
|
|
6342
|
-
|
|
6343
6315
|
return this.setQueryParameters({
|
|
6344
6316
|
numericRefinements: mod
|
|
6345
6317
|
});
|
|
@@ -6349,7 +6321,7 @@
|
|
|
6349
6321
|
* @param {string} facetName name of the attribute used for faceting
|
|
6350
6322
|
* @return {string[]} list of refinements
|
|
6351
6323
|
*/
|
|
6352
|
-
getConjunctiveRefinements: function(facetName) {
|
|
6324
|
+
getConjunctiveRefinements: function getConjunctiveRefinements(facetName) {
|
|
6353
6325
|
if (!this.isConjunctiveFacet(facetName)) {
|
|
6354
6326
|
return [];
|
|
6355
6327
|
}
|
|
@@ -6360,7 +6332,7 @@
|
|
|
6360
6332
|
* @param {string} facetName name of the attribute used for faceting
|
|
6361
6333
|
* @return {string[]} list of refinements
|
|
6362
6334
|
*/
|
|
6363
|
-
getDisjunctiveRefinements: function(facetName) {
|
|
6335
|
+
getDisjunctiveRefinements: function getDisjunctiveRefinements(facetName) {
|
|
6364
6336
|
if (!this.isDisjunctiveFacet(facetName)) {
|
|
6365
6337
|
return [];
|
|
6366
6338
|
}
|
|
@@ -6371,7 +6343,7 @@
|
|
|
6371
6343
|
* @param {string} facetName name of the attribute used for faceting
|
|
6372
6344
|
* @return {string[]} list of refinements
|
|
6373
6345
|
*/
|
|
6374
|
-
getHierarchicalRefinement: function(facetName) {
|
|
6346
|
+
getHierarchicalRefinement: function getHierarchicalRefinement(facetName) {
|
|
6375
6347
|
// we send an array but we currently do not support multiple
|
|
6376
6348
|
// hierarchicalRefinements for a hierarchicalFacet
|
|
6377
6349
|
return this.hierarchicalFacetsRefinements[facetName] || [];
|
|
@@ -6381,47 +6353,42 @@
|
|
|
6381
6353
|
* @param {string} facetName name of the attribute used for faceting
|
|
6382
6354
|
* @return {string[]} list of refinements
|
|
6383
6355
|
*/
|
|
6384
|
-
getExcludeRefinements: function(facetName) {
|
|
6356
|
+
getExcludeRefinements: function getExcludeRefinements(facetName) {
|
|
6385
6357
|
if (!this.isConjunctiveFacet(facetName)) {
|
|
6386
6358
|
return [];
|
|
6387
6359
|
}
|
|
6388
6360
|
return this.facetsExcludes[facetName] || [];
|
|
6389
6361
|
},
|
|
6390
|
-
|
|
6391
6362
|
/**
|
|
6392
6363
|
* Remove all the numeric filter for a given (attribute, operator)
|
|
6393
6364
|
* @method
|
|
6394
6365
|
* @param {string} attribute attribute to set the filter on
|
|
6395
6366
|
* @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
|
|
6396
6367
|
* @param {number} [number] the value to be removed
|
|
6397
|
-
* @return {SearchParameters}
|
|
6368
|
+
* @return {SearchParameters} new instance
|
|
6398
6369
|
*/
|
|
6399
|
-
removeNumericRefinement: function(attribute, operator,
|
|
6370
|
+
removeNumericRefinement: function removeNumericRefinement(attribute, operator, number) {
|
|
6371
|
+
var paramValue = number;
|
|
6400
6372
|
if (paramValue !== undefined) {
|
|
6401
6373
|
if (!this.isNumericRefined(attribute, operator, paramValue)) {
|
|
6402
6374
|
return this;
|
|
6403
6375
|
}
|
|
6404
6376
|
return this.setQueryParameters({
|
|
6405
|
-
numericRefinements: this._clearNumericRefinements(function(value, key) {
|
|
6406
|
-
return (
|
|
6407
|
-
key === attribute &&
|
|
6408
|
-
value.op === operator &&
|
|
6409
|
-
isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
|
|
6410
|
-
);
|
|
6377
|
+
numericRefinements: this._clearNumericRefinements(function (value, key) {
|
|
6378
|
+
return key === attribute && value.op === operator && isEqualNumericRefinement(value.val, valToNumber_1(paramValue));
|
|
6411
6379
|
})
|
|
6412
6380
|
});
|
|
6413
6381
|
} else if (operator !== undefined) {
|
|
6414
6382
|
if (!this.isNumericRefined(attribute, operator)) return this;
|
|
6415
6383
|
return this.setQueryParameters({
|
|
6416
|
-
numericRefinements: this._clearNumericRefinements(function(value, key) {
|
|
6384
|
+
numericRefinements: this._clearNumericRefinements(function (value, key) {
|
|
6417
6385
|
return key === attribute && value.op === operator;
|
|
6418
6386
|
})
|
|
6419
6387
|
});
|
|
6420
6388
|
}
|
|
6421
|
-
|
|
6422
6389
|
if (!this.isNumericRefined(attribute)) return this;
|
|
6423
6390
|
return this.setQueryParameters({
|
|
6424
|
-
numericRefinements: this._clearNumericRefinements(function(value, key) {
|
|
6391
|
+
numericRefinements: this._clearNumericRefinements(function (value, key) {
|
|
6425
6392
|
return key === attribute;
|
|
6426
6393
|
})
|
|
6427
6394
|
});
|
|
@@ -6431,7 +6398,7 @@
|
|
|
6431
6398
|
* @param {string} facetName name of the attribute used for faceting
|
|
6432
6399
|
* @return {SearchParameters.OperatorList} list of refinements
|
|
6433
6400
|
*/
|
|
6434
|
-
getNumericRefinements: function(facetName) {
|
|
6401
|
+
getNumericRefinements: function getNumericRefinements(facetName) {
|
|
6435
6402
|
return this.numericRefinements[facetName] || {};
|
|
6436
6403
|
},
|
|
6437
6404
|
/**
|
|
@@ -6440,7 +6407,7 @@
|
|
|
6440
6407
|
* @param {string} operator operator applied on the refined values
|
|
6441
6408
|
* @return {Array.<number|number[]>} refined values
|
|
6442
6409
|
*/
|
|
6443
|
-
getNumericRefinement: function(attribute, operator) {
|
|
6410
|
+
getNumericRefinement: function getNumericRefinement(attribute, operator) {
|
|
6444
6411
|
return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
|
|
6445
6412
|
},
|
|
6446
6413
|
/**
|
|
@@ -6451,7 +6418,7 @@
|
|
|
6451
6418
|
* - If not given, means to clear all the filters.
|
|
6452
6419
|
* - If `string`, means to clear all refinements for the `attribute` named filter.
|
|
6453
6420
|
* - If `function`, means to clear all the refinements that return truthy values.
|
|
6454
|
-
* @return {Object.<string, OperatorList>}
|
|
6421
|
+
* @return {Object.<string, OperatorList>} new numeric refinements
|
|
6455
6422
|
*/
|
|
6456
6423
|
_clearNumericRefinements: function _clearNumericRefinements(attribute) {
|
|
6457
6424
|
if (attribute === undefined) {
|
|
@@ -6464,16 +6431,18 @@
|
|
|
6464
6431
|
} else if (typeof attribute === 'function') {
|
|
6465
6432
|
var hasChanged = false;
|
|
6466
6433
|
var numericRefinements = this.numericRefinements;
|
|
6467
|
-
var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
|
|
6434
|
+
var newNumericRefinements = Object.keys(numericRefinements).reduce(function (memo, key) {
|
|
6468
6435
|
var operators = numericRefinements[key];
|
|
6469
6436
|
var operatorList = {};
|
|
6470
|
-
|
|
6471
6437
|
operators = operators || {};
|
|
6472
|
-
Object.keys(operators).forEach(function(operator) {
|
|
6438
|
+
Object.keys(operators).forEach(function (operator) {
|
|
6473
6439
|
var values = operators[operator] || [];
|
|
6474
6440
|
var outValues = [];
|
|
6475
|
-
values.forEach(function(value) {
|
|
6476
|
-
var predicateResult = attribute({
|
|
6441
|
+
values.forEach(function (value) {
|
|
6442
|
+
var predicateResult = attribute({
|
|
6443
|
+
val: value,
|
|
6444
|
+
op: operator
|
|
6445
|
+
}, key, 'numeric');
|
|
6477
6446
|
if (!predicateResult) outValues.push(value);
|
|
6478
6447
|
});
|
|
6479
6448
|
if (outValues.length !== values.length) {
|
|
@@ -6481,28 +6450,28 @@
|
|
|
6481
6450
|
}
|
|
6482
6451
|
operatorList[operator] = outValues;
|
|
6483
6452
|
});
|
|
6484
|
-
|
|
6485
6453
|
memo[key] = operatorList;
|
|
6486
|
-
|
|
6487
6454
|
return memo;
|
|
6488
6455
|
}, {});
|
|
6489
|
-
|
|
6490
6456
|
if (hasChanged) return newNumericRefinements;
|
|
6491
6457
|
return this.numericRefinements;
|
|
6492
6458
|
}
|
|
6459
|
+
|
|
6460
|
+
// We return nothing if the attribute is not undefined, a string or a function,
|
|
6461
|
+
// as it is not a valid value for a refinement
|
|
6462
|
+
return undefined;
|
|
6493
6463
|
},
|
|
6494
6464
|
/**
|
|
6495
6465
|
* Add a facet to the facets attribute of the helper configuration, if it
|
|
6496
6466
|
* isn't already present.
|
|
6497
6467
|
* @method
|
|
6498
6468
|
* @param {string} facet facet name to add
|
|
6499
|
-
* @return {SearchParameters}
|
|
6469
|
+
* @return {SearchParameters} new instance
|
|
6500
6470
|
*/
|
|
6501
6471
|
addFacet: function addFacet(facet) {
|
|
6502
6472
|
if (this.isConjunctiveFacet(facet)) {
|
|
6503
6473
|
return this;
|
|
6504
6474
|
}
|
|
6505
|
-
|
|
6506
6475
|
return this.setQueryParameters({
|
|
6507
6476
|
facets: this.facets.concat([facet])
|
|
6508
6477
|
});
|
|
@@ -6512,13 +6481,12 @@
|
|
|
6512
6481
|
* configuration, if it isn't already present.
|
|
6513
6482
|
* @method
|
|
6514
6483
|
* @param {string} facet disjunctive facet name to add
|
|
6515
|
-
* @return {SearchParameters}
|
|
6484
|
+
* @return {SearchParameters} new instance
|
|
6516
6485
|
*/
|
|
6517
6486
|
addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
|
|
6518
6487
|
if (this.isDisjunctiveFacet(facet)) {
|
|
6519
6488
|
return this;
|
|
6520
6489
|
}
|
|
6521
|
-
|
|
6522
6490
|
return this.setQueryParameters({
|
|
6523
6491
|
disjunctiveFacets: this.disjunctiveFacets.concat([facet])
|
|
6524
6492
|
});
|
|
@@ -6528,15 +6496,13 @@
|
|
|
6528
6496
|
* configuration.
|
|
6529
6497
|
* @method
|
|
6530
6498
|
* @param {object} hierarchicalFacet hierarchical facet to add
|
|
6531
|
-
* @return {SearchParameters}
|
|
6499
|
+
* @return {SearchParameters} new instance
|
|
6532
6500
|
* @throws will throw an error if a hierarchical facet with the same name was already declared
|
|
6533
6501
|
*/
|
|
6534
6502
|
addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
|
|
6535
6503
|
if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
|
|
6536
|
-
throw new Error(
|
|
6537
|
-
'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
|
|
6504
|
+
throw new Error('Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
|
|
6538
6505
|
}
|
|
6539
|
-
|
|
6540
6506
|
return this.setQueryParameters({
|
|
6541
6507
|
hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
|
|
6542
6508
|
});
|
|
@@ -6546,14 +6512,13 @@
|
|
|
6546
6512
|
* @method
|
|
6547
6513
|
* @param {string} facet attribute to apply the faceting on
|
|
6548
6514
|
* @param {string} value value of the attribute (will be converted to string)
|
|
6549
|
-
* @return {SearchParameters}
|
|
6515
|
+
* @return {SearchParameters} new instance
|
|
6550
6516
|
*/
|
|
6551
6517
|
addFacetRefinement: function addFacetRefinement(facet, value) {
|
|
6552
6518
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6553
6519
|
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
|
|
6554
6520
|
}
|
|
6555
6521
|
if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
|
|
6556
|
-
|
|
6557
6522
|
return this.setQueryParameters({
|
|
6558
6523
|
facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
|
|
6559
6524
|
});
|
|
@@ -6563,14 +6528,13 @@
|
|
|
6563
6528
|
* @method
|
|
6564
6529
|
* @param {string} facet attribute to apply the exclusion on
|
|
6565
6530
|
* @param {string} value value of the attribute (will be converted to string)
|
|
6566
|
-
* @return {SearchParameters}
|
|
6531
|
+
* @return {SearchParameters} new instance
|
|
6567
6532
|
*/
|
|
6568
6533
|
addExcludeRefinement: function addExcludeRefinement(facet, value) {
|
|
6569
6534
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6570
6535
|
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
|
|
6571
6536
|
}
|
|
6572
6537
|
if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
|
|
6573
|
-
|
|
6574
6538
|
return this.setQueryParameters({
|
|
6575
6539
|
facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
|
|
6576
6540
|
});
|
|
@@ -6580,33 +6544,27 @@
|
|
|
6580
6544
|
* @method
|
|
6581
6545
|
* @param {string} facet attribute to apply the faceting on
|
|
6582
6546
|
* @param {string} value value of the attribute (will be converted to string)
|
|
6583
|
-
* @return {SearchParameters}
|
|
6547
|
+
* @return {SearchParameters} new instance
|
|
6584
6548
|
*/
|
|
6585
6549
|
addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
|
|
6586
6550
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
6587
|
-
throw new Error(
|
|
6588
|
-
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
|
|
6551
|
+
throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
|
|
6589
6552
|
}
|
|
6590
|
-
|
|
6591
6553
|
if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
|
|
6592
|
-
|
|
6593
6554
|
return this.setQueryParameters({
|
|
6594
|
-
disjunctiveFacetsRefinements: RefinementList.addRefinement(
|
|
6595
|
-
this.disjunctiveFacetsRefinements, facet, value)
|
|
6555
|
+
disjunctiveFacetsRefinements: RefinementList.addRefinement(this.disjunctiveFacetsRefinements, facet, value)
|
|
6596
6556
|
});
|
|
6597
6557
|
},
|
|
6598
6558
|
/**
|
|
6599
6559
|
* addTagRefinement adds a tag to the list used to filter the results
|
|
6600
6560
|
* @param {string} tag tag to be added
|
|
6601
|
-
* @return {SearchParameters}
|
|
6561
|
+
* @return {SearchParameters} new instance
|
|
6602
6562
|
*/
|
|
6603
6563
|
addTagRefinement: function addTagRefinement(tag) {
|
|
6604
6564
|
if (this.isTagRefined(tag)) return this;
|
|
6605
|
-
|
|
6606
6565
|
var modification = {
|
|
6607
6566
|
tagRefinements: this.tagRefinements.concat(tag)
|
|
6608
6567
|
};
|
|
6609
|
-
|
|
6610
6568
|
return this.setQueryParameters(modification);
|
|
6611
6569
|
},
|
|
6612
6570
|
/**
|
|
@@ -6614,15 +6572,14 @@
|
|
|
6614
6572
|
* is present.
|
|
6615
6573
|
* @method
|
|
6616
6574
|
* @param {string} facet facet name to remove
|
|
6617
|
-
* @return {SearchParameters}
|
|
6575
|
+
* @return {SearchParameters} new instance
|
|
6618
6576
|
*/
|
|
6619
6577
|
removeFacet: function removeFacet(facet) {
|
|
6620
6578
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6621
6579
|
return this;
|
|
6622
6580
|
}
|
|
6623
|
-
|
|
6624
6581
|
return this.clearRefinements(facet).setQueryParameters({
|
|
6625
|
-
facets: this.facets.filter(function(f) {
|
|
6582
|
+
facets: this.facets.filter(function (f) {
|
|
6626
6583
|
return f !== facet;
|
|
6627
6584
|
})
|
|
6628
6585
|
});
|
|
@@ -6632,15 +6589,14 @@
|
|
|
6632
6589
|
* helper configuration, if it is present.
|
|
6633
6590
|
* @method
|
|
6634
6591
|
* @param {string} facet disjunctive facet name to remove
|
|
6635
|
-
* @return {SearchParameters}
|
|
6592
|
+
* @return {SearchParameters} new instance
|
|
6636
6593
|
*/
|
|
6637
6594
|
removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
|
|
6638
6595
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
6639
6596
|
return this;
|
|
6640
6597
|
}
|
|
6641
|
-
|
|
6642
6598
|
return this.clearRefinements(facet).setQueryParameters({
|
|
6643
|
-
disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
|
|
6599
|
+
disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
|
|
6644
6600
|
return f !== facet;
|
|
6645
6601
|
})
|
|
6646
6602
|
});
|
|
@@ -6650,15 +6606,14 @@
|
|
|
6650
6606
|
* helper configuration, if it is present.
|
|
6651
6607
|
* @method
|
|
6652
6608
|
* @param {string} facet hierarchical facet name to remove
|
|
6653
|
-
* @return {SearchParameters}
|
|
6609
|
+
* @return {SearchParameters} new instance
|
|
6654
6610
|
*/
|
|
6655
6611
|
removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
|
|
6656
6612
|
if (!this.isHierarchicalFacet(facet)) {
|
|
6657
6613
|
return this;
|
|
6658
6614
|
}
|
|
6659
|
-
|
|
6660
6615
|
return this.clearRefinements(facet).setQueryParameters({
|
|
6661
|
-
hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
|
|
6616
|
+
hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
|
|
6662
6617
|
return f.name !== facet;
|
|
6663
6618
|
})
|
|
6664
6619
|
});
|
|
@@ -6670,14 +6625,13 @@
|
|
|
6670
6625
|
* @method
|
|
6671
6626
|
* @param {string} facet name of the attribute used for faceting
|
|
6672
6627
|
* @param {string} [value] value used to filter
|
|
6673
|
-
* @return {SearchParameters}
|
|
6628
|
+
* @return {SearchParameters} new instance
|
|
6674
6629
|
*/
|
|
6675
6630
|
removeFacetRefinement: function removeFacetRefinement(facet, value) {
|
|
6676
6631
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6677
6632
|
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
|
|
6678
6633
|
}
|
|
6679
6634
|
if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
|
|
6680
|
-
|
|
6681
6635
|
return this.setQueryParameters({
|
|
6682
6636
|
facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
|
|
6683
6637
|
});
|
|
@@ -6687,14 +6641,13 @@
|
|
|
6687
6641
|
* @method
|
|
6688
6642
|
* @param {string} facet name of the attribute used for faceting
|
|
6689
6643
|
* @param {string} value value used to filter
|
|
6690
|
-
* @return {SearchParameters}
|
|
6644
|
+
* @return {SearchParameters} new instance
|
|
6691
6645
|
*/
|
|
6692
6646
|
removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
|
|
6693
6647
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6694
6648
|
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
|
|
6695
6649
|
}
|
|
6696
6650
|
if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
|
|
6697
|
-
|
|
6698
6651
|
return this.setQueryParameters({
|
|
6699
6652
|
facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
|
|
6700
6653
|
});
|
|
@@ -6704,35 +6657,30 @@
|
|
|
6704
6657
|
* @method
|
|
6705
6658
|
* @param {string} facet name of the attribute used for faceting
|
|
6706
6659
|
* @param {string} value value used to filter
|
|
6707
|
-
* @return {SearchParameters}
|
|
6660
|
+
* @return {SearchParameters} new instance
|
|
6708
6661
|
*/
|
|
6709
6662
|
removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
|
|
6710
6663
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
6711
|
-
throw new Error(
|
|
6712
|
-
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
|
|
6664
|
+
throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
|
|
6713
6665
|
}
|
|
6714
6666
|
if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
|
|
6715
|
-
|
|
6716
6667
|
return this.setQueryParameters({
|
|
6717
|
-
disjunctiveFacetsRefinements: RefinementList.removeRefinement(
|
|
6718
|
-
this.disjunctiveFacetsRefinements, facet, value)
|
|
6668
|
+
disjunctiveFacetsRefinements: RefinementList.removeRefinement(this.disjunctiveFacetsRefinements, facet, value)
|
|
6719
6669
|
});
|
|
6720
6670
|
},
|
|
6721
6671
|
/**
|
|
6722
6672
|
* Remove a tag from the list of tag refinements
|
|
6723
6673
|
* @method
|
|
6724
6674
|
* @param {string} tag the tag to remove
|
|
6725
|
-
* @return {SearchParameters}
|
|
6675
|
+
* @return {SearchParameters} new instance
|
|
6726
6676
|
*/
|
|
6727
6677
|
removeTagRefinement: function removeTagRefinement(tag) {
|
|
6728
6678
|
if (!this.isTagRefined(tag)) return this;
|
|
6729
|
-
|
|
6730
6679
|
var modification = {
|
|
6731
|
-
tagRefinements: this.tagRefinements.filter(function(t) {
|
|
6680
|
+
tagRefinements: this.tagRefinements.filter(function (t) {
|
|
6732
6681
|
return t !== tag;
|
|
6733
6682
|
})
|
|
6734
6683
|
};
|
|
6735
|
-
|
|
6736
6684
|
return this.setQueryParameters(modification);
|
|
6737
6685
|
},
|
|
6738
6686
|
/**
|
|
@@ -6740,7 +6688,7 @@
|
|
|
6740
6688
|
* and hierarchical facets
|
|
6741
6689
|
* @param {string} facet the facet to refine
|
|
6742
6690
|
* @param {string} value the associated value
|
|
6743
|
-
* @return {SearchParameters}
|
|
6691
|
+
* @return {SearchParameters} new instance
|
|
6744
6692
|
* @throws will throw an error if the facet is not declared in the settings of the helper
|
|
6745
6693
|
* @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
|
|
6746
6694
|
*/
|
|
@@ -6752,7 +6700,7 @@
|
|
|
6752
6700
|
* and hierarchical facets
|
|
6753
6701
|
* @param {string} facet the facet to refine
|
|
6754
6702
|
* @param {string} value the associated value
|
|
6755
|
-
* @return {SearchParameters}
|
|
6703
|
+
* @return {SearchParameters} new instance
|
|
6756
6704
|
* @throws will throw an error if the facet is not declared in the settings of the helper
|
|
6757
6705
|
*/
|
|
6758
6706
|
toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
|
|
@@ -6763,22 +6711,19 @@
|
|
|
6763
6711
|
} else if (this.isDisjunctiveFacet(facet)) {
|
|
6764
6712
|
return this.toggleDisjunctiveFacetRefinement(facet, value);
|
|
6765
6713
|
}
|
|
6766
|
-
|
|
6767
|
-
throw new Error('Cannot refine the undeclared facet ' + facet +
|
|
6768
|
-
'; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
|
|
6714
|
+
throw new Error('Cannot refine the undeclared facet ' + facet + '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
|
|
6769
6715
|
},
|
|
6770
6716
|
/**
|
|
6771
6717
|
* Switch the refinement applied over a facet/value
|
|
6772
6718
|
* @method
|
|
6773
6719
|
* @param {string} facet name of the attribute used for faceting
|
|
6774
6720
|
* @param {value} value value used for filtering
|
|
6775
|
-
* @return {SearchParameters}
|
|
6721
|
+
* @return {SearchParameters} new instance
|
|
6776
6722
|
*/
|
|
6777
6723
|
toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
|
|
6778
6724
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6779
6725
|
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
|
|
6780
6726
|
}
|
|
6781
|
-
|
|
6782
6727
|
return this.setQueryParameters({
|
|
6783
6728
|
facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
|
|
6784
6729
|
});
|
|
@@ -6788,13 +6733,12 @@
|
|
|
6788
6733
|
* @method
|
|
6789
6734
|
* @param {string} facet name of the attribute used for faceting
|
|
6790
6735
|
* @param {value} value value used for filtering
|
|
6791
|
-
* @return {SearchParameters}
|
|
6736
|
+
* @return {SearchParameters} new instance
|
|
6792
6737
|
*/
|
|
6793
6738
|
toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
|
|
6794
6739
|
if (!this.isConjunctiveFacet(facet)) {
|
|
6795
6740
|
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
|
|
6796
6741
|
}
|
|
6797
|
-
|
|
6798
6742
|
return this.setQueryParameters({
|
|
6799
6743
|
facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
|
|
6800
6744
|
});
|
|
@@ -6804,17 +6748,14 @@
|
|
|
6804
6748
|
* @method
|
|
6805
6749
|
* @param {string} facet name of the attribute used for faceting
|
|
6806
6750
|
* @param {value} value value used for filtering
|
|
6807
|
-
* @return {SearchParameters}
|
|
6751
|
+
* @return {SearchParameters} new instance
|
|
6808
6752
|
*/
|
|
6809
6753
|
toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
|
|
6810
6754
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
6811
|
-
throw new Error(
|
|
6812
|
-
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
|
|
6755
|
+
throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
|
|
6813
6756
|
}
|
|
6814
|
-
|
|
6815
6757
|
return this.setQueryParameters({
|
|
6816
|
-
disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
|
|
6817
|
-
this.disjunctiveFacetsRefinements, facet, value)
|
|
6758
|
+
disjunctiveFacetsRefinements: RefinementList.toggleRefinement(this.disjunctiveFacetsRefinements, facet, value)
|
|
6818
6759
|
});
|
|
6819
6760
|
},
|
|
6820
6761
|
/**
|
|
@@ -6822,30 +6763,23 @@
|
|
|
6822
6763
|
* @method
|
|
6823
6764
|
* @param {string} facet name of the attribute used for faceting
|
|
6824
6765
|
* @param {value} value value used for filtering
|
|
6825
|
-
* @return {SearchParameters}
|
|
6766
|
+
* @return {SearchParameters} new instance
|
|
6826
6767
|
*/
|
|
6827
6768
|
toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
|
|
6828
6769
|
if (!this.isHierarchicalFacet(facet)) {
|
|
6829
|
-
throw new Error(
|
|
6830
|
-
facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
|
|
6770
|
+
throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
|
|
6831
6771
|
}
|
|
6832
|
-
|
|
6833
6772
|
var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
|
|
6834
|
-
|
|
6835
6773
|
var mod = {};
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
// - refinement should be `beer`
|
|
6846
|
-
this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
|
|
6847
|
-
);
|
|
6848
|
-
|
|
6774
|
+
var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined && this.hierarchicalFacetsRefinements[facet].length > 0 && (
|
|
6775
|
+
// remove current refinement:
|
|
6776
|
+
// refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
|
|
6777
|
+
this.hierarchicalFacetsRefinements[facet][0] === value ||
|
|
6778
|
+
// remove a parent refinement of the current refinement:
|
|
6779
|
+
// - refinement was 'beer > IPA > Flying dog'
|
|
6780
|
+
// - call is toggleRefine('beer > IPA')
|
|
6781
|
+
// - refinement should be `beer`
|
|
6782
|
+
this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0);
|
|
6849
6783
|
if (upOneOrMultipleLevel) {
|
|
6850
6784
|
if (value.indexOf(separator) === -1) {
|
|
6851
6785
|
// go back to root level
|
|
@@ -6856,12 +6790,10 @@
|
|
|
6856
6790
|
} else {
|
|
6857
6791
|
mod[facet] = [value];
|
|
6858
6792
|
}
|
|
6859
|
-
|
|
6860
6793
|
return this.setQueryParameters({
|
|
6861
6794
|
hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
|
|
6862
6795
|
});
|
|
6863
6796
|
},
|
|
6864
|
-
|
|
6865
6797
|
/**
|
|
6866
6798
|
* Adds a refinement on a hierarchical facet.
|
|
6867
6799
|
* @param {string} facet the facet name
|
|
@@ -6869,7 +6801,7 @@
|
|
|
6869
6801
|
* @return {SearchParameter} the new state
|
|
6870
6802
|
* @throws Error if the facet is not defined or if the facet is refined
|
|
6871
6803
|
*/
|
|
6872
|
-
addHierarchicalFacetRefinement: function(facet, path) {
|
|
6804
|
+
addHierarchicalFacetRefinement: function addHierarchicalFacetRefinement(facet, path) {
|
|
6873
6805
|
if (this.isHierarchicalFacetRefined(facet)) {
|
|
6874
6806
|
throw new Error(facet + ' is already refined.');
|
|
6875
6807
|
}
|
|
@@ -6882,14 +6814,13 @@
|
|
|
6882
6814
|
hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
|
|
6883
6815
|
});
|
|
6884
6816
|
},
|
|
6885
|
-
|
|
6886
6817
|
/**
|
|
6887
6818
|
* Removes the refinement set on a hierarchical facet.
|
|
6888
6819
|
* @param {string} facet the facet name
|
|
6889
6820
|
* @return {SearchParameter} the new state
|
|
6890
6821
|
* @throws Error if the facet is not defined or if the facet is not refined
|
|
6891
6822
|
*/
|
|
6892
|
-
removeHierarchicalFacetRefinement: function(facet) {
|
|
6823
|
+
removeHierarchicalFacetRefinement: function removeHierarchicalFacetRefinement(facet) {
|
|
6893
6824
|
if (!this.isHierarchicalFacetRefined(facet)) {
|
|
6894
6825
|
return this;
|
|
6895
6826
|
}
|
|
@@ -6903,40 +6834,39 @@
|
|
|
6903
6834
|
* Switch the tag refinement
|
|
6904
6835
|
* @method
|
|
6905
6836
|
* @param {string} tag the tag to remove or add
|
|
6906
|
-
* @return {SearchParameters}
|
|
6837
|
+
* @return {SearchParameters} new instance
|
|
6907
6838
|
*/
|
|
6908
6839
|
toggleTagRefinement: function toggleTagRefinement(tag) {
|
|
6909
6840
|
if (this.isTagRefined(tag)) {
|
|
6910
6841
|
return this.removeTagRefinement(tag);
|
|
6911
6842
|
}
|
|
6912
|
-
|
|
6913
6843
|
return this.addTagRefinement(tag);
|
|
6914
6844
|
},
|
|
6915
6845
|
/**
|
|
6916
6846
|
* Test if the facet name is from one of the disjunctive facets
|
|
6917
6847
|
* @method
|
|
6918
6848
|
* @param {string} facet facet name to test
|
|
6919
|
-
* @return {boolean}
|
|
6849
|
+
* @return {boolean} true if facet is a disjunctive facet
|
|
6920
6850
|
*/
|
|
6921
|
-
isDisjunctiveFacet: function(facet) {
|
|
6851
|
+
isDisjunctiveFacet: function isDisjunctiveFacet(facet) {
|
|
6922
6852
|
return this.disjunctiveFacets.indexOf(facet) > -1;
|
|
6923
6853
|
},
|
|
6924
6854
|
/**
|
|
6925
6855
|
* Test if the facet name is from one of the hierarchical facets
|
|
6926
6856
|
* @method
|
|
6927
6857
|
* @param {string} facetName facet name to test
|
|
6928
|
-
* @return {boolean}
|
|
6858
|
+
* @return {boolean} true if facetName is a hierarchical facet
|
|
6929
6859
|
*/
|
|
6930
|
-
isHierarchicalFacet: function(facetName) {
|
|
6860
|
+
isHierarchicalFacet: function isHierarchicalFacet(facetName) {
|
|
6931
6861
|
return this.getHierarchicalFacetByName(facetName) !== undefined;
|
|
6932
6862
|
},
|
|
6933
6863
|
/**
|
|
6934
6864
|
* Test if the facet name is from one of the conjunctive/normal facets
|
|
6935
6865
|
* @method
|
|
6936
6866
|
* @param {string} facet facet name to test
|
|
6937
|
-
* @return {boolean}
|
|
6867
|
+
* @return {boolean} true if facet is a conjunctive facet
|
|
6938
6868
|
*/
|
|
6939
|
-
isConjunctiveFacet: function(facet) {
|
|
6869
|
+
isConjunctiveFacet: function isConjunctiveFacet(facet) {
|
|
6940
6870
|
return this.facets.indexOf(facet) > -1;
|
|
6941
6871
|
},
|
|
6942
6872
|
/**
|
|
@@ -6977,7 +6907,7 @@
|
|
|
6977
6907
|
* @param {string} facet name of the attribute for used for faceting
|
|
6978
6908
|
* @param {string} value optional, will test if the value is used for refinement
|
|
6979
6909
|
* if there is one, otherwise will test if the facet contains any refinement
|
|
6980
|
-
* @return {boolean}
|
|
6910
|
+
* @return {boolean} true if the facet is refined
|
|
6981
6911
|
*/
|
|
6982
6912
|
isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
|
|
6983
6913
|
if (!this.isDisjunctiveFacet(facet)) {
|
|
@@ -6992,19 +6922,16 @@
|
|
|
6992
6922
|
* @param {string} facet name of the attribute for used for faceting
|
|
6993
6923
|
* @param {string} value optional, will test if the value is used for refinement
|
|
6994
6924
|
* if there is one, otherwise will test if the facet contains any refinement
|
|
6995
|
-
* @return {boolean}
|
|
6925
|
+
* @return {boolean} true if the facet is refined
|
|
6996
6926
|
*/
|
|
6997
6927
|
isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
|
|
6998
6928
|
if (!this.isHierarchicalFacet(facet)) {
|
|
6999
6929
|
return false;
|
|
7000
6930
|
}
|
|
7001
|
-
|
|
7002
6931
|
var refinements = this.getHierarchicalRefinement(facet);
|
|
7003
|
-
|
|
7004
6932
|
if (!value) {
|
|
7005
6933
|
return refinements.length > 0;
|
|
7006
6934
|
}
|
|
7007
|
-
|
|
7008
6935
|
return refinements.indexOf(value) !== -1;
|
|
7009
6936
|
},
|
|
7010
6937
|
/**
|
|
@@ -7019,29 +6946,21 @@
|
|
|
7019
6946
|
*/
|
|
7020
6947
|
isNumericRefined: function isNumericRefined(attribute, operator, value) {
|
|
7021
6948
|
if (value === undefined && operator === undefined) {
|
|
7022
|
-
return
|
|
6949
|
+
return Boolean(this.numericRefinements[attribute]);
|
|
7023
6950
|
}
|
|
7024
|
-
|
|
7025
|
-
var isOperatorDefined =
|
|
7026
|
-
this.numericRefinements[attribute] &&
|
|
7027
|
-
this.numericRefinements[attribute][operator] !== undefined;
|
|
7028
|
-
|
|
6951
|
+
var isOperatorDefined = this.numericRefinements[attribute] && this.numericRefinements[attribute][operator] !== undefined;
|
|
7029
6952
|
if (value === undefined || !isOperatorDefined) {
|
|
7030
6953
|
return isOperatorDefined;
|
|
7031
6954
|
}
|
|
7032
|
-
|
|
7033
6955
|
var parsedValue = valToNumber_1(value);
|
|
7034
|
-
var isAttributeValueDefined =
|
|
7035
|
-
findArray(this.numericRefinements[attribute][operator], parsedValue) !==
|
|
7036
|
-
undefined;
|
|
7037
|
-
|
|
6956
|
+
var isAttributeValueDefined = findArray(this.numericRefinements[attribute][operator], parsedValue) !== undefined;
|
|
7038
6957
|
return isOperatorDefined && isAttributeValueDefined;
|
|
7039
6958
|
},
|
|
7040
6959
|
/**
|
|
7041
6960
|
* Returns true if the tag refined, false otherwise
|
|
7042
6961
|
* @method
|
|
7043
6962
|
* @param {string} tag the tag to check
|
|
7044
|
-
* @return {boolean}
|
|
6963
|
+
* @return {boolean} true if tag is refined
|
|
7045
6964
|
*/
|
|
7046
6965
|
isTagRefined: function isTagRefined(tag) {
|
|
7047
6966
|
return this.tagRefinements.indexOf(tag) !== -1;
|
|
@@ -7051,83 +6970,63 @@
|
|
|
7051
6970
|
* @method
|
|
7052
6971
|
* @param {string} facet name of the attribute used for faceting
|
|
7053
6972
|
* @param {value} value value used for filtering
|
|
7054
|
-
* @return {string[]}
|
|
6973
|
+
* @return {string[]} returns the list of refinements
|
|
7055
6974
|
*/
|
|
7056
6975
|
getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
|
|
6976
|
+
// eslint-disable-next-line consistent-this
|
|
7057
6977
|
var self = this;
|
|
7058
6978
|
|
|
7059
6979
|
// attributes used for numeric filter can also be disjunctive
|
|
7060
|
-
var disjunctiveNumericRefinedFacets = intersection_1(
|
|
7061
|
-
Object.keys(
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
this.disjunctiveFacets
|
|
7065
|
-
);
|
|
7066
|
-
|
|
7067
|
-
return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
|
|
6980
|
+
var disjunctiveNumericRefinedFacets = intersection_1(Object.keys(this.numericRefinements).filter(function (facet) {
|
|
6981
|
+
return Object.keys(self.numericRefinements[facet]).length > 0;
|
|
6982
|
+
}), this.disjunctiveFacets);
|
|
6983
|
+
return Object.keys(this.disjunctiveFacetsRefinements).filter(function (facet) {
|
|
7068
6984
|
return self.disjunctiveFacetsRefinements[facet].length > 0;
|
|
7069
|
-
})
|
|
7070
|
-
.concat(disjunctiveNumericRefinedFacets)
|
|
7071
|
-
.concat(this.getRefinedHierarchicalFacets());
|
|
6985
|
+
}).concat(disjunctiveNumericRefinedFacets).concat(this.getRefinedHierarchicalFacets());
|
|
7072
6986
|
},
|
|
7073
6987
|
/**
|
|
7074
6988
|
* Returns the list of all disjunctive facets refined
|
|
7075
6989
|
* @method
|
|
7076
6990
|
* @param {string} facet name of the attribute used for faceting
|
|
7077
6991
|
* @param {value} value value used for filtering
|
|
7078
|
-
* @return {string[]}
|
|
6992
|
+
* @return {string[]} returns the list of refinements
|
|
7079
6993
|
*/
|
|
7080
6994
|
getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
|
|
6995
|
+
// eslint-disable-next-line consistent-this
|
|
7081
6996
|
var self = this;
|
|
7082
6997
|
return intersection_1(
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
);
|
|
6998
|
+
// enforce the order between the two arrays,
|
|
6999
|
+
// so that refinement name index === hierarchical facet index
|
|
7000
|
+
this.hierarchicalFacets.map(function (facet) {
|
|
7001
|
+
return facet.name;
|
|
7002
|
+
}), Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
|
|
7003
|
+
return self.hierarchicalFacetsRefinements[facet].length > 0;
|
|
7004
|
+
}));
|
|
7090
7005
|
},
|
|
7091
7006
|
/**
|
|
7092
7007
|
* Returned the list of all disjunctive facets not refined
|
|
7093
7008
|
* @method
|
|
7094
|
-
* @return {string[]}
|
|
7009
|
+
* @return {string[]} returns the list of facets that are not refined
|
|
7095
7010
|
*/
|
|
7096
|
-
getUnrefinedDisjunctiveFacets: function() {
|
|
7011
|
+
getUnrefinedDisjunctiveFacets: function getUnrefinedDisjunctiveFacets() {
|
|
7097
7012
|
var refinedFacets = this.getRefinedDisjunctiveFacets();
|
|
7098
|
-
|
|
7099
|
-
return this.disjunctiveFacets.filter(function(f) {
|
|
7013
|
+
return this.disjunctiveFacets.filter(function (f) {
|
|
7100
7014
|
return refinedFacets.indexOf(f) === -1;
|
|
7101
7015
|
});
|
|
7102
7016
|
},
|
|
7103
|
-
|
|
7104
|
-
managedParameters: [
|
|
7105
|
-
'index',
|
|
7106
|
-
|
|
7107
|
-
'facets',
|
|
7108
|
-
'disjunctiveFacets',
|
|
7109
|
-
'facetsRefinements',
|
|
7110
|
-
'hierarchicalFacets',
|
|
7111
|
-
'facetsExcludes',
|
|
7112
|
-
|
|
7113
|
-
'disjunctiveFacetsRefinements',
|
|
7114
|
-
'numericRefinements',
|
|
7115
|
-
'tagRefinements',
|
|
7116
|
-
'hierarchicalFacetsRefinements'
|
|
7117
|
-
],
|
|
7017
|
+
managedParameters: ['index', 'facets', 'disjunctiveFacets', 'facetsRefinements', 'hierarchicalFacets', 'facetsExcludes', 'disjunctiveFacetsRefinements', 'numericRefinements', 'tagRefinements', 'hierarchicalFacetsRefinements'],
|
|
7118
7018
|
getQueryParams: function getQueryParams() {
|
|
7119
7019
|
var managedParameters = this.managedParameters;
|
|
7120
|
-
|
|
7121
7020
|
var queryParams = {};
|
|
7122
7021
|
|
|
7022
|
+
// eslint-disable-next-line consistent-this
|
|
7123
7023
|
var self = this;
|
|
7124
|
-
Object.keys(this).forEach(function(paramName) {
|
|
7024
|
+
Object.keys(this).forEach(function (paramName) {
|
|
7125
7025
|
var paramValue = self[paramName];
|
|
7126
7026
|
if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
|
|
7127
7027
|
queryParams[paramName] = paramValue;
|
|
7128
7028
|
}
|
|
7129
7029
|
});
|
|
7130
|
-
|
|
7131
7030
|
return queryParams;
|
|
7132
7031
|
},
|
|
7133
7032
|
/**
|
|
@@ -7142,11 +7041,8 @@
|
|
|
7142
7041
|
*/
|
|
7143
7042
|
setQueryParameter: function setParameter(parameter, value) {
|
|
7144
7043
|
if (this[parameter] === value) return this;
|
|
7145
|
-
|
|
7146
7044
|
var modification = {};
|
|
7147
|
-
|
|
7148
7045
|
modification[parameter] = value;
|
|
7149
|
-
|
|
7150
7046
|
return this.setQueryParameters(modification);
|
|
7151
7047
|
},
|
|
7152
7048
|
/**
|
|
@@ -7157,134 +7053,109 @@
|
|
|
7157
7053
|
*/
|
|
7158
7054
|
setQueryParameters: function setQueryParameters(params) {
|
|
7159
7055
|
if (!params) return this;
|
|
7160
|
-
|
|
7161
7056
|
var error = SearchParameters.validate(this, params);
|
|
7162
|
-
|
|
7163
7057
|
if (error) {
|
|
7164
7058
|
throw error;
|
|
7165
7059
|
}
|
|
7166
7060
|
|
|
7061
|
+
// eslint-disable-next-line consistent-this
|
|
7167
7062
|
var self = this;
|
|
7168
7063
|
var nextWithNumbers = SearchParameters._parseNumbers(params);
|
|
7169
|
-
var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
|
|
7064
|
+
var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
|
|
7170
7065
|
acc[key] = self[key];
|
|
7171
7066
|
return acc;
|
|
7172
7067
|
}, {});
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
previous[key] = nextWithNumbers[key];
|
|
7185
|
-
}
|
|
7186
|
-
|
|
7187
|
-
return previous;
|
|
7188
|
-
},
|
|
7189
|
-
previousPlainObject
|
|
7190
|
-
);
|
|
7191
|
-
|
|
7068
|
+
var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (previous, key) {
|
|
7069
|
+
var isPreviousValueDefined = previous[key] !== undefined;
|
|
7070
|
+
var isNextValueDefined = nextWithNumbers[key] !== undefined;
|
|
7071
|
+
if (isPreviousValueDefined && !isNextValueDefined) {
|
|
7072
|
+
return omit$1(previous, [key]);
|
|
7073
|
+
}
|
|
7074
|
+
if (isNextValueDefined) {
|
|
7075
|
+
previous[key] = nextWithNumbers[key];
|
|
7076
|
+
}
|
|
7077
|
+
return previous;
|
|
7078
|
+
}, previousPlainObject);
|
|
7192
7079
|
return new this.constructor(nextPlainObject);
|
|
7193
7080
|
},
|
|
7194
|
-
|
|
7195
7081
|
/**
|
|
7196
7082
|
* Returns a new instance with the page reset. Two scenarios possible:
|
|
7197
7083
|
* the page is omitted -> return the given instance
|
|
7198
7084
|
* the page is set -> return a new instance with a page of 0
|
|
7199
7085
|
* @return {SearchParameters} a new updated instance
|
|
7200
7086
|
*/
|
|
7201
|
-
resetPage: function() {
|
|
7087
|
+
resetPage: function resetPage() {
|
|
7202
7088
|
if (this.page === undefined) {
|
|
7203
7089
|
return this;
|
|
7204
7090
|
}
|
|
7205
|
-
|
|
7206
7091
|
return this.setPage(0);
|
|
7207
7092
|
},
|
|
7208
|
-
|
|
7209
7093
|
/**
|
|
7210
7094
|
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
|
|
7211
|
-
* @param {object} hierarchicalFacet
|
|
7095
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
7212
7096
|
* @return {string} returns the hierarchicalFacet.separator or `>` as default
|
|
7213
7097
|
*/
|
|
7214
|
-
_getHierarchicalFacetSortBy: function(hierarchicalFacet) {
|
|
7098
|
+
_getHierarchicalFacetSortBy: function _getHierarchicalFacetSortBy(hierarchicalFacet) {
|
|
7215
7099
|
return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
|
|
7216
7100
|
},
|
|
7217
|
-
|
|
7218
7101
|
/**
|
|
7219
7102
|
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
|
|
7220
7103
|
* @private
|
|
7221
|
-
* @param {object} hierarchicalFacet
|
|
7104
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
7222
7105
|
* @return {string} returns the hierarchicalFacet.separator or `>` as default
|
|
7223
7106
|
*/
|
|
7224
|
-
_getHierarchicalFacetSeparator: function(hierarchicalFacet) {
|
|
7107
|
+
_getHierarchicalFacetSeparator: function _getHierarchicalFacetSeparator(hierarchicalFacet) {
|
|
7225
7108
|
return hierarchicalFacet.separator || ' > ';
|
|
7226
7109
|
},
|
|
7227
|
-
|
|
7228
7110
|
/**
|
|
7229
7111
|
* Helper function to get the hierarchicalFacet prefix path or null
|
|
7230
7112
|
* @private
|
|
7231
|
-
* @param {object} hierarchicalFacet
|
|
7113
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
7232
7114
|
* @return {string} returns the hierarchicalFacet.rootPath or null as default
|
|
7233
7115
|
*/
|
|
7234
|
-
_getHierarchicalRootPath: function(hierarchicalFacet) {
|
|
7116
|
+
_getHierarchicalRootPath: function _getHierarchicalRootPath(hierarchicalFacet) {
|
|
7235
7117
|
return hierarchicalFacet.rootPath || null;
|
|
7236
7118
|
},
|
|
7237
|
-
|
|
7238
7119
|
/**
|
|
7239
7120
|
* Helper function to check if we show the parent level of the hierarchicalFacet
|
|
7240
7121
|
* @private
|
|
7241
|
-
* @param {object} hierarchicalFacet
|
|
7122
|
+
* @param {object} hierarchicalFacet the hierarchicalFacet object
|
|
7242
7123
|
* @return {string} returns the hierarchicalFacet.showParentLevel or true as default
|
|
7243
7124
|
*/
|
|
7244
|
-
_getHierarchicalShowParentLevel: function(hierarchicalFacet) {
|
|
7125
|
+
_getHierarchicalShowParentLevel: function _getHierarchicalShowParentLevel(hierarchicalFacet) {
|
|
7245
7126
|
if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
|
|
7246
7127
|
return hierarchicalFacet.showParentLevel;
|
|
7247
7128
|
}
|
|
7248
7129
|
return true;
|
|
7249
7130
|
},
|
|
7250
|
-
|
|
7251
7131
|
/**
|
|
7252
7132
|
* Helper function to get the hierarchicalFacet by it's name
|
|
7253
|
-
* @param {string} hierarchicalFacetName
|
|
7133
|
+
* @param {string} hierarchicalFacetName the hierarchicalFacet name
|
|
7254
7134
|
* @return {object} a hierarchicalFacet
|
|
7255
7135
|
*/
|
|
7256
|
-
getHierarchicalFacetByName: function(hierarchicalFacetName) {
|
|
7257
|
-
return find$1(
|
|
7258
|
-
|
|
7259
|
-
|
|
7260
|
-
return f.name === hierarchicalFacetName;
|
|
7261
|
-
}
|
|
7262
|
-
);
|
|
7136
|
+
getHierarchicalFacetByName: function getHierarchicalFacetByName(hierarchicalFacetName) {
|
|
7137
|
+
return find$1(this.hierarchicalFacets, function (f) {
|
|
7138
|
+
return f.name === hierarchicalFacetName;
|
|
7139
|
+
});
|
|
7263
7140
|
},
|
|
7264
|
-
|
|
7265
7141
|
/**
|
|
7266
7142
|
* Get the current breadcrumb for a hierarchical facet, as an array
|
|
7267
7143
|
* @param {string} facetName Hierarchical facet name
|
|
7268
7144
|
* @return {array.<string>} the path as an array of string
|
|
7269
7145
|
*/
|
|
7270
|
-
getHierarchicalFacetBreadcrumb: function(facetName) {
|
|
7146
|
+
getHierarchicalFacetBreadcrumb: function getHierarchicalFacetBreadcrumb(facetName) {
|
|
7271
7147
|
if (!this.isHierarchicalFacet(facetName)) {
|
|
7272
7148
|
return [];
|
|
7273
7149
|
}
|
|
7274
|
-
|
|
7275
7150
|
var refinement = this.getHierarchicalRefinement(facetName)[0];
|
|
7276
7151
|
if (!refinement) return [];
|
|
7277
|
-
|
|
7278
|
-
var separator = this._getHierarchicalFacetSeparator(
|
|
7279
|
-
this.getHierarchicalFacetByName(facetName)
|
|
7280
|
-
);
|
|
7152
|
+
var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facetName));
|
|
7281
7153
|
var path = refinement.split(separator);
|
|
7282
|
-
return path.map(function(part) {
|
|
7154
|
+
return path.map(function (part) {
|
|
7283
7155
|
return part.trim();
|
|
7284
7156
|
});
|
|
7285
7157
|
},
|
|
7286
|
-
|
|
7287
|
-
toString: function() {
|
|
7158
|
+
toString: function toString() {
|
|
7288
7159
|
return JSON.stringify(this, null, 2);
|
|
7289
7160
|
}
|
|
7290
7161
|
};
|
|
@@ -7304,22 +7175,12 @@
|
|
|
7304
7175
|
if (value !== other) {
|
|
7305
7176
|
var valIsDefined = value !== undefined;
|
|
7306
7177
|
var valIsNull = value === null;
|
|
7307
|
-
|
|
7308
7178
|
var othIsDefined = other !== undefined;
|
|
7309
7179
|
var othIsNull = other === null;
|
|
7310
|
-
|
|
7311
|
-
if (
|
|
7312
|
-
(!othIsNull && value > other) ||
|
|
7313
|
-
(valIsNull && othIsDefined) ||
|
|
7314
|
-
!valIsDefined
|
|
7315
|
-
) {
|
|
7180
|
+
if (!othIsNull && value > other || valIsNull && othIsDefined || !valIsDefined) {
|
|
7316
7181
|
return 1;
|
|
7317
7182
|
}
|
|
7318
|
-
if (
|
|
7319
|
-
(!valIsNull && value < other) ||
|
|
7320
|
-
(othIsNull && valIsDefined) ||
|
|
7321
|
-
!othIsDefined
|
|
7322
|
-
) {
|
|
7183
|
+
if (!valIsNull && value < other || othIsNull && valIsDefined || !othIsDefined) {
|
|
7323
7184
|
return -1;
|
|
7324
7185
|
}
|
|
7325
7186
|
}
|
|
@@ -7330,29 +7191,26 @@
|
|
|
7330
7191
|
* @param {Array<object>} collection object with keys in attributes
|
|
7331
7192
|
* @param {Array<string>} iteratees attributes
|
|
7332
7193
|
* @param {Array<string>} orders asc | desc
|
|
7194
|
+
* @return {Array<object>} sorted collection
|
|
7333
7195
|
*/
|
|
7334
7196
|
function orderBy(collection, iteratees, orders) {
|
|
7335
7197
|
if (!Array.isArray(collection)) {
|
|
7336
7198
|
return [];
|
|
7337
7199
|
}
|
|
7338
|
-
|
|
7339
7200
|
if (!Array.isArray(orders)) {
|
|
7340
7201
|
orders = [];
|
|
7341
7202
|
}
|
|
7342
|
-
|
|
7343
|
-
var result = collection.map(function(value, index) {
|
|
7203
|
+
var result = collection.map(function (value, index) {
|
|
7344
7204
|
return {
|
|
7345
|
-
criteria: iteratees.map(function(iteratee) {
|
|
7205
|
+
criteria: iteratees.map(function (iteratee) {
|
|
7346
7206
|
return value[iteratee];
|
|
7347
7207
|
}),
|
|
7348
7208
|
index: index,
|
|
7349
7209
|
value: value
|
|
7350
7210
|
};
|
|
7351
7211
|
});
|
|
7352
|
-
|
|
7353
7212
|
result.sort(function comparer(object, other) {
|
|
7354
7213
|
var index = -1;
|
|
7355
|
-
|
|
7356
7214
|
while (++index < object.criteria.length) {
|
|
7357
7215
|
var res = compareAscending(object.criteria[index], other.criteria[index]);
|
|
7358
7216
|
if (res) {
|
|
@@ -7370,19 +7228,16 @@
|
|
|
7370
7228
|
// See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
|
|
7371
7229
|
return object.index - other.index;
|
|
7372
7230
|
});
|
|
7373
|
-
|
|
7374
|
-
return result.map(function(res) {
|
|
7231
|
+
return result.map(function (res) {
|
|
7375
7232
|
return res.value;
|
|
7376
7233
|
});
|
|
7377
7234
|
}
|
|
7378
|
-
|
|
7379
7235
|
var orderBy_1 = orderBy;
|
|
7380
7236
|
|
|
7381
7237
|
var compact = function compact(array) {
|
|
7382
7238
|
if (!Array.isArray(array)) {
|
|
7383
7239
|
return [];
|
|
7384
7240
|
}
|
|
7385
|
-
|
|
7386
7241
|
return array.filter(Boolean);
|
|
7387
7242
|
};
|
|
7388
7243
|
|
|
@@ -7391,7 +7246,6 @@
|
|
|
7391
7246
|
if (!Array.isArray(array)) {
|
|
7392
7247
|
return -1;
|
|
7393
7248
|
}
|
|
7394
|
-
|
|
7395
7249
|
for (var i = 0; i < array.length; i++) {
|
|
7396
7250
|
if (comparator(array[i])) {
|
|
7397
7251
|
return i;
|
|
@@ -7407,43 +7261,33 @@
|
|
|
7407
7261
|
* @return {array.<string[]>} array containing 2 elements : attributes, orders
|
|
7408
7262
|
*/
|
|
7409
7263
|
var formatSort = function formatSort(sortBy, defaults) {
|
|
7410
|
-
var defaultInstructions = (defaults || []).map(function(sort) {
|
|
7264
|
+
var defaultInstructions = (defaults || []).map(function (sort) {
|
|
7411
7265
|
return sort.split(':');
|
|
7412
7266
|
});
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
)
|
|
7421
|
-
return defaultInstruction[0] === sortInstruction[0];
|
|
7422
|
-
});
|
|
7423
|
-
|
|
7424
|
-
if (sortInstruction.length > 1 || !matchingDefault) {
|
|
7425
|
-
out[0].push(sortInstruction[0]);
|
|
7426
|
-
out[1].push(sortInstruction[1]);
|
|
7427
|
-
return out;
|
|
7428
|
-
}
|
|
7429
|
-
|
|
7430
|
-
out[0].push(matchingDefault[0]);
|
|
7431
|
-
out[1].push(matchingDefault[1]);
|
|
7267
|
+
return sortBy.reduce(function preparePredicate(out, sort) {
|
|
7268
|
+
var sortInstruction = sort.split(':');
|
|
7269
|
+
var matchingDefault = find$1(defaultInstructions, function (defaultInstruction) {
|
|
7270
|
+
return defaultInstruction[0] === sortInstruction[0];
|
|
7271
|
+
});
|
|
7272
|
+
if (sortInstruction.length > 1 || !matchingDefault) {
|
|
7273
|
+
out[0].push(sortInstruction[0]);
|
|
7274
|
+
out[1].push(sortInstruction[1]);
|
|
7432
7275
|
return out;
|
|
7433
|
-
}
|
|
7434
|
-
[
|
|
7435
|
-
|
|
7276
|
+
}
|
|
7277
|
+
out[0].push(matchingDefault[0]);
|
|
7278
|
+
out[1].push(matchingDefault[1]);
|
|
7279
|
+
return out;
|
|
7280
|
+
}, [[], []]);
|
|
7436
7281
|
};
|
|
7437
7282
|
|
|
7438
7283
|
/**
|
|
7439
7284
|
* Replaces a leading - with \-
|
|
7440
7285
|
* @private
|
|
7441
7286
|
* @param {any} value the facet value to replace
|
|
7442
|
-
* @returns any
|
|
7287
|
+
* @returns {any} the escaped facet value or the value if it was not a string
|
|
7443
7288
|
*/
|
|
7444
7289
|
function escapeFacetValue$1(value) {
|
|
7445
7290
|
if (typeof value !== 'string') return value;
|
|
7446
|
-
|
|
7447
7291
|
return String(value).replace(/^-/, '\\-');
|
|
7448
7292
|
}
|
|
7449
7293
|
|
|
@@ -7451,14 +7295,12 @@
|
|
|
7451
7295
|
* Replaces a leading \- with -
|
|
7452
7296
|
* @private
|
|
7453
7297
|
* @param {any} value the escaped facet value
|
|
7454
|
-
* @returns any
|
|
7298
|
+
* @returns {any} the unescaped facet value or the value if it was not a string
|
|
7455
7299
|
*/
|
|
7456
7300
|
function unescapeFacetValue$1(value) {
|
|
7457
7301
|
if (typeof value !== 'string') return value;
|
|
7458
|
-
|
|
7459
7302
|
return value.replace(/^\\-/, '-');
|
|
7460
7303
|
}
|
|
7461
|
-
|
|
7462
7304
|
var escapeFacetValue_1 = {
|
|
7463
7305
|
escapeFacetValue: escapeFacetValue$1,
|
|
7464
7306
|
unescapeFacetValue: unescapeFacetValue$1
|
|
@@ -7469,87 +7311,50 @@
|
|
|
7469
7311
|
|
|
7470
7312
|
|
|
7471
7313
|
|
|
7472
|
-
|
|
7473
7314
|
var escapeFacetValue$2 = escapeFacetValue_1.escapeFacetValue;
|
|
7474
7315
|
var unescapeFacetValue$2 = escapeFacetValue_1.unescapeFacetValue;
|
|
7475
|
-
|
|
7476
7316
|
function generateTrees(state) {
|
|
7477
7317
|
return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
|
|
7478
7318
|
var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
|
|
7479
|
-
var hierarchicalFacetRefinement =
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
var
|
|
7484
|
-
|
|
7485
|
-
);
|
|
7486
|
-
var hierarchicalRootPath = state._getHierarchicalRootPath(
|
|
7487
|
-
hierarchicalFacet
|
|
7488
|
-
);
|
|
7489
|
-
var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
|
|
7490
|
-
hierarchicalFacet
|
|
7491
|
-
);
|
|
7492
|
-
var sortBy = formatSort(
|
|
7493
|
-
state._getHierarchicalFacetSortBy(hierarchicalFacet)
|
|
7494
|
-
);
|
|
7495
|
-
|
|
7496
|
-
var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
|
|
7319
|
+
var hierarchicalFacetRefinement = state.hierarchicalFacetsRefinements[hierarchicalFacet.name] && state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0] || '';
|
|
7320
|
+
var hierarchicalSeparator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
7321
|
+
var hierarchicalRootPath = state._getHierarchicalRootPath(hierarchicalFacet);
|
|
7322
|
+
var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(hierarchicalFacet);
|
|
7323
|
+
var sortBy = formatSort(state._getHierarchicalFacetSortBy(hierarchicalFacet));
|
|
7324
|
+
var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
|
|
7497
7325
|
return facetResult.exhaustive;
|
|
7498
7326
|
});
|
|
7499
|
-
|
|
7500
|
-
var generateTreeFn = generateHierarchicalTree(
|
|
7501
|
-
sortBy,
|
|
7502
|
-
hierarchicalSeparator,
|
|
7503
|
-
hierarchicalRootPath,
|
|
7504
|
-
hierarchicalShowParentLevel,
|
|
7505
|
-
hierarchicalFacetRefinement
|
|
7506
|
-
);
|
|
7507
|
-
|
|
7327
|
+
var generateTreeFn = generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, hierarchicalFacetRefinement);
|
|
7508
7328
|
var results = hierarchicalFacetResult;
|
|
7509
|
-
|
|
7510
7329
|
if (hierarchicalRootPath) {
|
|
7511
|
-
results = hierarchicalFacetResult.slice(
|
|
7512
|
-
hierarchicalRootPath.split(hierarchicalSeparator).length
|
|
7513
|
-
);
|
|
7330
|
+
results = hierarchicalFacetResult.slice(hierarchicalRootPath.split(hierarchicalSeparator).length);
|
|
7514
7331
|
}
|
|
7515
|
-
|
|
7516
7332
|
return results.reduce(generateTreeFn, {
|
|
7517
7333
|
name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
|
|
7518
|
-
count: null,
|
|
7519
|
-
|
|
7520
|
-
|
|
7334
|
+
count: null,
|
|
7335
|
+
// root level, no count
|
|
7336
|
+
isRefined: true,
|
|
7337
|
+
// root level, always refined
|
|
7338
|
+
path: null,
|
|
7339
|
+
// root level, no path
|
|
7521
7340
|
escapedValue: null,
|
|
7522
7341
|
exhaustive: rootExhaustive,
|
|
7523
7342
|
data: null
|
|
7524
7343
|
});
|
|
7525
7344
|
};
|
|
7526
7345
|
}
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
sortBy,
|
|
7530
|
-
hierarchicalSeparator,
|
|
7531
|
-
hierarchicalRootPath,
|
|
7532
|
-
hierarchicalShowParentLevel,
|
|
7533
|
-
currentRefinement
|
|
7534
|
-
) {
|
|
7535
|
-
return function generateTree(
|
|
7536
|
-
hierarchicalTree,
|
|
7537
|
-
hierarchicalFacetResult,
|
|
7538
|
-
currentHierarchicalLevel
|
|
7539
|
-
) {
|
|
7346
|
+
function generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, currentRefinement) {
|
|
7347
|
+
return function generateTree(hierarchicalTree, hierarchicalFacetResult, currentHierarchicalLevel) {
|
|
7540
7348
|
var parent = hierarchicalTree;
|
|
7541
|
-
|
|
7542
7349
|
if (currentHierarchicalLevel > 0) {
|
|
7543
7350
|
var level = 0;
|
|
7544
|
-
|
|
7545
7351
|
parent = hierarchicalTree;
|
|
7546
|
-
|
|
7547
7352
|
while (level < currentHierarchicalLevel) {
|
|
7548
7353
|
/**
|
|
7549
7354
|
* @type {object[]]} hierarchical data
|
|
7550
7355
|
*/
|
|
7551
7356
|
var data = parent && Array.isArray(parent.data) ? parent.data : [];
|
|
7552
|
-
parent = find$1(data, function(subtree) {
|
|
7357
|
+
parent = find$1(data, function (subtree) {
|
|
7553
7358
|
return subtree.isRefined;
|
|
7554
7359
|
});
|
|
7555
7360
|
level++;
|
|
@@ -7569,99 +7374,49 @@
|
|
|
7569
7374
|
// If parent refinement is `beers`, then we do not want to have `bières > Belges`
|
|
7570
7375
|
// showing up
|
|
7571
7376
|
|
|
7572
|
-
var picked = Object.keys(hierarchicalFacetResult.data)
|
|
7573
|
-
.
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
.
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
hierarchicalRootPath,
|
|
7584
|
-
hierarchicalShowParentLevel
|
|
7585
|
-
);
|
|
7586
|
-
});
|
|
7587
|
-
|
|
7588
|
-
parent.data = orderBy_1(
|
|
7589
|
-
picked.map(function(tuple) {
|
|
7590
|
-
var facetValue = tuple[0];
|
|
7591
|
-
var facetCount = tuple[1];
|
|
7592
|
-
|
|
7593
|
-
return format(
|
|
7594
|
-
facetCount,
|
|
7595
|
-
facetValue,
|
|
7596
|
-
hierarchicalSeparator,
|
|
7597
|
-
unescapeFacetValue$2(currentRefinement),
|
|
7598
|
-
hierarchicalFacetResult.exhaustive
|
|
7599
|
-
);
|
|
7600
|
-
}),
|
|
7601
|
-
sortBy[0],
|
|
7602
|
-
sortBy[1]
|
|
7603
|
-
);
|
|
7377
|
+
var picked = Object.keys(hierarchicalFacetResult.data).map(function (facetValue) {
|
|
7378
|
+
return [facetValue, hierarchicalFacetResult.data[facetValue]];
|
|
7379
|
+
}).filter(function (tuple) {
|
|
7380
|
+
var facetValue = tuple[0];
|
|
7381
|
+
return onlyMatchingTree(facetValue, parent.path || hierarchicalRootPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel);
|
|
7382
|
+
});
|
|
7383
|
+
parent.data = orderBy_1(picked.map(function (tuple) {
|
|
7384
|
+
var facetValue = tuple[0];
|
|
7385
|
+
var facetCount = tuple[1];
|
|
7386
|
+
return format(facetCount, facetValue, hierarchicalSeparator, unescapeFacetValue$2(currentRefinement), hierarchicalFacetResult.exhaustive);
|
|
7387
|
+
}), sortBy[0], sortBy[1]);
|
|
7604
7388
|
}
|
|
7605
|
-
|
|
7606
7389
|
return hierarchicalTree;
|
|
7607
7390
|
};
|
|
7608
7391
|
}
|
|
7609
7392
|
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
parentPath,
|
|
7613
|
-
currentRefinement,
|
|
7614
|
-
hierarchicalSeparator,
|
|
7615
|
-
hierarchicalRootPath,
|
|
7616
|
-
hierarchicalShowParentLevel
|
|
7617
|
-
) {
|
|
7393
|
+
// eslint-disable-next-line max-params
|
|
7394
|
+
function onlyMatchingTree(facetValue, parentPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel) {
|
|
7618
7395
|
// we want the facetValue is a child of hierarchicalRootPath
|
|
7619
|
-
if (
|
|
7620
|
-
hierarchicalRootPath &&
|
|
7621
|
-
(facetValue.indexOf(hierarchicalRootPath) !== 0 ||
|
|
7622
|
-
hierarchicalRootPath === facetValue)
|
|
7623
|
-
) {
|
|
7396
|
+
if (hierarchicalRootPath && (facetValue.indexOf(hierarchicalRootPath) !== 0 || hierarchicalRootPath === facetValue)) {
|
|
7624
7397
|
return false;
|
|
7625
7398
|
}
|
|
7626
7399
|
|
|
7627
7400
|
// we always want root levels (only when there is no prefix path)
|
|
7628
|
-
return (
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
(facetValue.indexOf(hierarchicalSeparator) === -1 &&
|
|
7639
|
-
currentRefinement.indexOf(hierarchicalSeparator) === -1) ||
|
|
7640
|
-
// currentRefinement is a child of the facet value
|
|
7641
|
-
currentRefinement.indexOf(facetValue) === 0 ||
|
|
7642
|
-
// facetValue is a child of the current parent, add it
|
|
7643
|
-
(facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
|
|
7644
|
-
(hierarchicalShowParentLevel ||
|
|
7645
|
-
facetValue.indexOf(currentRefinement) === 0))
|
|
7646
|
-
);
|
|
7401
|
+
return !hierarchicalRootPath && facetValue.indexOf(hierarchicalSeparator) === -1 ||
|
|
7402
|
+
// if there is a rootPath, being root level mean 1 level under rootPath
|
|
7403
|
+
hierarchicalRootPath && facetValue.split(hierarchicalSeparator).length - hierarchicalRootPath.split(hierarchicalSeparator).length === 1 ||
|
|
7404
|
+
// if current refinement is a root level and current facetValue is a root level,
|
|
7405
|
+
// keep the facetValue
|
|
7406
|
+
facetValue.indexOf(hierarchicalSeparator) === -1 && currentRefinement.indexOf(hierarchicalSeparator) === -1 ||
|
|
7407
|
+
// currentRefinement is a child of the facet value
|
|
7408
|
+
currentRefinement.indexOf(facetValue) === 0 ||
|
|
7409
|
+
// facetValue is a child of the current parent, add it
|
|
7410
|
+
facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 && (hierarchicalShowParentLevel || facetValue.indexOf(currentRefinement) === 0);
|
|
7647
7411
|
}
|
|
7648
|
-
|
|
7649
|
-
function format(
|
|
7650
|
-
facetCount,
|
|
7651
|
-
facetValue,
|
|
7652
|
-
hierarchicalSeparator,
|
|
7653
|
-
currentRefinement,
|
|
7654
|
-
exhaustive
|
|
7655
|
-
) {
|
|
7412
|
+
function format(facetCount, facetValue, hierarchicalSeparator, currentRefinement, exhaustive) {
|
|
7656
7413
|
var parts = facetValue.split(hierarchicalSeparator);
|
|
7657
7414
|
return {
|
|
7658
7415
|
name: parts[parts.length - 1].trim(),
|
|
7659
7416
|
path: facetValue,
|
|
7660
7417
|
escapedValue: escapeFacetValue$2(facetValue),
|
|
7661
7418
|
count: facetCount,
|
|
7662
|
-
isRefined:
|
|
7663
|
-
currentRefinement === facetValue ||
|
|
7664
|
-
currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
|
|
7419
|
+
isRefined: currentRefinement === facetValue || currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
|
|
7665
7420
|
exhaustive: exhaustive,
|
|
7666
7421
|
data: null
|
|
7667
7422
|
};
|
|
@@ -7671,7 +7426,6 @@
|
|
|
7671
7426
|
var unescapeFacetValue$3 = escapeFacetValue_1.unescapeFacetValue;
|
|
7672
7427
|
|
|
7673
7428
|
|
|
7674
|
-
|
|
7675
7429
|
/**
|
|
7676
7430
|
* @typedef SearchResults.Facet
|
|
7677
7431
|
* @type {object}
|
|
@@ -7714,18 +7468,17 @@
|
|
|
7714
7468
|
*/
|
|
7715
7469
|
|
|
7716
7470
|
/**
|
|
7717
|
-
*
|
|
7471
|
+
* Turn an array of attributes in an object of attributes with their position in the array as value
|
|
7472
|
+
* @param {string[]} attributes the list of attributes in the record
|
|
7473
|
+
* @return {object} the list of attributes indexed by attribute name
|
|
7718
7474
|
*/
|
|
7719
7475
|
function getIndices(attributes) {
|
|
7720
7476
|
var indices = {};
|
|
7721
|
-
|
|
7722
|
-
attributes.forEach(function(val, idx) {
|
|
7477
|
+
attributes.forEach(function (val, idx) {
|
|
7723
7478
|
indices[val] = idx;
|
|
7724
7479
|
});
|
|
7725
|
-
|
|
7726
7480
|
return indices;
|
|
7727
7481
|
}
|
|
7728
|
-
|
|
7729
7482
|
function assignFacetStats(dest, facetStats, key) {
|
|
7730
7483
|
if (facetStats && facetStats[key]) {
|
|
7731
7484
|
dest.stats = facetStats[key];
|
|
@@ -7739,22 +7492,18 @@
|
|
|
7739
7492
|
*/
|
|
7740
7493
|
|
|
7741
7494
|
/**
|
|
7742
|
-
* @param {HierarchicalFacet[]} hierarchicalFacets
|
|
7743
|
-
* @param {string} hierarchicalAttributeName
|
|
7495
|
+
* @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
|
|
7496
|
+
* @param {string} hierarchicalAttributeName The name of the hierarchical attribute
|
|
7497
|
+
* @return {HierarchicalFacet} The hierarchical facet matching the attribute name
|
|
7744
7498
|
*/
|
|
7745
|
-
function findMatchingHierarchicalFacetFromAttributeName(
|
|
7746
|
-
hierarchicalFacets,
|
|
7747
|
-
hierarchicalAttributeName
|
|
7748
|
-
) {
|
|
7749
|
-
return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
|
|
7750
|
-
hierarchicalFacet
|
|
7751
|
-
) {
|
|
7499
|
+
function findMatchingHierarchicalFacetFromAttributeName(hierarchicalFacets, hierarchicalAttributeName) {
|
|
7500
|
+
return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(hierarchicalFacet) {
|
|
7752
7501
|
var facetNames = hierarchicalFacet.attributes || [];
|
|
7753
7502
|
return facetNames.indexOf(hierarchicalAttributeName) > -1;
|
|
7754
7503
|
});
|
|
7755
7504
|
}
|
|
7756
7505
|
|
|
7757
|
-
|
|
7506
|
+
// eslint-disable-next-line valid-jsdoc
|
|
7758
7507
|
/**
|
|
7759
7508
|
* Constructor for SearchResults
|
|
7760
7509
|
* @class
|
|
@@ -7885,21 +7634,20 @@
|
|
|
7885
7634
|
"index": "bestbuy"
|
|
7886
7635
|
}
|
|
7887
7636
|
**/
|
|
7888
|
-
/*eslint-enable */
|
|
7889
7637
|
function SearchResults(state, results, options) {
|
|
7890
7638
|
var mainSubResponse = results[0];
|
|
7891
|
-
|
|
7892
7639
|
this._rawResults = results;
|
|
7893
7640
|
|
|
7641
|
+
// eslint-disable-next-line consistent-this
|
|
7894
7642
|
var self = this;
|
|
7895
7643
|
|
|
7896
7644
|
// https://www.algolia.com/doc/api-reference/api-methods/search/#response
|
|
7897
|
-
Object.keys(mainSubResponse).forEach(function(key) {
|
|
7645
|
+
Object.keys(mainSubResponse).forEach(function (key) {
|
|
7898
7646
|
self[key] = mainSubResponse[key];
|
|
7899
7647
|
});
|
|
7900
7648
|
|
|
7901
7649
|
// Make every key of the result options reachable from the instance
|
|
7902
|
-
Object.keys(options || {}).forEach(function(key) {
|
|
7650
|
+
Object.keys(options || {}).forEach(function (key) {
|
|
7903
7651
|
self[key] = options[key];
|
|
7904
7652
|
});
|
|
7905
7653
|
|
|
@@ -7921,8 +7669,8 @@
|
|
|
7921
7669
|
* all the records that match the search parameters. Each record is
|
|
7922
7670
|
* augmented with a new attribute `_highlightResult`
|
|
7923
7671
|
* which is an object keyed by attribute and with the following properties:
|
|
7924
|
-
*
|
|
7925
|
-
*
|
|
7672
|
+
* - `value` : the value of the facet highlighted (html)
|
|
7673
|
+
* - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
|
|
7926
7674
|
* @name hits
|
|
7927
7675
|
* @member {object[]}
|
|
7928
7676
|
* @memberof SearchResults
|
|
@@ -8043,10 +7791,8 @@
|
|
|
8043
7791
|
* @memberof SearchResults
|
|
8044
7792
|
* @instance
|
|
8045
7793
|
*/
|
|
8046
|
-
this.processingTimeMS = results.reduce(function(sum, result) {
|
|
8047
|
-
return result.processingTimeMS === undefined
|
|
8048
|
-
? sum
|
|
8049
|
-
: sum + result.processingTimeMS;
|
|
7794
|
+
this.processingTimeMS = results.reduce(function (sum, result) {
|
|
7795
|
+
return result.processingTimeMS === undefined ? sum : sum + result.processingTimeMS;
|
|
8050
7796
|
}, 0);
|
|
8051
7797
|
|
|
8052
7798
|
/**
|
|
@@ -8066,9 +7812,7 @@
|
|
|
8066
7812
|
* @member {SearchResults.Facet[]}
|
|
8067
7813
|
*/
|
|
8068
7814
|
this.facets = [];
|
|
8069
|
-
|
|
8070
7815
|
var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
|
|
8071
|
-
|
|
8072
7816
|
var facetsIndices = getIndices(state.facets);
|
|
8073
7817
|
var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
|
|
8074
7818
|
var nextDisjunctiveResult = 1;
|
|
@@ -8077,20 +7821,14 @@
|
|
|
8077
7821
|
// we get the facets information from the first, general, response.
|
|
8078
7822
|
|
|
8079
7823
|
var mainFacets = mainSubResponse.facets || {};
|
|
8080
|
-
|
|
8081
|
-
Object.keys(mainFacets).forEach(function(facetKey) {
|
|
7824
|
+
Object.keys(mainFacets).forEach(function (facetKey) {
|
|
8082
7825
|
var facetValueObject = mainFacets[facetKey];
|
|
8083
|
-
|
|
8084
|
-
var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
|
|
8085
|
-
state.hierarchicalFacets,
|
|
8086
|
-
facetKey
|
|
8087
|
-
);
|
|
8088
|
-
|
|
7826
|
+
var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(state.hierarchicalFacets, facetKey);
|
|
8089
7827
|
if (hierarchicalFacet) {
|
|
8090
7828
|
// Place the hierarchicalFacet data at the correct index depending on
|
|
8091
7829
|
// the attributes order that was defined at the helper initialization
|
|
8092
7830
|
var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
|
|
8093
|
-
var idxAttributeName = findIndex$1(state.hierarchicalFacets, function(f) {
|
|
7831
|
+
var idxAttributeName = findIndex$1(state.hierarchicalFacets, function (f) {
|
|
8094
7832
|
return f.name === hierarchicalFacet.name;
|
|
8095
7833
|
});
|
|
8096
7834
|
self.hierarchicalFacets[idxAttributeName][facetIndex] = {
|
|
@@ -8102,7 +7840,6 @@
|
|
|
8102
7840
|
var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
|
|
8103
7841
|
var isFacetConjunctive = state.facets.indexOf(facetKey) !== -1;
|
|
8104
7842
|
var position;
|
|
8105
|
-
|
|
8106
7843
|
if (isFacetDisjunctive) {
|
|
8107
7844
|
position = disjunctiveFacetsIndices[facetKey];
|
|
8108
7845
|
self.disjunctiveFacets[position] = {
|
|
@@ -8128,22 +7865,20 @@
|
|
|
8128
7865
|
this.hierarchicalFacets = compact(this.hierarchicalFacets);
|
|
8129
7866
|
|
|
8130
7867
|
// aggregate the refined disjunctive facets
|
|
8131
|
-
disjunctiveFacets.forEach(function(disjunctiveFacet) {
|
|
7868
|
+
disjunctiveFacets.forEach(function (disjunctiveFacet) {
|
|
8132
7869
|
var result = results[nextDisjunctiveResult];
|
|
8133
7870
|
var facets = result && result.facets ? result.facets : {};
|
|
8134
7871
|
var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
|
|
8135
7872
|
|
|
8136
7873
|
// There should be only item in facets.
|
|
8137
|
-
Object.keys(facets).forEach(function(dfacet) {
|
|
7874
|
+
Object.keys(facets).forEach(function (dfacet) {
|
|
8138
7875
|
var facetResults = facets[dfacet];
|
|
8139
|
-
|
|
8140
7876
|
var position;
|
|
8141
|
-
|
|
8142
7877
|
if (hierarchicalFacet) {
|
|
8143
|
-
position = findIndex$1(state.hierarchicalFacets, function(f) {
|
|
7878
|
+
position = findIndex$1(state.hierarchicalFacets, function (f) {
|
|
8144
7879
|
return f.name === hierarchicalFacet.name;
|
|
8145
7880
|
});
|
|
8146
|
-
var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function(f) {
|
|
7881
|
+
var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function (f) {
|
|
8147
7882
|
return f.attribute === dfacet;
|
|
8148
7883
|
});
|
|
8149
7884
|
|
|
@@ -8151,29 +7886,20 @@
|
|
|
8151
7886
|
if (attributeIndex === -1) {
|
|
8152
7887
|
return;
|
|
8153
7888
|
}
|
|
8154
|
-
|
|
8155
|
-
self.hierarchicalFacets[position][attributeIndex].data = merge_1(
|
|
8156
|
-
{},
|
|
8157
|
-
self.hierarchicalFacets[position][attributeIndex].data,
|
|
8158
|
-
facetResults
|
|
8159
|
-
);
|
|
7889
|
+
self.hierarchicalFacets[position][attributeIndex].data = merge$1({}, self.hierarchicalFacets[position][attributeIndex].data, facetResults);
|
|
8160
7890
|
} else {
|
|
8161
7891
|
position = disjunctiveFacetsIndices[dfacet];
|
|
8162
|
-
|
|
8163
7892
|
var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
|
|
8164
|
-
|
|
8165
7893
|
self.disjunctiveFacets[position] = {
|
|
8166
7894
|
name: dfacet,
|
|
8167
7895
|
data: defaultsPure({}, facetResults, dataFromMainRequest),
|
|
8168
7896
|
exhaustive: result.exhaustiveFacetsCount
|
|
8169
7897
|
};
|
|
8170
7898
|
assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
|
|
8171
|
-
|
|
8172
7899
|
if (state.disjunctiveFacetsRefinements[dfacet]) {
|
|
8173
|
-
state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
|
|
7900
|
+
state.disjunctiveFacetsRefinements[dfacet].forEach(function (refinementValue) {
|
|
8174
7901
|
// add the disjunctive refinements if it is no more retrieved
|
|
8175
|
-
if (!self.disjunctiveFacets[position].data[refinementValue] &&
|
|
8176
|
-
state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
|
|
7902
|
+
if (!self.disjunctiveFacets[position].data[refinementValue] && state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
|
|
8177
7903
|
self.disjunctiveFacets[position].data[refinementValue] = 0;
|
|
8178
7904
|
}
|
|
8179
7905
|
});
|
|
@@ -8184,28 +7910,23 @@
|
|
|
8184
7910
|
});
|
|
8185
7911
|
|
|
8186
7912
|
// if we have some parent level values for hierarchical facets, merge them
|
|
8187
|
-
state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
|
|
7913
|
+
state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
|
|
8188
7914
|
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
|
|
8189
7915
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
8190
|
-
|
|
8191
7916
|
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
|
|
8192
7917
|
// if we are already at a root refinement (or no refinement at all), there is no
|
|
8193
7918
|
// root level values request
|
|
8194
7919
|
if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
|
|
8195
7920
|
return;
|
|
8196
7921
|
}
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
? result.facets
|
|
8201
|
-
: {};
|
|
8202
|
-
|
|
8203
|
-
Object.keys(facets).forEach(function(dfacet) {
|
|
7922
|
+
results.slice(nextDisjunctiveResult).forEach(function (result) {
|
|
7923
|
+
var facets = result && result.facets ? result.facets : {};
|
|
7924
|
+
Object.keys(facets).forEach(function (dfacet) {
|
|
8204
7925
|
var facetResults = facets[dfacet];
|
|
8205
|
-
var position = findIndex$1(state.hierarchicalFacets, function(f) {
|
|
7926
|
+
var position = findIndex$1(state.hierarchicalFacets, function (f) {
|
|
8206
7927
|
return f.name === hierarchicalFacet.name;
|
|
8207
7928
|
});
|
|
8208
|
-
var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function(f) {
|
|
7929
|
+
var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function (f) {
|
|
8209
7930
|
return f.attribute === dfacet;
|
|
8210
7931
|
});
|
|
8211
7932
|
|
|
@@ -8223,35 +7944,29 @@
|
|
|
8223
7944
|
// | beers (5)
|
|
8224
7945
|
// > IPA (5)
|
|
8225
7946
|
var defaultData = {};
|
|
8226
|
-
|
|
8227
7947
|
if (currentRefinement.length > 0) {
|
|
8228
7948
|
var root = currentRefinement[0].split(separator)[0];
|
|
8229
7949
|
defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
|
|
8230
7950
|
}
|
|
8231
|
-
|
|
8232
|
-
self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
|
|
8233
|
-
defaultData,
|
|
8234
|
-
facetResults,
|
|
8235
|
-
self.hierarchicalFacets[position][attributeIndex].data
|
|
8236
|
-
);
|
|
7951
|
+
self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(defaultData, facetResults, self.hierarchicalFacets[position][attributeIndex].data);
|
|
8237
7952
|
});
|
|
8238
|
-
|
|
8239
7953
|
nextDisjunctiveResult++;
|
|
8240
7954
|
});
|
|
8241
7955
|
});
|
|
8242
7956
|
|
|
8243
7957
|
// add the excludes
|
|
8244
|
-
Object.keys(state.facetsExcludes).forEach(function(facetName) {
|
|
7958
|
+
Object.keys(state.facetsExcludes).forEach(function (facetName) {
|
|
8245
7959
|
var excludes = state.facetsExcludes[facetName];
|
|
8246
7960
|
var position = facetsIndices[facetName];
|
|
8247
|
-
|
|
8248
7961
|
self.facets[position] = {
|
|
8249
7962
|
name: facetName,
|
|
8250
7963
|
data: mainFacets[facetName],
|
|
8251
7964
|
exhaustive: mainSubResponse.exhaustiveFacetsCount
|
|
8252
7965
|
};
|
|
8253
|
-
excludes.forEach(function(facetValue) {
|
|
8254
|
-
self.facets[position] = self.facets[position] || {
|
|
7966
|
+
excludes.forEach(function (facetValue) {
|
|
7967
|
+
self.facets[position] = self.facets[position] || {
|
|
7968
|
+
name: facetName
|
|
7969
|
+
};
|
|
8255
7970
|
self.facets[position].data = self.facets[position].data || {};
|
|
8256
7971
|
self.facets[position].data[facetValue] = 0;
|
|
8257
7972
|
});
|
|
@@ -8270,7 +7985,6 @@
|
|
|
8270
7985
|
* @type {Array}
|
|
8271
7986
|
*/
|
|
8272
7987
|
this.disjunctiveFacets = compact(this.disjunctiveFacets);
|
|
8273
|
-
|
|
8274
7988
|
this._state = state;
|
|
8275
7989
|
}
|
|
8276
7990
|
|
|
@@ -8280,14 +7994,11 @@
|
|
|
8280
7994
|
* @param {string} name name of the faceted attribute
|
|
8281
7995
|
* @return {SearchResults.Facet} the facet object
|
|
8282
7996
|
*/
|
|
8283
|
-
SearchResults.prototype.getFacetByName = function(name) {
|
|
7997
|
+
SearchResults.prototype.getFacetByName = function (name) {
|
|
8284
7998
|
function predicate(facet) {
|
|
8285
7999
|
return facet.name === name;
|
|
8286
8000
|
}
|
|
8287
|
-
|
|
8288
|
-
return find$1(this.facets, predicate) ||
|
|
8289
|
-
find$1(this.disjunctiveFacets, predicate) ||
|
|
8290
|
-
find$1(this.hierarchicalFacets, predicate);
|
|
8001
|
+
return find$1(this.facets, predicate) || find$1(this.disjunctiveFacets, predicate) || find$1(this.hierarchicalFacets, predicate);
|
|
8291
8002
|
};
|
|
8292
8003
|
|
|
8293
8004
|
/**
|
|
@@ -8301,12 +8012,10 @@
|
|
|
8301
8012
|
function predicate(facet) {
|
|
8302
8013
|
return facet.name === attribute;
|
|
8303
8014
|
}
|
|
8304
|
-
|
|
8305
8015
|
if (results._state.isConjunctiveFacet(attribute)) {
|
|
8306
8016
|
var facet = find$1(results.facets, predicate);
|
|
8307
8017
|
if (!facet) return [];
|
|
8308
|
-
|
|
8309
|
-
return Object.keys(facet.data).map(function(name) {
|
|
8018
|
+
return Object.keys(facet.data).map(function (name) {
|
|
8310
8019
|
var value = escapeFacetValue$3(name);
|
|
8311
8020
|
return {
|
|
8312
8021
|
name: name,
|
|
@@ -8319,8 +8028,7 @@
|
|
|
8319
8028
|
} else if (results._state.isDisjunctiveFacet(attribute)) {
|
|
8320
8029
|
var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
|
|
8321
8030
|
if (!disjunctiveFacet) return [];
|
|
8322
|
-
|
|
8323
|
-
return Object.keys(disjunctiveFacet.data).map(function(name) {
|
|
8031
|
+
return Object.keys(disjunctiveFacet.data).map(function (name) {
|
|
8324
8032
|
var value = escapeFacetValue$3(name);
|
|
8325
8033
|
return {
|
|
8326
8034
|
name: name,
|
|
@@ -8332,29 +8040,31 @@
|
|
|
8332
8040
|
} else if (results._state.isHierarchicalFacet(attribute)) {
|
|
8333
8041
|
var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
|
|
8334
8042
|
if (!hierarchicalFacetValues) return hierarchicalFacetValues;
|
|
8335
|
-
|
|
8336
8043
|
var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
|
|
8337
|
-
var
|
|
8338
|
-
|
|
8339
|
-
|
|
8044
|
+
var separator = results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
8045
|
+
var currentRefinement = unescapeFacetValue$3(results._state.getHierarchicalRefinement(attribute)[0] || '');
|
|
8046
|
+
if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
|
|
8047
|
+
currentRefinement = currentRefinement.replace(hierarchicalFacet.rootPath + separator, '');
|
|
8048
|
+
}
|
|
8049
|
+
var currentRefinementSplit = currentRefinement.split(separator);
|
|
8340
8050
|
currentRefinementSplit.unshift(attribute);
|
|
8341
|
-
|
|
8342
8051
|
setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
|
|
8343
|
-
|
|
8344
8052
|
return hierarchicalFacetValues;
|
|
8345
8053
|
}
|
|
8054
|
+
return undefined;
|
|
8346
8055
|
}
|
|
8347
8056
|
|
|
8348
8057
|
/**
|
|
8349
8058
|
* Set the isRefined of a hierarchical facet result based on the current state.
|
|
8350
8059
|
* @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
|
|
8351
|
-
* @param {string[]}
|
|
8060
|
+
* @param {string[]} currentRefinement array of parts of the current hierarchical refinement
|
|
8352
8061
|
* @param {number} depth recursion depth in the currentRefinement
|
|
8062
|
+
* @return {undefined} function mutates the item
|
|
8353
8063
|
*/
|
|
8354
8064
|
function setIsRefined(item, currentRefinement, depth) {
|
|
8355
8065
|
item.isRefined = item.name === currentRefinement[depth];
|
|
8356
8066
|
if (item.data) {
|
|
8357
|
-
item.data.forEach(function(child) {
|
|
8067
|
+
item.data.forEach(function (child) {
|
|
8358
8068
|
setIsRefined(child, currentRefinement, depth + 1);
|
|
8359
8069
|
});
|
|
8360
8070
|
}
|
|
@@ -8363,32 +8073,30 @@
|
|
|
8363
8073
|
/**
|
|
8364
8074
|
* Sort nodes of a hierarchical or disjunctive facet results
|
|
8365
8075
|
* @private
|
|
8366
|
-
* @param {function} sortFn
|
|
8076
|
+
* @param {function} sortFn sort function to apply
|
|
8367
8077
|
* @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
|
|
8368
8078
|
* @param {string[]} names attribute names
|
|
8369
8079
|
* @param {number} [level=0] current index in the names array
|
|
8080
|
+
* @return {HierarchicalFacet|Array} sorted node
|
|
8370
8081
|
*/
|
|
8371
8082
|
function recSort(sortFn, node, names, level) {
|
|
8372
8083
|
level = level || 0;
|
|
8373
|
-
|
|
8374
8084
|
if (Array.isArray(node)) {
|
|
8375
8085
|
return sortFn(node, names[level]);
|
|
8376
8086
|
}
|
|
8377
|
-
|
|
8378
8087
|
if (!node.data || node.data.length === 0) {
|
|
8379
8088
|
return node;
|
|
8380
8089
|
}
|
|
8381
|
-
|
|
8382
|
-
var children = node.data.map(function(childNode) {
|
|
8090
|
+
var children = node.data.map(function (childNode) {
|
|
8383
8091
|
return recSort(sortFn, childNode, names, level + 1);
|
|
8384
8092
|
});
|
|
8385
8093
|
var sortedChildren = sortFn(children, names[level]);
|
|
8386
|
-
var newNode = defaultsPure({
|
|
8094
|
+
var newNode = defaultsPure({
|
|
8095
|
+
data: sortedChildren
|
|
8096
|
+
}, node);
|
|
8387
8097
|
return newNode;
|
|
8388
8098
|
}
|
|
8389
|
-
|
|
8390
8099
|
SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
|
|
8391
|
-
|
|
8392
8100
|
function vanillaSortFn(order, data) {
|
|
8393
8101
|
return data.sort(order);
|
|
8394
8102
|
}
|
|
@@ -8404,23 +8112,21 @@
|
|
|
8404
8112
|
* Sorts facet arrays via their facet ordering
|
|
8405
8113
|
* @param {Array} facetValues the values
|
|
8406
8114
|
* @param {FacetOrdering} facetOrdering the ordering
|
|
8407
|
-
* @returns {Array}
|
|
8115
|
+
* @returns {Array} the sorted facet values
|
|
8408
8116
|
*/
|
|
8409
8117
|
function sortViaFacetOrdering(facetValues, facetOrdering) {
|
|
8410
8118
|
var orderedFacets = [];
|
|
8411
8119
|
var remainingFacets = [];
|
|
8412
|
-
|
|
8413
8120
|
var order = facetOrdering.order || [];
|
|
8414
8121
|
/**
|
|
8415
8122
|
* an object with the keys being the values in order, the values their index:
|
|
8416
8123
|
* ['one', 'two'] -> { one: 0, two: 1 }
|
|
8417
8124
|
*/
|
|
8418
|
-
var reverseOrder = order.reduce(function(acc, name, i) {
|
|
8125
|
+
var reverseOrder = order.reduce(function (acc, name, i) {
|
|
8419
8126
|
acc[name] = i;
|
|
8420
8127
|
return acc;
|
|
8421
8128
|
}, {});
|
|
8422
|
-
|
|
8423
|
-
facetValues.forEach(function(item) {
|
|
8129
|
+
facetValues.forEach(function (item) {
|
|
8424
8130
|
// hierarchical facets get sorted using their raw name
|
|
8425
8131
|
var name = item.path || item.name;
|
|
8426
8132
|
if (reverseOrder[name] !== undefined) {
|
|
@@ -8429,11 +8135,9 @@
|
|
|
8429
8135
|
remainingFacets.push(item);
|
|
8430
8136
|
}
|
|
8431
8137
|
});
|
|
8432
|
-
|
|
8433
|
-
orderedFacets = orderedFacets.filter(function(facet) {
|
|
8138
|
+
orderedFacets = orderedFacets.filter(function (facet) {
|
|
8434
8139
|
return facet;
|
|
8435
8140
|
});
|
|
8436
|
-
|
|
8437
8141
|
var sortRemainingBy = facetOrdering.sortRemainingBy;
|
|
8438
8142
|
var ordering;
|
|
8439
8143
|
if (sortRemainingBy === 'hidden') {
|
|
@@ -8443,24 +8147,16 @@
|
|
|
8443
8147
|
} else {
|
|
8444
8148
|
ordering = [['count'], ['desc']];
|
|
8445
8149
|
}
|
|
8446
|
-
|
|
8447
|
-
return orderedFacets.concat(
|
|
8448
|
-
orderBy_1(remainingFacets, ordering[0], ordering[1])
|
|
8449
|
-
);
|
|
8150
|
+
return orderedFacets.concat(orderBy_1(remainingFacets, ordering[0], ordering[1]));
|
|
8450
8151
|
}
|
|
8451
8152
|
|
|
8452
8153
|
/**
|
|
8453
8154
|
* @param {SearchResults} results the search results class
|
|
8454
8155
|
* @param {string} attribute the attribute to retrieve ordering of
|
|
8455
|
-
* @returns {FacetOrdering
|
|
8156
|
+
* @returns {FacetOrdering | undefined} the facet ordering
|
|
8456
8157
|
*/
|
|
8457
8158
|
function getFacetOrdering(results, attribute) {
|
|
8458
|
-
return
|
|
8459
|
-
results.renderingContent &&
|
|
8460
|
-
results.renderingContent.facetOrdering &&
|
|
8461
|
-
results.renderingContent.facetOrdering.values &&
|
|
8462
|
-
results.renderingContent.facetOrdering.values[attribute]
|
|
8463
|
-
);
|
|
8159
|
+
return results.renderingContent && results.renderingContent.facetOrdering && results.renderingContent.facetOrdering.values && results.renderingContent.facetOrdering.values[attribute];
|
|
8464
8160
|
}
|
|
8465
8161
|
|
|
8466
8162
|
/**
|
|
@@ -8511,12 +8207,11 @@
|
|
|
8511
8207
|
* });
|
|
8512
8208
|
* });
|
|
8513
8209
|
*/
|
|
8514
|
-
SearchResults.prototype.getFacetValues = function(attribute, opts) {
|
|
8210
|
+
SearchResults.prototype.getFacetValues = function (attribute, opts) {
|
|
8515
8211
|
var facetValues = extractNormalizedFacetValues(this, attribute);
|
|
8516
8212
|
if (!facetValues) {
|
|
8517
8213
|
return undefined;
|
|
8518
8214
|
}
|
|
8519
|
-
|
|
8520
8215
|
var options = defaultsPure({}, opts, {
|
|
8521
8216
|
sortBy: SearchResults.DEFAULT_SORT,
|
|
8522
8217
|
// if no sortBy is given, attempt to sort based on facetOrdering
|
|
@@ -8524,6 +8219,7 @@
|
|
|
8524
8219
|
facetOrdering: !(opts && opts.sortBy)
|
|
8525
8220
|
});
|
|
8526
8221
|
|
|
8222
|
+
// eslint-disable-next-line consistent-this
|
|
8527
8223
|
var results = this;
|
|
8528
8224
|
var attributes;
|
|
8529
8225
|
if (Array.isArray(facetValues)) {
|
|
@@ -8532,25 +8228,20 @@
|
|
|
8532
8228
|
var config = results._state.getHierarchicalFacetByName(facetValues.name);
|
|
8533
8229
|
attributes = config.attributes;
|
|
8534
8230
|
}
|
|
8535
|
-
|
|
8536
|
-
return recSort(function(data, facetName) {
|
|
8231
|
+
return recSort(function (data, facetName) {
|
|
8537
8232
|
if (options.facetOrdering) {
|
|
8538
8233
|
var facetOrdering = getFacetOrdering(results, facetName);
|
|
8539
|
-
if (
|
|
8234
|
+
if (facetOrdering) {
|
|
8540
8235
|
return sortViaFacetOrdering(data, facetOrdering);
|
|
8541
8236
|
}
|
|
8542
8237
|
}
|
|
8543
|
-
|
|
8544
8238
|
if (Array.isArray(options.sortBy)) {
|
|
8545
8239
|
var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
|
|
8546
8240
|
return orderBy_1(data, order[0], order[1]);
|
|
8547
8241
|
} else if (typeof options.sortBy === 'function') {
|
|
8548
8242
|
return vanillaSortFn(options.sortBy, data);
|
|
8549
8243
|
}
|
|
8550
|
-
throw new Error(
|
|
8551
|
-
'options.sortBy is optional but if defined it must be ' +
|
|
8552
|
-
'either an array of string (predicates) or a sorting function'
|
|
8553
|
-
);
|
|
8244
|
+
throw new Error('options.sortBy is optional but if defined it must be ' + 'either an array of string (predicates) or a sorting function');
|
|
8554
8245
|
}, facetValues, attributes);
|
|
8555
8246
|
};
|
|
8556
8247
|
|
|
@@ -8560,13 +8251,12 @@
|
|
|
8560
8251
|
* @param {string} attribute name of the faceted attribute
|
|
8561
8252
|
* @return {object} The stats of the facet
|
|
8562
8253
|
*/
|
|
8563
|
-
SearchResults.prototype.getFacetStats = function(attribute) {
|
|
8254
|
+
SearchResults.prototype.getFacetStats = function (attribute) {
|
|
8564
8255
|
if (this._state.isConjunctiveFacet(attribute)) {
|
|
8565
8256
|
return getFacetStatsIfAvailable(this.facets, attribute);
|
|
8566
8257
|
} else if (this._state.isDisjunctiveFacet(attribute)) {
|
|
8567
8258
|
return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
|
|
8568
8259
|
}
|
|
8569
|
-
|
|
8570
8260
|
return undefined;
|
|
8571
8261
|
};
|
|
8572
8262
|
|
|
@@ -8577,10 +8267,11 @@
|
|
|
8577
8267
|
|
|
8578
8268
|
/**
|
|
8579
8269
|
* @param {FacetListItem[]} facetList (has more items, but enough for here)
|
|
8580
|
-
* @param {string} facetName
|
|
8270
|
+
* @param {string} facetName The attribute to look for
|
|
8271
|
+
* @return {object|undefined} The stats of the facet
|
|
8581
8272
|
*/
|
|
8582
8273
|
function getFacetStatsIfAvailable(facetList, facetName) {
|
|
8583
|
-
var data = find$1(facetList, function(facet) {
|
|
8274
|
+
var data = find$1(facetList, function (facet) {
|
|
8584
8275
|
return facet.name === facetName;
|
|
8585
8276
|
});
|
|
8586
8277
|
return data && data.stats;
|
|
@@ -8598,40 +8289,35 @@
|
|
|
8598
8289
|
*
|
|
8599
8290
|
* @return {Array.<Refinement>} all the refinements
|
|
8600
8291
|
*/
|
|
8601
|
-
SearchResults.prototype.getRefinements = function() {
|
|
8292
|
+
SearchResults.prototype.getRefinements = function () {
|
|
8602
8293
|
var state = this._state;
|
|
8294
|
+
// eslint-disable-next-line consistent-this
|
|
8603
8295
|
var results = this;
|
|
8604
8296
|
var res = [];
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
state.facetsRefinements[attributeName].forEach(function(name) {
|
|
8297
|
+
Object.keys(state.facetsRefinements).forEach(function (attributeName) {
|
|
8298
|
+
state.facetsRefinements[attributeName].forEach(function (name) {
|
|
8608
8299
|
res.push(getRefinement$1(state, 'facet', attributeName, name, results.facets));
|
|
8609
8300
|
});
|
|
8610
8301
|
});
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
state.facetsExcludes[attributeName].forEach(function(name) {
|
|
8302
|
+
Object.keys(state.facetsExcludes).forEach(function (attributeName) {
|
|
8303
|
+
state.facetsExcludes[attributeName].forEach(function (name) {
|
|
8614
8304
|
res.push(getRefinement$1(state, 'exclude', attributeName, name, results.facets));
|
|
8615
8305
|
});
|
|
8616
8306
|
});
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
|
|
8307
|
+
Object.keys(state.disjunctiveFacetsRefinements).forEach(function (attributeName) {
|
|
8308
|
+
state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
|
|
8620
8309
|
res.push(getRefinement$1(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
|
|
8621
8310
|
});
|
|
8622
8311
|
});
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
|
|
8312
|
+
Object.keys(state.hierarchicalFacetsRefinements).forEach(function (attributeName) {
|
|
8313
|
+
state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
|
|
8626
8314
|
res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
|
|
8627
8315
|
});
|
|
8628
8316
|
});
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
Object.keys(state.numericRefinements).forEach(function(attributeName) {
|
|
8317
|
+
Object.keys(state.numericRefinements).forEach(function (attributeName) {
|
|
8632
8318
|
var operators = state.numericRefinements[attributeName];
|
|
8633
|
-
Object.keys(operators).forEach(function(operator) {
|
|
8634
|
-
operators[operator].forEach(function(value) {
|
|
8319
|
+
Object.keys(operators).forEach(function (operator) {
|
|
8320
|
+
operators[operator].forEach(function (value) {
|
|
8635
8321
|
res.push({
|
|
8636
8322
|
type: 'numeric',
|
|
8637
8323
|
attributeName: attributeName,
|
|
@@ -8642,11 +8328,13 @@
|
|
|
8642
8328
|
});
|
|
8643
8329
|
});
|
|
8644
8330
|
});
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8331
|
+
state.tagRefinements.forEach(function (name) {
|
|
8332
|
+
res.push({
|
|
8333
|
+
type: 'tag',
|
|
8334
|
+
attributeName: '_tags',
|
|
8335
|
+
name: name
|
|
8336
|
+
});
|
|
8648
8337
|
});
|
|
8649
|
-
|
|
8650
8338
|
return res;
|
|
8651
8339
|
};
|
|
8652
8340
|
|
|
@@ -8658,19 +8346,19 @@
|
|
|
8658
8346
|
*/
|
|
8659
8347
|
|
|
8660
8348
|
/**
|
|
8661
|
-
* @param {
|
|
8662
|
-
* @param {
|
|
8663
|
-
* @param {string} attributeName
|
|
8664
|
-
* @param {*} name
|
|
8665
|
-
* @param {Facet[]} resultsFacets
|
|
8349
|
+
* @param {SearchParameters} state the current state
|
|
8350
|
+
* @param {string} type the type of the refinement
|
|
8351
|
+
* @param {string} attributeName The attribute of the facet
|
|
8352
|
+
* @param {*} name The name of the facet
|
|
8353
|
+
* @param {Facet[]} resultsFacets facets from the results
|
|
8354
|
+
* @return {Refinement} the refinement
|
|
8666
8355
|
*/
|
|
8667
8356
|
function getRefinement$1(state, type, attributeName, name, resultsFacets) {
|
|
8668
|
-
var facet = find$1(resultsFacets, function(f) {
|
|
8357
|
+
var facet = find$1(resultsFacets, function (f) {
|
|
8669
8358
|
return f.name === attributeName;
|
|
8670
8359
|
});
|
|
8671
8360
|
var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
|
|
8672
|
-
var exhaustive =
|
|
8673
|
-
|
|
8361
|
+
var exhaustive = facet && facet.exhaustive || false;
|
|
8674
8362
|
return {
|
|
8675
8363
|
type: type,
|
|
8676
8364
|
attributeName: attributeName,
|
|
@@ -8681,31 +8369,28 @@
|
|
|
8681
8369
|
}
|
|
8682
8370
|
|
|
8683
8371
|
/**
|
|
8684
|
-
* @param {
|
|
8685
|
-
* @param {string} attributeName
|
|
8686
|
-
* @param {
|
|
8687
|
-
* @param {Facet[]} resultsFacets
|
|
8372
|
+
* @param {SearchParameters} state the current state
|
|
8373
|
+
* @param {string} attributeName the attribute of the hierarchical facet
|
|
8374
|
+
* @param {string} name the name of the facet
|
|
8375
|
+
* @param {Facet[]} resultsFacets facets from the results
|
|
8376
|
+
* @return {HierarchicalFacet} the hierarchical facet
|
|
8688
8377
|
*/
|
|
8689
8378
|
function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
|
|
8690
8379
|
var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
|
|
8691
8380
|
var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
|
|
8692
8381
|
var split = name.split(separator);
|
|
8693
|
-
var rootFacet = find$1(resultsFacets, function(facet) {
|
|
8382
|
+
var rootFacet = find$1(resultsFacets, function (facet) {
|
|
8694
8383
|
return facet.name === attributeName;
|
|
8695
8384
|
});
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
return f.name === part;
|
|
8701
|
-
});
|
|
8385
|
+
var facet = split.reduce(function (intermediateFacet, part) {
|
|
8386
|
+
var newFacet = intermediateFacet && find$1(intermediateFacet.data, function (f) {
|
|
8387
|
+
return f.name === part;
|
|
8388
|
+
});
|
|
8702
8389
|
return newFacet !== undefined ? newFacet : intermediateFacet;
|
|
8703
8390
|
}, rootFacet);
|
|
8704
|
-
|
|
8705
|
-
var
|
|
8706
|
-
var
|
|
8707
|
-
var path = (facet && facet.path) || '';
|
|
8708
|
-
|
|
8391
|
+
var count = facet && facet.count || 0;
|
|
8392
|
+
var exhaustive = facet && facet.exhaustive || false;
|
|
8393
|
+
var path = facet && facet.path || '';
|
|
8709
8394
|
return {
|
|
8710
8395
|
type: 'hierarchical',
|
|
8711
8396
|
attributeName: attributeName,
|
|
@@ -8714,7 +8399,6 @@
|
|
|
8714
8399
|
exhaustive: exhaustive
|
|
8715
8400
|
};
|
|
8716
8401
|
}
|
|
8717
|
-
|
|
8718
8402
|
var SearchResults_1 = SearchResults;
|
|
8719
8403
|
|
|
8720
8404
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
@@ -9030,7 +8714,6 @@
|
|
|
9030
8714
|
}
|
|
9031
8715
|
});
|
|
9032
8716
|
}
|
|
9033
|
-
|
|
9034
8717
|
var inherits_1 = inherits;
|
|
9035
8718
|
|
|
9036
8719
|
/**
|
|
@@ -9042,13 +8725,14 @@
|
|
|
9042
8725
|
* - result: when the response is retrieved from Algolia and is processed.
|
|
9043
8726
|
* This event contains a {@link SearchResults} object and the
|
|
9044
8727
|
* {@link SearchParameters} corresponding to this answer.
|
|
8728
|
+
* @param {AlgoliaSearchHelper} mainHelper the main helper
|
|
8729
|
+
* @param {function} fn the function to create the derived state
|
|
9045
8730
|
*/
|
|
9046
8731
|
function DerivedHelper(mainHelper, fn) {
|
|
9047
8732
|
this.main = mainHelper;
|
|
9048
8733
|
this.fn = fn;
|
|
9049
8734
|
this.lastResults = null;
|
|
9050
8735
|
}
|
|
9051
|
-
|
|
9052
8736
|
inherits_1(DerivedHelper, events);
|
|
9053
8737
|
|
|
9054
8738
|
/**
|
|
@@ -9056,33 +8740,30 @@
|
|
|
9056
8740
|
* @return {undefined}
|
|
9057
8741
|
* @throws Error if the derived helper is already detached
|
|
9058
8742
|
*/
|
|
9059
|
-
DerivedHelper.prototype.detach = function() {
|
|
8743
|
+
DerivedHelper.prototype.detach = function () {
|
|
9060
8744
|
this.removeAllListeners();
|
|
9061
8745
|
this.main.detachDerivedHelper(this);
|
|
9062
8746
|
};
|
|
9063
|
-
|
|
9064
|
-
DerivedHelper.prototype.getModifiedState = function(parameters) {
|
|
8747
|
+
DerivedHelper.prototype.getModifiedState = function (parameters) {
|
|
9065
8748
|
return this.fn(parameters);
|
|
9066
8749
|
};
|
|
9067
|
-
|
|
9068
8750
|
var DerivedHelper_1 = DerivedHelper;
|
|
9069
8751
|
|
|
9070
8752
|
function sortObject(obj) {
|
|
9071
|
-
return Object.keys(obj)
|
|
9072
|
-
.
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
return acc;
|
|
9078
|
-
}, {});
|
|
8753
|
+
return Object.keys(obj).sort(function (a, b) {
|
|
8754
|
+
return a.localeCompare(b);
|
|
8755
|
+
}).reduce(function (acc, curr) {
|
|
8756
|
+
acc[curr] = obj[curr];
|
|
8757
|
+
return acc;
|
|
8758
|
+
}, {});
|
|
9079
8759
|
}
|
|
9080
|
-
|
|
9081
8760
|
var requestBuilder = {
|
|
9082
8761
|
/**
|
|
9083
8762
|
* Get all the queries to send to the client, those queries can used directly
|
|
9084
8763
|
* with the Algolia client.
|
|
9085
8764
|
* @private
|
|
8765
|
+
* @param {string} index The name of the index
|
|
8766
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
9086
8767
|
* @return {object[]} The queries
|
|
9087
8768
|
*/
|
|
9088
8769
|
_getQueries: function getQueries(index, state) {
|
|
@@ -9095,7 +8776,7 @@
|
|
|
9095
8776
|
});
|
|
9096
8777
|
|
|
9097
8778
|
// One for each disjunctive facets
|
|
9098
|
-
state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
|
|
8779
|
+
state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
|
|
9099
8780
|
queries.push({
|
|
9100
8781
|
indexName: index,
|
|
9101
8782
|
params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
|
|
@@ -9103,7 +8784,7 @@
|
|
|
9103
8784
|
});
|
|
9104
8785
|
|
|
9105
8786
|
// More to get the parent levels of the hierarchical facets when refined
|
|
9106
|
-
state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
|
|
8787
|
+
state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
|
|
9107
8788
|
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
|
|
9108
8789
|
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
|
|
9109
8790
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
@@ -9112,75 +8793,58 @@
|
|
|
9112
8793
|
// we want to get all parent values
|
|
9113
8794
|
if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
|
|
9114
8795
|
// We generate a map of the filters we will use for our facet values queries
|
|
9115
|
-
var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
}
|
|
9124
|
-
, []);
|
|
9125
|
-
|
|
9126
|
-
filtersMap.forEach(function(filter, level) {
|
|
9127
|
-
var params = requestBuilder._getDisjunctiveFacetSearchParams(
|
|
9128
|
-
state,
|
|
9129
|
-
filter.attribute,
|
|
9130
|
-
level === 0
|
|
9131
|
-
);
|
|
8796
|
+
var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(function createFiltersMap(map, segment, level) {
|
|
8797
|
+
return map.concat({
|
|
8798
|
+
attribute: hierarchicalFacet.attributes[level],
|
|
8799
|
+
value: level === 0 ? segment : [map[map.length - 1].value, segment].join(separator)
|
|
8800
|
+
});
|
|
8801
|
+
}, []);
|
|
8802
|
+
filtersMap.forEach(function (filter, level) {
|
|
8803
|
+
var params = requestBuilder._getDisjunctiveFacetSearchParams(state, filter.attribute, level === 0);
|
|
9132
8804
|
|
|
9133
8805
|
// Keep facet filters unrelated to current hierarchical attributes
|
|
9134
8806
|
function hasHierarchicalFacetFilter(value) {
|
|
9135
|
-
return hierarchicalFacet.attributes.some(function(attribute) {
|
|
8807
|
+
return hierarchicalFacet.attributes.some(function (attribute) {
|
|
9136
8808
|
return attribute === value.split(':')[0];
|
|
9137
8809
|
});
|
|
9138
8810
|
}
|
|
9139
|
-
|
|
9140
|
-
var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
|
|
8811
|
+
var filteredFacetFilters = (params.facetFilters || []).reduce(function (acc, facetFilter) {
|
|
9141
8812
|
if (Array.isArray(facetFilter)) {
|
|
9142
|
-
var filtered = facetFilter.filter(function(filterValue) {
|
|
8813
|
+
var filtered = facetFilter.filter(function (filterValue) {
|
|
9143
8814
|
return !hasHierarchicalFacetFilter(filterValue);
|
|
9144
8815
|
});
|
|
9145
|
-
|
|
9146
8816
|
if (filtered.length > 0) {
|
|
9147
8817
|
acc.push(filtered);
|
|
9148
8818
|
}
|
|
9149
8819
|
}
|
|
9150
|
-
|
|
9151
8820
|
if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
|
|
9152
8821
|
acc.push(facetFilter);
|
|
9153
8822
|
}
|
|
9154
|
-
|
|
9155
8823
|
return acc;
|
|
9156
8824
|
}, []);
|
|
9157
|
-
|
|
9158
8825
|
var parent = filtersMap[level - 1];
|
|
9159
8826
|
if (level > 0) {
|
|
9160
8827
|
params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
|
|
9161
8828
|
} else {
|
|
9162
8829
|
params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
|
|
9163
8830
|
}
|
|
9164
|
-
|
|
9165
|
-
|
|
8831
|
+
queries.push({
|
|
8832
|
+
indexName: index,
|
|
8833
|
+
params: params
|
|
8834
|
+
});
|
|
9166
8835
|
});
|
|
9167
8836
|
}
|
|
9168
8837
|
});
|
|
9169
|
-
|
|
9170
8838
|
return queries;
|
|
9171
8839
|
},
|
|
9172
|
-
|
|
9173
8840
|
/**
|
|
9174
8841
|
* Build search parameters used to fetch hits
|
|
9175
8842
|
* @private
|
|
9176
|
-
* @
|
|
8843
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
8844
|
+
* @return {object.<string, any>} The search parameters for hits
|
|
9177
8845
|
*/
|
|
9178
|
-
_getHitsSearchParams: function(state) {
|
|
9179
|
-
var facets = state.facets
|
|
9180
|
-
.concat(state.disjunctiveFacets)
|
|
9181
|
-
.concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
|
|
9182
|
-
|
|
9183
|
-
|
|
8846
|
+
_getHitsSearchParams: function _getHitsSearchParams(state) {
|
|
8847
|
+
var facets = state.facets.concat(state.disjunctiveFacets).concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
|
|
9184
8848
|
var facetFilters = requestBuilder._getFacetFilters(state);
|
|
9185
8849
|
var numericFilters = requestBuilder._getNumericFilters(state);
|
|
9186
8850
|
var tagFilters = requestBuilder._getTagFilters(state);
|
|
@@ -9188,26 +8852,23 @@
|
|
|
9188
8852
|
facets: facets.indexOf('*') > -1 ? ['*'] : facets,
|
|
9189
8853
|
tagFilters: tagFilters
|
|
9190
8854
|
};
|
|
9191
|
-
|
|
9192
8855
|
if (facetFilters.length > 0) {
|
|
9193
8856
|
additionalParams.facetFilters = facetFilters;
|
|
9194
8857
|
}
|
|
9195
|
-
|
|
9196
8858
|
if (numericFilters.length > 0) {
|
|
9197
8859
|
additionalParams.numericFilters = numericFilters;
|
|
9198
8860
|
}
|
|
9199
|
-
|
|
9200
|
-
return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
|
|
8861
|
+
return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
|
|
9201
8862
|
},
|
|
9202
|
-
|
|
9203
8863
|
/**
|
|
9204
8864
|
* Build search parameters used to fetch a disjunctive facet
|
|
9205
8865
|
* @private
|
|
8866
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
9206
8867
|
* @param {string} facet the associated facet name
|
|
9207
8868
|
* @param {boolean} hierarchicalRootLevel ?? FIXME
|
|
9208
|
-
* @return {object}
|
|
8869
|
+
* @return {object} The search parameters for a disjunctive facet
|
|
9209
8870
|
*/
|
|
9210
|
-
_getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
|
|
8871
|
+
_getDisjunctiveFacetSearchParams: function _getDisjunctiveFacetSearchParams(state, facet, hierarchicalRootLevel) {
|
|
9211
8872
|
var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
|
|
9212
8873
|
var numericFilters = requestBuilder._getNumericFilters(state, facet);
|
|
9213
8874
|
var tagFilters = requestBuilder._getTagFilters(state);
|
|
@@ -9217,55 +8878,43 @@
|
|
|
9217
8878
|
analytics: false,
|
|
9218
8879
|
clickAnalytics: false
|
|
9219
8880
|
};
|
|
9220
|
-
|
|
9221
8881
|
if (tagFilters.length > 0) {
|
|
9222
8882
|
additionalParams.tagFilters = tagFilters;
|
|
9223
8883
|
}
|
|
9224
|
-
|
|
9225
8884
|
var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
|
|
9226
|
-
|
|
9227
8885
|
if (hierarchicalFacet) {
|
|
9228
|
-
additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
|
|
9229
|
-
state,
|
|
9230
|
-
hierarchicalFacet,
|
|
9231
|
-
hierarchicalRootLevel
|
|
9232
|
-
);
|
|
8886
|
+
additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, hierarchicalRootLevel);
|
|
9233
8887
|
} else {
|
|
9234
8888
|
additionalParams.facets = facet;
|
|
9235
8889
|
}
|
|
9236
|
-
|
|
9237
8890
|
if (numericFilters.length > 0) {
|
|
9238
8891
|
additionalParams.numericFilters = numericFilters;
|
|
9239
8892
|
}
|
|
9240
|
-
|
|
9241
8893
|
if (facetFilters.length > 0) {
|
|
9242
8894
|
additionalParams.facetFilters = facetFilters;
|
|
9243
8895
|
}
|
|
9244
|
-
|
|
9245
|
-
return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
|
|
8896
|
+
return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
|
|
9246
8897
|
},
|
|
9247
|
-
|
|
9248
8898
|
/**
|
|
9249
8899
|
* Return the numeric filters in an algolia request fashion
|
|
9250
8900
|
* @private
|
|
8901
|
+
* @param {SearchParameters} state the state from which to get the filters
|
|
9251
8902
|
* @param {string} [facetName] the name of the attribute for which the filters should be excluded
|
|
9252
8903
|
* @return {string[]} the numeric filters in the algolia format
|
|
9253
8904
|
*/
|
|
9254
|
-
_getNumericFilters: function(state, facetName) {
|
|
8905
|
+
_getNumericFilters: function _getNumericFilters(state, facetName) {
|
|
9255
8906
|
if (state.numericFilters) {
|
|
9256
8907
|
return state.numericFilters;
|
|
9257
8908
|
}
|
|
9258
|
-
|
|
9259
8909
|
var numericFilters = [];
|
|
9260
|
-
|
|
9261
|
-
Object.keys(state.numericRefinements).forEach(function(attribute) {
|
|
8910
|
+
Object.keys(state.numericRefinements).forEach(function (attribute) {
|
|
9262
8911
|
var operators = state.numericRefinements[attribute] || {};
|
|
9263
|
-
Object.keys(operators).forEach(function(operator) {
|
|
8912
|
+
Object.keys(operators).forEach(function (operator) {
|
|
9264
8913
|
var values = operators[operator] || [];
|
|
9265
8914
|
if (facetName !== attribute) {
|
|
9266
|
-
values.forEach(function(value) {
|
|
8915
|
+
values.forEach(function (value) {
|
|
9267
8916
|
if (Array.isArray(value)) {
|
|
9268
|
-
var vs = value.map(function(v) {
|
|
8917
|
+
var vs = value.map(function (v) {
|
|
9269
8918
|
return attribute + operator + v;
|
|
9270
8919
|
});
|
|
9271
8920
|
numericFilters.push(vs);
|
|
@@ -9276,74 +8925,64 @@
|
|
|
9276
8925
|
}
|
|
9277
8926
|
});
|
|
9278
8927
|
});
|
|
9279
|
-
|
|
9280
8928
|
return numericFilters;
|
|
9281
8929
|
},
|
|
9282
|
-
|
|
9283
8930
|
/**
|
|
9284
|
-
* Return the tags filters depending
|
|
8931
|
+
* Return the tags filters depending on which format is used, either tagFilters or tagRefinements
|
|
9285
8932
|
* @private
|
|
9286
|
-
* @
|
|
8933
|
+
* @param {SearchParameters} state the state from which to get the filters
|
|
8934
|
+
* @return {string} Tag filters in a single string
|
|
9287
8935
|
*/
|
|
9288
|
-
_getTagFilters: function(state) {
|
|
8936
|
+
_getTagFilters: function _getTagFilters(state) {
|
|
9289
8937
|
if (state.tagFilters) {
|
|
9290
8938
|
return state.tagFilters;
|
|
9291
8939
|
}
|
|
9292
|
-
|
|
9293
8940
|
return state.tagRefinements.join(',');
|
|
9294
8941
|
},
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
8942
|
/**
|
|
9298
8943
|
* Build facetFilters parameter based on current refinements. The array returned
|
|
9299
8944
|
* contains strings representing the facet filters in the algolia format.
|
|
9300
8945
|
* @private
|
|
8946
|
+
* @param {SearchParameters} state The state from which to get the queries
|
|
9301
8947
|
* @param {string} [facet] if set, the current disjunctive facet
|
|
9302
|
-
* @
|
|
8948
|
+
* @param {boolean} [hierarchicalRootLevel] ?? FIXME
|
|
8949
|
+
* @return {array.<string>} The facet filters in the algolia format
|
|
9303
8950
|
*/
|
|
9304
|
-
_getFacetFilters: function(state, facet, hierarchicalRootLevel) {
|
|
8951
|
+
_getFacetFilters: function _getFacetFilters(state, facet, hierarchicalRootLevel) {
|
|
9305
8952
|
var facetFilters = [];
|
|
9306
|
-
|
|
9307
8953
|
var facetsRefinements = state.facetsRefinements || {};
|
|
9308
|
-
Object.keys(facetsRefinements).forEach(function(facetName) {
|
|
8954
|
+
Object.keys(facetsRefinements).forEach(function (facetName) {
|
|
9309
8955
|
var facetValues = facetsRefinements[facetName] || [];
|
|
9310
|
-
facetValues.forEach(function(facetValue) {
|
|
8956
|
+
facetValues.forEach(function (facetValue) {
|
|
9311
8957
|
facetFilters.push(facetName + ':' + facetValue);
|
|
9312
8958
|
});
|
|
9313
8959
|
});
|
|
9314
|
-
|
|
9315
8960
|
var facetsExcludes = state.facetsExcludes || {};
|
|
9316
|
-
Object.keys(facetsExcludes).forEach(function(facetName) {
|
|
8961
|
+
Object.keys(facetsExcludes).forEach(function (facetName) {
|
|
9317
8962
|
var facetValues = facetsExcludes[facetName] || [];
|
|
9318
|
-
facetValues.forEach(function(facetValue) {
|
|
8963
|
+
facetValues.forEach(function (facetValue) {
|
|
9319
8964
|
facetFilters.push(facetName + ':-' + facetValue);
|
|
9320
8965
|
});
|
|
9321
8966
|
});
|
|
9322
|
-
|
|
9323
8967
|
var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
|
|
9324
|
-
Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
|
|
8968
|
+
Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
|
|
9325
8969
|
var facetValues = disjunctiveFacetsRefinements[facetName] || [];
|
|
9326
8970
|
if (facetName === facet || !facetValues || facetValues.length === 0) {
|
|
9327
8971
|
return;
|
|
9328
8972
|
}
|
|
9329
8973
|
var orFilters = [];
|
|
9330
|
-
|
|
9331
|
-
facetValues.forEach(function(facetValue) {
|
|
8974
|
+
facetValues.forEach(function (facetValue) {
|
|
9332
8975
|
orFilters.push(facetName + ':' + facetValue);
|
|
9333
8976
|
});
|
|
9334
|
-
|
|
9335
8977
|
facetFilters.push(orFilters);
|
|
9336
8978
|
});
|
|
9337
|
-
|
|
9338
8979
|
var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
|
|
9339
|
-
Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
|
|
8980
|
+
Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
|
|
9340
8981
|
var facetValues = hierarchicalFacetsRefinements[facetName] || [];
|
|
9341
8982
|
var facetValue = facetValues[0];
|
|
9342
|
-
|
|
9343
8983
|
if (facetValue === undefined) {
|
|
9344
8984
|
return;
|
|
9345
8985
|
}
|
|
9346
|
-
|
|
9347
8986
|
var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
|
|
9348
8987
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
9349
8988
|
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
|
|
@@ -9354,11 +8993,9 @@
|
|
|
9354
8993
|
if (facet === facetName) {
|
|
9355
8994
|
// if we are at the root level already, no need to ask for facet values, we get them from
|
|
9356
8995
|
// the hits query
|
|
9357
|
-
if (facetValue.indexOf(separator) === -1 ||
|
|
9358
|
-
(rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
|
|
8996
|
+
if (facetValue.indexOf(separator) === -1 || !rootPath && hierarchicalRootLevel === true || rootPath && rootPath.split(separator).length === facetValue.split(separator).length) {
|
|
9359
8997
|
return;
|
|
9360
8998
|
}
|
|
9361
|
-
|
|
9362
8999
|
if (!rootPath) {
|
|
9363
9000
|
attributesIndex = facetValue.split(separator).length - 2;
|
|
9364
9001
|
facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
|
|
@@ -9366,56 +9003,45 @@
|
|
|
9366
9003
|
attributesIndex = rootPath.split(separator).length - 1;
|
|
9367
9004
|
facetValue = rootPath;
|
|
9368
9005
|
}
|
|
9369
|
-
|
|
9370
9006
|
attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
|
|
9371
9007
|
} else {
|
|
9372
9008
|
attributesIndex = facetValue.split(separator).length - 1;
|
|
9373
|
-
|
|
9374
9009
|
attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
|
|
9375
9010
|
}
|
|
9376
|
-
|
|
9377
9011
|
if (attributeToRefine) {
|
|
9378
9012
|
facetFilters.push([attributeToRefine + ':' + facetValue]);
|
|
9379
9013
|
}
|
|
9380
9014
|
});
|
|
9381
|
-
|
|
9382
9015
|
return facetFilters;
|
|
9383
9016
|
},
|
|
9384
|
-
|
|
9385
|
-
_getHitsHierarchicalFacetsAttributes: function(state) {
|
|
9017
|
+
_getHitsHierarchicalFacetsAttributes: function _getHitsHierarchicalFacetsAttributes(state) {
|
|
9386
9018
|
var out = [];
|
|
9387
|
-
|
|
9388
9019
|
return state.hierarchicalFacets.reduce(
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
return allAttributes.concat(newAttributes);
|
|
9404
|
-
}, out);
|
|
9020
|
+
// ask for as much levels as there's hierarchical refinements
|
|
9021
|
+
function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
|
|
9022
|
+
var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
|
|
9023
|
+
|
|
9024
|
+
// if no refinement, ask for root level
|
|
9025
|
+
if (!hierarchicalRefinement) {
|
|
9026
|
+
allAttributes.push(hierarchicalFacet.attributes[0]);
|
|
9027
|
+
return allAttributes;
|
|
9028
|
+
}
|
|
9029
|
+
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
9030
|
+
var level = hierarchicalRefinement.split(separator).length;
|
|
9031
|
+
var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
|
|
9032
|
+
return allAttributes.concat(newAttributes);
|
|
9033
|
+
}, out);
|
|
9405
9034
|
},
|
|
9406
|
-
|
|
9407
|
-
_getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
|
|
9035
|
+
_getDisjunctiveHierarchicalFacetAttribute: function _getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, rootLevel) {
|
|
9408
9036
|
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
|
|
9409
9037
|
if (rootLevel === true) {
|
|
9410
9038
|
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
|
|
9411
9039
|
var attributeIndex = 0;
|
|
9412
|
-
|
|
9413
9040
|
if (rootPath) {
|
|
9414
9041
|
attributeIndex = rootPath.split(separator).length;
|
|
9415
9042
|
}
|
|
9416
9043
|
return [hierarchicalFacet.attributes[attributeIndex]];
|
|
9417
9044
|
}
|
|
9418
|
-
|
|
9419
9045
|
var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
|
|
9420
9046
|
// if refinement is 'beers > IPA > Flying dog',
|
|
9421
9047
|
// then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
|
|
@@ -9423,11 +9049,8 @@
|
|
|
9423
9049
|
var parentLevel = hierarchicalRefinement.split(separator).length - 1;
|
|
9424
9050
|
return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
|
|
9425
9051
|
},
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
|
|
9429
|
-
state.clearRefinements(facetName) :
|
|
9430
|
-
state;
|
|
9052
|
+
getSearchForFacetQuery: function getSearchForFacetQuery(facetName, query, maxFacetHits, state) {
|
|
9053
|
+
var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ? state.clearRefinements(facetName) : state;
|
|
9431
9054
|
var searchForFacetSearchParameters = {
|
|
9432
9055
|
facetQuery: query,
|
|
9433
9056
|
facetName: facetName
|
|
@@ -9435,17 +9058,12 @@
|
|
|
9435
9058
|
if (typeof maxFacetHits === 'number') {
|
|
9436
9059
|
searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
|
|
9437
9060
|
}
|
|
9438
|
-
return sortObject(
|
|
9439
|
-
{},
|
|
9440
|
-
requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
|
|
9441
|
-
searchForFacetSearchParameters
|
|
9442
|
-
));
|
|
9061
|
+
return sortObject(merge$1({}, requestBuilder._getHitsSearchParams(stateForSearchForFacetValues), searchForFacetSearchParameters));
|
|
9443
9062
|
}
|
|
9444
9063
|
};
|
|
9445
|
-
|
|
9446
9064
|
var requestBuilder_1 = requestBuilder;
|
|
9447
9065
|
|
|
9448
|
-
var version = '3.13.
|
|
9066
|
+
var version = '3.13.3';
|
|
9449
9067
|
|
|
9450
9068
|
var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
|
|
9451
9069
|
|
|
@@ -9556,7 +9174,6 @@
|
|
|
9556
9174
|
if (typeof client.addAlgoliaAgent === 'function') {
|
|
9557
9175
|
client.addAlgoliaAgent('JS Helper (' + version + ')');
|
|
9558
9176
|
}
|
|
9559
|
-
|
|
9560
9177
|
this.setClient(client);
|
|
9561
9178
|
var opts = options || {};
|
|
9562
9179
|
opts.index = index;
|
|
@@ -9567,7 +9184,6 @@
|
|
|
9567
9184
|
this.derivedHelpers = [];
|
|
9568
9185
|
this._currentNbQueries = 0;
|
|
9569
9186
|
}
|
|
9570
|
-
|
|
9571
9187
|
inherits_1(AlgoliaSearchHelper, events);
|
|
9572
9188
|
|
|
9573
9189
|
/**
|
|
@@ -9575,19 +9191,22 @@
|
|
|
9575
9191
|
* method is called, it triggers a `search` event. The results will
|
|
9576
9192
|
* be available through the `result` event. If an error occurs, an
|
|
9577
9193
|
* `error` will be fired instead.
|
|
9578
|
-
* @return {AlgoliaSearchHelper}
|
|
9194
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9579
9195
|
* @fires search
|
|
9580
9196
|
* @fires result
|
|
9581
9197
|
* @fires error
|
|
9582
9198
|
* @chainable
|
|
9583
9199
|
*/
|
|
9584
|
-
AlgoliaSearchHelper.prototype.search = function() {
|
|
9585
|
-
this._search({
|
|
9200
|
+
AlgoliaSearchHelper.prototype.search = function () {
|
|
9201
|
+
this._search({
|
|
9202
|
+
onlyWithDerivedHelpers: false
|
|
9203
|
+
});
|
|
9586
9204
|
return this;
|
|
9587
9205
|
};
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9206
|
+
AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
|
|
9207
|
+
this._search({
|
|
9208
|
+
onlyWithDerivedHelpers: true
|
|
9209
|
+
});
|
|
9591
9210
|
return this;
|
|
9592
9211
|
};
|
|
9593
9212
|
|
|
@@ -9596,7 +9215,7 @@
|
|
|
9596
9215
|
* for the hits
|
|
9597
9216
|
* @return {object} Query Parameters
|
|
9598
9217
|
*/
|
|
9599
|
-
AlgoliaSearchHelper.prototype.getQuery = function() {
|
|
9218
|
+
AlgoliaSearchHelper.prototype.getQuery = function () {
|
|
9600
9219
|
var state = this.state;
|
|
9601
9220
|
return requestBuilder_1._getHitsSearchParams(state);
|
|
9602
9221
|
};
|
|
@@ -9608,7 +9227,7 @@
|
|
|
9608
9227
|
* same as a search call before calling searchOnce.
|
|
9609
9228
|
* @param {object} options can contain all the parameters that can be set to SearchParameters
|
|
9610
9229
|
* plus the index
|
|
9611
|
-
* @param {function} [
|
|
9230
|
+
* @param {function} [cb] optional callback executed when the response from the
|
|
9612
9231
|
* server is back.
|
|
9613
9232
|
* @return {promise|undefined} if a callback is passed the method returns undefined
|
|
9614
9233
|
* otherwise it returns a promise containing an object with two keys :
|
|
@@ -9637,41 +9256,32 @@
|
|
|
9637
9256
|
* // }
|
|
9638
9257
|
* }
|
|
9639
9258
|
*/
|
|
9640
|
-
AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
|
|
9259
|
+
AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
|
|
9641
9260
|
var tempState = !options ? this.state : this.state.setQueryParameters(options);
|
|
9642
9261
|
var queries = requestBuilder_1._getQueries(tempState.index, tempState);
|
|
9262
|
+
// eslint-disable-next-line consistent-this
|
|
9643
9263
|
var self = this;
|
|
9644
|
-
|
|
9645
9264
|
this._currentNbQueries++;
|
|
9646
|
-
|
|
9647
9265
|
this.emit('searchOnce', {
|
|
9648
9266
|
state: tempState
|
|
9649
9267
|
});
|
|
9650
|
-
|
|
9651
9268
|
if (cb) {
|
|
9652
|
-
this.client
|
|
9653
|
-
.
|
|
9654
|
-
.
|
|
9655
|
-
self.
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
self.emit('searchQueueEmpty');
|
|
9666
|
-
}
|
|
9667
|
-
|
|
9668
|
-
cb(err, null, tempState);
|
|
9669
|
-
});
|
|
9670
|
-
|
|
9269
|
+
this.client.search(queries).then(function (content) {
|
|
9270
|
+
self._currentNbQueries--;
|
|
9271
|
+
if (self._currentNbQueries === 0) {
|
|
9272
|
+
self.emit('searchQueueEmpty');
|
|
9273
|
+
}
|
|
9274
|
+
cb(null, new SearchResults_1(tempState, content.results), tempState);
|
|
9275
|
+
}).catch(function (err) {
|
|
9276
|
+
self._currentNbQueries--;
|
|
9277
|
+
if (self._currentNbQueries === 0) {
|
|
9278
|
+
self.emit('searchQueueEmpty');
|
|
9279
|
+
}
|
|
9280
|
+
cb(err, null, tempState);
|
|
9281
|
+
});
|
|
9671
9282
|
return undefined;
|
|
9672
9283
|
}
|
|
9673
|
-
|
|
9674
|
-
return this.client.search(queries).then(function(content) {
|
|
9284
|
+
return this.client.search(queries).then(function (content) {
|
|
9675
9285
|
self._currentNbQueries--;
|
|
9676
9286
|
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
9677
9287
|
return {
|
|
@@ -9679,14 +9289,14 @@
|
|
|
9679
9289
|
state: tempState,
|
|
9680
9290
|
_originalResponse: content
|
|
9681
9291
|
};
|
|
9682
|
-
}, function(e) {
|
|
9292
|
+
}, function (e) {
|
|
9683
9293
|
self._currentNbQueries--;
|
|
9684
9294
|
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
9685
9295
|
throw e;
|
|
9686
9296
|
});
|
|
9687
9297
|
};
|
|
9688
9298
|
|
|
9689
|
-
|
|
9299
|
+
/**
|
|
9690
9300
|
* Start the search for answers with the parameters set in the state.
|
|
9691
9301
|
* This method returns a promise.
|
|
9692
9302
|
* @param {Object} options - the options for answers API call
|
|
@@ -9697,7 +9307,8 @@
|
|
|
9697
9307
|
* @return {promise} the answer results
|
|
9698
9308
|
* @deprecated answers is deprecated and will be replaced with new initiatives
|
|
9699
9309
|
*/
|
|
9700
|
-
AlgoliaSearchHelper.prototype.findAnswers = function(options) {
|
|
9310
|
+
AlgoliaSearchHelper.prototype.findAnswers = function (options) {
|
|
9311
|
+
// eslint-disable-next-line no-console
|
|
9701
9312
|
console.warn('[algoliasearch-helper] answers is no longer supported');
|
|
9702
9313
|
var state = this.state;
|
|
9703
9314
|
var derivedHelper = this.derivedHelpers[0];
|
|
@@ -9705,21 +9316,12 @@
|
|
|
9705
9316
|
return Promise.resolve([]);
|
|
9706
9317
|
}
|
|
9707
9318
|
var derivedState = derivedHelper.getModifiedState(state);
|
|
9708
|
-
var data =
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
|
|
9715
|
-
'attributesToSnippet',
|
|
9716
|
-
'hitsPerPage',
|
|
9717
|
-
'restrictSearchableAttributes',
|
|
9718
|
-
'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
|
|
9719
|
-
])
|
|
9720
|
-
}
|
|
9721
|
-
);
|
|
9722
|
-
|
|
9319
|
+
var data = merge$1({
|
|
9320
|
+
attributesForPrediction: options.attributesForPrediction,
|
|
9321
|
+
nbHits: options.nbHits
|
|
9322
|
+
}, {
|
|
9323
|
+
params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), ['attributesToSnippet', 'hitsPerPage', 'restrictSearchableAttributes', 'snippetEllipsisText'])
|
|
9324
|
+
});
|
|
9723
9325
|
var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
|
|
9724
9326
|
if (typeof this.client.initIndex !== 'function') {
|
|
9725
9327
|
throw new Error(errorMessage);
|
|
@@ -9765,75 +9367,56 @@
|
|
|
9765
9367
|
* it in the generated query.
|
|
9766
9368
|
* @return {promise.<FacetSearchResult>} the results of the search
|
|
9767
9369
|
*/
|
|
9768
|
-
AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
|
|
9370
|
+
AlgoliaSearchHelper.prototype.searchForFacetValues = function (facet, query, maxFacetHits, userState) {
|
|
9769
9371
|
var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
|
|
9770
9372
|
var clientHasInitIndex = typeof this.client.initIndex === 'function';
|
|
9771
|
-
if (
|
|
9772
|
-
|
|
9773
|
-
!clientHasInitIndex &&
|
|
9774
|
-
typeof this.client.search !== 'function'
|
|
9775
|
-
) {
|
|
9776
|
-
throw new Error(
|
|
9777
|
-
'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
|
|
9778
|
-
);
|
|
9373
|
+
if (!clientHasSFFV && !clientHasInitIndex && typeof this.client.search !== 'function') {
|
|
9374
|
+
throw new Error('search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues');
|
|
9779
9375
|
}
|
|
9780
|
-
|
|
9781
9376
|
var state = this.state.setQueryParameters(userState || {});
|
|
9782
9377
|
var isDisjunctive = state.isDisjunctiveFacet(facet);
|
|
9783
9378
|
var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
|
|
9784
|
-
|
|
9785
9379
|
this._currentNbQueries++;
|
|
9380
|
+
// eslint-disable-next-line consistent-this
|
|
9786
9381
|
var self = this;
|
|
9787
9382
|
var searchForFacetValuesPromise;
|
|
9788
9383
|
// newer algoliasearch ^3.27.1 - ~4.0.0
|
|
9789
9384
|
if (clientHasSFFV) {
|
|
9790
|
-
searchForFacetValuesPromise = this.client.searchForFacetValues([
|
|
9791
|
-
|
|
9792
|
-
|
|
9385
|
+
searchForFacetValuesPromise = this.client.searchForFacetValues([{
|
|
9386
|
+
indexName: state.index,
|
|
9387
|
+
params: algoliaQuery
|
|
9388
|
+
}]);
|
|
9793
9389
|
// algoliasearch < 3.27.1
|
|
9794
9390
|
} else if (clientHasInitIndex) {
|
|
9795
|
-
searchForFacetValuesPromise = this.client
|
|
9796
|
-
.initIndex(state.index)
|
|
9797
|
-
.searchForFacetValues(algoliaQuery);
|
|
9391
|
+
searchForFacetValuesPromise = this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
|
|
9798
9392
|
// algoliasearch ~5.0.0
|
|
9799
9393
|
} else {
|
|
9800
9394
|
// @MAJOR only use client.search
|
|
9801
9395
|
delete algoliaQuery.facetName;
|
|
9802
|
-
searchForFacetValuesPromise = this.client
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
])
|
|
9811
|
-
.then(function processResponse(response) {
|
|
9812
|
-
return response.results[0];
|
|
9813
|
-
});
|
|
9396
|
+
searchForFacetValuesPromise = this.client.search([{
|
|
9397
|
+
type: 'facet',
|
|
9398
|
+
facet: facet,
|
|
9399
|
+
indexName: state.index,
|
|
9400
|
+
params: algoliaQuery
|
|
9401
|
+
}]).then(function processResponse(response) {
|
|
9402
|
+
return response.results[0];
|
|
9403
|
+
});
|
|
9814
9404
|
}
|
|
9815
|
-
|
|
9816
9405
|
this.emit('searchForFacetValues', {
|
|
9817
9406
|
state: state,
|
|
9818
9407
|
facet: facet,
|
|
9819
9408
|
query: query
|
|
9820
9409
|
});
|
|
9821
|
-
|
|
9822
9410
|
return searchForFacetValuesPromise.then(function addIsRefined(content) {
|
|
9823
9411
|
self._currentNbQueries--;
|
|
9824
9412
|
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
9825
|
-
|
|
9826
9413
|
content = Array.isArray(content) ? content[0] : content;
|
|
9827
|
-
|
|
9828
|
-
content.facetHits.forEach(function(f) {
|
|
9414
|
+
content.facetHits.forEach(function (f) {
|
|
9829
9415
|
f.escapedValue = escapeFacetValue$4(f.value);
|
|
9830
|
-
f.isRefined = isDisjunctive
|
|
9831
|
-
? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
|
|
9832
|
-
: state.isFacetRefined(facet, f.escapedValue);
|
|
9416
|
+
f.isRefined = isDisjunctive ? state.isDisjunctiveFacetRefined(facet, f.escapedValue) : state.isFacetRefined(facet, f.escapedValue);
|
|
9833
9417
|
});
|
|
9834
|
-
|
|
9835
9418
|
return content;
|
|
9836
|
-
}, function(e) {
|
|
9419
|
+
}, function (e) {
|
|
9837
9420
|
self._currentNbQueries--;
|
|
9838
9421
|
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
|
|
9839
9422
|
throw e;
|
|
@@ -9845,16 +9428,15 @@
|
|
|
9845
9428
|
*
|
|
9846
9429
|
* This method resets the current page to 0.
|
|
9847
9430
|
* @param {string} q the user query
|
|
9848
|
-
* @return {AlgoliaSearchHelper}
|
|
9431
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9849
9432
|
* @fires change
|
|
9850
9433
|
* @chainable
|
|
9851
9434
|
*/
|
|
9852
|
-
AlgoliaSearchHelper.prototype.setQuery = function(q) {
|
|
9435
|
+
AlgoliaSearchHelper.prototype.setQuery = function (q) {
|
|
9853
9436
|
this._change({
|
|
9854
9437
|
state: this.state.resetPage().setQuery(q),
|
|
9855
9438
|
isPageReset: true
|
|
9856
9439
|
});
|
|
9857
|
-
|
|
9858
9440
|
return this;
|
|
9859
9441
|
};
|
|
9860
9442
|
|
|
@@ -9866,7 +9448,7 @@
|
|
|
9866
9448
|
*
|
|
9867
9449
|
* This method resets the current page to 0.
|
|
9868
9450
|
* @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
|
|
9869
|
-
* @return {AlgoliaSearchHelper}
|
|
9451
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9870
9452
|
* @fires change
|
|
9871
9453
|
* @chainable
|
|
9872
9454
|
* @example
|
|
@@ -9881,12 +9463,11 @@
|
|
|
9881
9463
|
* return type === 'exclude' && attribute === 'category';
|
|
9882
9464
|
* }).search();
|
|
9883
9465
|
*/
|
|
9884
|
-
AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
|
|
9466
|
+
AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
|
|
9885
9467
|
this._change({
|
|
9886
9468
|
state: this.state.resetPage().clearRefinements(name),
|
|
9887
9469
|
isPageReset: true
|
|
9888
9470
|
});
|
|
9889
|
-
|
|
9890
9471
|
return this;
|
|
9891
9472
|
};
|
|
9892
9473
|
|
|
@@ -9894,16 +9475,15 @@
|
|
|
9894
9475
|
* Remove all the tag filters.
|
|
9895
9476
|
*
|
|
9896
9477
|
* This method resets the current page to 0.
|
|
9897
|
-
* @return {AlgoliaSearchHelper}
|
|
9478
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9898
9479
|
* @fires change
|
|
9899
9480
|
* @chainable
|
|
9900
9481
|
*/
|
|
9901
|
-
AlgoliaSearchHelper.prototype.clearTags = function() {
|
|
9482
|
+
AlgoliaSearchHelper.prototype.clearTags = function () {
|
|
9902
9483
|
this._change({
|
|
9903
9484
|
state: this.state.resetPage().clearTags(),
|
|
9904
9485
|
isPageReset: true
|
|
9905
9486
|
});
|
|
9906
|
-
|
|
9907
9487
|
return this;
|
|
9908
9488
|
};
|
|
9909
9489
|
|
|
@@ -9914,23 +9494,23 @@
|
|
|
9914
9494
|
* This method resets the current page to 0.
|
|
9915
9495
|
* @param {string} facet the facet to refine
|
|
9916
9496
|
* @param {string} value the associated value (will be converted to string)
|
|
9917
|
-
* @return {AlgoliaSearchHelper}
|
|
9497
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9918
9498
|
* @fires change
|
|
9919
9499
|
* @chainable
|
|
9920
9500
|
*/
|
|
9921
|
-
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
|
|
9501
|
+
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (facet, value) {
|
|
9922
9502
|
this._change({
|
|
9923
9503
|
state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
|
|
9924
9504
|
isPageReset: true
|
|
9925
9505
|
});
|
|
9926
|
-
|
|
9927
9506
|
return this;
|
|
9928
9507
|
};
|
|
9929
9508
|
|
|
9509
|
+
// eslint-disable-next-line valid-jsdoc
|
|
9930
9510
|
/**
|
|
9931
9511
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
|
|
9932
9512
|
*/
|
|
9933
|
-
AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
|
|
9513
|
+
AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
|
|
9934
9514
|
return this.addDisjunctiveFacetRefinement.apply(this, arguments);
|
|
9935
9515
|
};
|
|
9936
9516
|
|
|
@@ -9942,17 +9522,16 @@
|
|
|
9942
9522
|
* This method resets the current page to 0.
|
|
9943
9523
|
* @param {string} facet the facet name
|
|
9944
9524
|
* @param {string} path the hierarchical facet path
|
|
9945
|
-
* @return {AlgoliaSearchHelper}
|
|
9525
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9946
9526
|
* @throws Error if the facet is not defined or if the facet is refined
|
|
9947
9527
|
* @chainable
|
|
9948
9528
|
* @fires change
|
|
9949
9529
|
*/
|
|
9950
|
-
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet,
|
|
9530
|
+
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (facet, path) {
|
|
9951
9531
|
this._change({
|
|
9952
|
-
state: this.state.resetPage().addHierarchicalFacetRefinement(facet,
|
|
9532
|
+
state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
|
|
9953
9533
|
isPageReset: true
|
|
9954
9534
|
});
|
|
9955
|
-
|
|
9956
9535
|
return this;
|
|
9957
9536
|
};
|
|
9958
9537
|
|
|
@@ -9964,16 +9543,15 @@
|
|
|
9964
9543
|
* @param {string} attribute the attribute on which the numeric filter applies
|
|
9965
9544
|
* @param {string} operator the operator of the filter
|
|
9966
9545
|
* @param {number} value the value of the filter
|
|
9967
|
-
* @return {AlgoliaSearchHelper}
|
|
9546
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9968
9547
|
* @fires change
|
|
9969
9548
|
* @chainable
|
|
9970
9549
|
*/
|
|
9971
|
-
AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
|
|
9550
|
+
AlgoliaSearchHelper.prototype.addNumericRefinement = function (attribute, operator, value) {
|
|
9972
9551
|
this._change({
|
|
9973
9552
|
state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
|
|
9974
9553
|
isPageReset: true
|
|
9975
9554
|
});
|
|
9976
|
-
|
|
9977
9555
|
return this;
|
|
9978
9556
|
};
|
|
9979
9557
|
|
|
@@ -9984,27 +9562,26 @@
|
|
|
9984
9562
|
* This method resets the current page to 0.
|
|
9985
9563
|
* @param {string} facet the facet to refine
|
|
9986
9564
|
* @param {string} value the associated value (will be converted to string)
|
|
9987
|
-
* @return {AlgoliaSearchHelper}
|
|
9565
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9988
9566
|
* @fires change
|
|
9989
9567
|
* @chainable
|
|
9990
9568
|
*/
|
|
9991
|
-
AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
|
|
9569
|
+
AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
|
|
9992
9570
|
this._change({
|
|
9993
9571
|
state: this.state.resetPage().addFacetRefinement(facet, value),
|
|
9994
9572
|
isPageReset: true
|
|
9995
9573
|
});
|
|
9996
|
-
|
|
9997
9574
|
return this;
|
|
9998
9575
|
};
|
|
9999
9576
|
|
|
9577
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10000
9578
|
/**
|
|
10001
9579
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
|
|
10002
9580
|
*/
|
|
10003
|
-
AlgoliaSearchHelper.prototype.addRefine = function() {
|
|
9581
|
+
AlgoliaSearchHelper.prototype.addRefine = function () {
|
|
10004
9582
|
return this.addFacetRefinement.apply(this, arguments);
|
|
10005
9583
|
};
|
|
10006
9584
|
|
|
10007
|
-
|
|
10008
9585
|
/**
|
|
10009
9586
|
* Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
|
|
10010
9587
|
* filter is already set, it doesn't change the filters.
|
|
@@ -10012,23 +9589,23 @@
|
|
|
10012
9589
|
* This method resets the current page to 0.
|
|
10013
9590
|
* @param {string} facet the facet to refine
|
|
10014
9591
|
* @param {string} value the associated value (will be converted to string)
|
|
10015
|
-
* @return {AlgoliaSearchHelper}
|
|
9592
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10016
9593
|
* @fires change
|
|
10017
9594
|
* @chainable
|
|
10018
9595
|
*/
|
|
10019
|
-
AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
|
|
9596
|
+
AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
|
|
10020
9597
|
this._change({
|
|
10021
9598
|
state: this.state.resetPage().addExcludeRefinement(facet, value),
|
|
10022
9599
|
isPageReset: true
|
|
10023
9600
|
});
|
|
10024
|
-
|
|
10025
9601
|
return this;
|
|
10026
9602
|
};
|
|
10027
9603
|
|
|
9604
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10028
9605
|
/**
|
|
10029
9606
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
|
|
10030
9607
|
*/
|
|
10031
|
-
AlgoliaSearchHelper.prototype.addExclude = function() {
|
|
9608
|
+
AlgoliaSearchHelper.prototype.addExclude = function () {
|
|
10032
9609
|
return this.addFacetExclusion.apply(this, arguments);
|
|
10033
9610
|
};
|
|
10034
9611
|
|
|
@@ -10038,16 +9615,15 @@
|
|
|
10038
9615
|
*
|
|
10039
9616
|
* This method resets the current page to 0.
|
|
10040
9617
|
* @param {string} tag the tag to add to the filter
|
|
10041
|
-
* @return {AlgoliaSearchHelper}
|
|
9618
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10042
9619
|
* @fires change
|
|
10043
9620
|
* @chainable
|
|
10044
9621
|
*/
|
|
10045
|
-
AlgoliaSearchHelper.prototype.addTag = function(tag) {
|
|
9622
|
+
AlgoliaSearchHelper.prototype.addTag = function (tag) {
|
|
10046
9623
|
this._change({
|
|
10047
9624
|
state: this.state.resetPage().addTagRefinement(tag),
|
|
10048
9625
|
isPageReset: true
|
|
10049
9626
|
});
|
|
10050
|
-
|
|
10051
9627
|
return this;
|
|
10052
9628
|
};
|
|
10053
9629
|
|
|
@@ -10065,16 +9641,15 @@
|
|
|
10065
9641
|
* @param {string} attribute the attribute on which the numeric filter applies
|
|
10066
9642
|
* @param {string} [operator] the operator of the filter
|
|
10067
9643
|
* @param {number} [value] the value of the filter
|
|
10068
|
-
* @return {AlgoliaSearchHelper}
|
|
9644
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10069
9645
|
* @fires change
|
|
10070
9646
|
* @chainable
|
|
10071
9647
|
*/
|
|
10072
|
-
AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
|
|
9648
|
+
AlgoliaSearchHelper.prototype.removeNumericRefinement = function (attribute, operator, value) {
|
|
10073
9649
|
this._change({
|
|
10074
9650
|
state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
|
|
10075
9651
|
isPageReset: true
|
|
10076
9652
|
});
|
|
10077
|
-
|
|
10078
9653
|
return this;
|
|
10079
9654
|
};
|
|
10080
9655
|
|
|
@@ -10088,40 +9663,39 @@
|
|
|
10088
9663
|
* This method resets the current page to 0.
|
|
10089
9664
|
* @param {string} facet the facet to refine
|
|
10090
9665
|
* @param {string} [value] the associated value
|
|
10091
|
-
* @return {AlgoliaSearchHelper}
|
|
9666
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10092
9667
|
* @fires change
|
|
10093
9668
|
* @chainable
|
|
10094
9669
|
*/
|
|
10095
|
-
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
|
|
9670
|
+
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (facet, value) {
|
|
10096
9671
|
this._change({
|
|
10097
9672
|
state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
|
|
10098
9673
|
isPageReset: true
|
|
10099
9674
|
});
|
|
10100
|
-
|
|
10101
9675
|
return this;
|
|
10102
9676
|
};
|
|
10103
9677
|
|
|
9678
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10104
9679
|
/**
|
|
10105
9680
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
|
|
10106
9681
|
*/
|
|
10107
|
-
AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
|
|
9682
|
+
AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
|
|
10108
9683
|
return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
|
|
10109
9684
|
};
|
|
10110
9685
|
|
|
10111
9686
|
/**
|
|
10112
9687
|
* Removes the refinement set on a hierarchical facet.
|
|
10113
9688
|
* @param {string} facet the facet name
|
|
10114
|
-
* @return {AlgoliaSearchHelper}
|
|
9689
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10115
9690
|
* @throws Error if the facet is not defined or if the facet is not refined
|
|
10116
9691
|
* @fires change
|
|
10117
9692
|
* @chainable
|
|
10118
9693
|
*/
|
|
10119
|
-
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
|
|
9694
|
+
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (facet) {
|
|
10120
9695
|
this._change({
|
|
10121
9696
|
state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
|
|
10122
9697
|
isPageReset: true
|
|
10123
9698
|
});
|
|
10124
|
-
|
|
10125
9699
|
return this;
|
|
10126
9700
|
};
|
|
10127
9701
|
|
|
@@ -10135,23 +9709,23 @@
|
|
|
10135
9709
|
* This method resets the current page to 0.
|
|
10136
9710
|
* @param {string} facet the facet to refine
|
|
10137
9711
|
* @param {string} [value] the associated value
|
|
10138
|
-
* @return {AlgoliaSearchHelper}
|
|
9712
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10139
9713
|
* @fires change
|
|
10140
9714
|
* @chainable
|
|
10141
9715
|
*/
|
|
10142
|
-
AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
|
|
9716
|
+
AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
|
|
10143
9717
|
this._change({
|
|
10144
9718
|
state: this.state.resetPage().removeFacetRefinement(facet, value),
|
|
10145
9719
|
isPageReset: true
|
|
10146
9720
|
});
|
|
10147
|
-
|
|
10148
9721
|
return this;
|
|
10149
9722
|
};
|
|
10150
9723
|
|
|
9724
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10151
9725
|
/**
|
|
10152
9726
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
|
|
10153
9727
|
*/
|
|
10154
|
-
AlgoliaSearchHelper.prototype.removeRefine = function() {
|
|
9728
|
+
AlgoliaSearchHelper.prototype.removeRefine = function () {
|
|
10155
9729
|
return this.removeFacetRefinement.apply(this, arguments);
|
|
10156
9730
|
};
|
|
10157
9731
|
|
|
@@ -10165,23 +9739,23 @@
|
|
|
10165
9739
|
* This method resets the current page to 0.
|
|
10166
9740
|
* @param {string} facet the facet to refine
|
|
10167
9741
|
* @param {string} [value] the associated value
|
|
10168
|
-
* @return {AlgoliaSearchHelper}
|
|
9742
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10169
9743
|
* @fires change
|
|
10170
9744
|
* @chainable
|
|
10171
9745
|
*/
|
|
10172
|
-
AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
|
|
9746
|
+
AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
|
|
10173
9747
|
this._change({
|
|
10174
9748
|
state: this.state.resetPage().removeExcludeRefinement(facet, value),
|
|
10175
9749
|
isPageReset: true
|
|
10176
9750
|
});
|
|
10177
|
-
|
|
10178
9751
|
return this;
|
|
10179
9752
|
};
|
|
10180
9753
|
|
|
9754
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10181
9755
|
/**
|
|
10182
9756
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
|
|
10183
9757
|
*/
|
|
10184
|
-
AlgoliaSearchHelper.prototype.removeExclude = function() {
|
|
9758
|
+
AlgoliaSearchHelper.prototype.removeExclude = function () {
|
|
10185
9759
|
return this.removeFacetExclusion.apply(this, arguments);
|
|
10186
9760
|
};
|
|
10187
9761
|
|
|
@@ -10191,16 +9765,15 @@
|
|
|
10191
9765
|
*
|
|
10192
9766
|
* This method resets the current page to 0.
|
|
10193
9767
|
* @param {string} tag tag to remove from the filter
|
|
10194
|
-
* @return {AlgoliaSearchHelper}
|
|
9768
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10195
9769
|
* @fires change
|
|
10196
9770
|
* @chainable
|
|
10197
9771
|
*/
|
|
10198
|
-
AlgoliaSearchHelper.prototype.removeTag = function(tag) {
|
|
9772
|
+
AlgoliaSearchHelper.prototype.removeTag = function (tag) {
|
|
10199
9773
|
this._change({
|
|
10200
9774
|
state: this.state.resetPage().removeTagRefinement(tag),
|
|
10201
9775
|
isPageReset: true
|
|
10202
9776
|
});
|
|
10203
|
-
|
|
10204
9777
|
return this;
|
|
10205
9778
|
};
|
|
10206
9779
|
|
|
@@ -10211,23 +9784,23 @@
|
|
|
10211
9784
|
* This method resets the current page to 0.
|
|
10212
9785
|
* @param {string} facet the facet to refine
|
|
10213
9786
|
* @param {string} value the associated value
|
|
10214
|
-
* @return {AlgoliaSearchHelper}
|
|
9787
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10215
9788
|
* @fires change
|
|
10216
9789
|
* @chainable
|
|
10217
9790
|
*/
|
|
10218
|
-
AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
|
|
9791
|
+
AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
|
|
10219
9792
|
this._change({
|
|
10220
9793
|
state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
|
|
10221
9794
|
isPageReset: true
|
|
10222
9795
|
});
|
|
10223
|
-
|
|
10224
9796
|
return this;
|
|
10225
9797
|
};
|
|
10226
9798
|
|
|
9799
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10227
9800
|
/**
|
|
10228
9801
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
|
|
10229
9802
|
*/
|
|
10230
|
-
AlgoliaSearchHelper.prototype.toggleExclude = function() {
|
|
9803
|
+
AlgoliaSearchHelper.prototype.toggleExclude = function () {
|
|
10231
9804
|
return this.toggleFacetExclusion.apply(this, arguments);
|
|
10232
9805
|
};
|
|
10233
9806
|
|
|
@@ -10240,13 +9813,13 @@
|
|
|
10240
9813
|
* This method resets the current page to 0.
|
|
10241
9814
|
* @param {string} facet the facet to refine
|
|
10242
9815
|
* @param {string} value the associated value
|
|
10243
|
-
* @return {AlgoliaSearchHelper}
|
|
9816
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10244
9817
|
* @throws Error will throw an error if the facet is not declared in the settings of the helper
|
|
10245
9818
|
* @fires change
|
|
10246
9819
|
* @chainable
|
|
10247
9820
|
* @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
|
|
10248
9821
|
*/
|
|
10249
|
-
AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
|
|
9822
|
+
AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
|
|
10250
9823
|
return this.toggleFacetRefinement(facet, value);
|
|
10251
9824
|
};
|
|
10252
9825
|
|
|
@@ -10259,24 +9832,24 @@
|
|
|
10259
9832
|
* This method resets the current page to 0.
|
|
10260
9833
|
* @param {string} facet the facet to refine
|
|
10261
9834
|
* @param {string} value the associated value
|
|
10262
|
-
* @return {AlgoliaSearchHelper}
|
|
9835
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10263
9836
|
* @throws Error will throw an error if the facet is not declared in the settings of the helper
|
|
10264
9837
|
* @fires change
|
|
10265
9838
|
* @chainable
|
|
10266
9839
|
*/
|
|
10267
|
-
AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
|
|
9840
|
+
AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
|
|
10268
9841
|
this._change({
|
|
10269
9842
|
state: this.state.resetPage().toggleFacetRefinement(facet, value),
|
|
10270
9843
|
isPageReset: true
|
|
10271
9844
|
});
|
|
10272
|
-
|
|
10273
9845
|
return this;
|
|
10274
9846
|
};
|
|
10275
9847
|
|
|
9848
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10276
9849
|
/**
|
|
10277
9850
|
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
|
|
10278
9851
|
*/
|
|
10279
|
-
AlgoliaSearchHelper.prototype.toggleRefine = function() {
|
|
9852
|
+
AlgoliaSearchHelper.prototype.toggleRefine = function () {
|
|
10280
9853
|
return this.toggleFacetRefinement.apply(this, arguments);
|
|
10281
9854
|
};
|
|
10282
9855
|
|
|
@@ -10286,29 +9859,28 @@
|
|
|
10286
9859
|
*
|
|
10287
9860
|
* This method resets the current page to 0.
|
|
10288
9861
|
* @param {string} tag tag to remove or add
|
|
10289
|
-
* @return {AlgoliaSearchHelper}
|
|
9862
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10290
9863
|
* @fires change
|
|
10291
9864
|
* @chainable
|
|
10292
9865
|
*/
|
|
10293
|
-
AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
|
|
9866
|
+
AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
|
|
10294
9867
|
this._change({
|
|
10295
9868
|
state: this.state.resetPage().toggleTagRefinement(tag),
|
|
10296
9869
|
isPageReset: true
|
|
10297
9870
|
});
|
|
10298
|
-
|
|
10299
9871
|
return this;
|
|
10300
9872
|
};
|
|
10301
9873
|
|
|
10302
9874
|
/**
|
|
10303
9875
|
* Increments the page number by one.
|
|
10304
|
-
* @return {AlgoliaSearchHelper}
|
|
9876
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10305
9877
|
* @fires change
|
|
10306
9878
|
* @chainable
|
|
10307
9879
|
* @example
|
|
10308
9880
|
* helper.setPage(0).nextPage().getPage();
|
|
10309
9881
|
* // returns 1
|
|
10310
9882
|
*/
|
|
10311
|
-
AlgoliaSearchHelper.prototype.nextPage = function() {
|
|
9883
|
+
AlgoliaSearchHelper.prototype.nextPage = function () {
|
|
10312
9884
|
var page = this.state.page || 0;
|
|
10313
9885
|
return this.setPage(page + 1);
|
|
10314
9886
|
};
|
|
@@ -10316,28 +9888,30 @@
|
|
|
10316
9888
|
/**
|
|
10317
9889
|
* Decrements the page number by one.
|
|
10318
9890
|
* @fires change
|
|
10319
|
-
* @return {AlgoliaSearchHelper}
|
|
9891
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10320
9892
|
* @chainable
|
|
10321
9893
|
* @example
|
|
10322
9894
|
* helper.setPage(1).previousPage().getPage();
|
|
10323
9895
|
* // returns 0
|
|
10324
9896
|
*/
|
|
10325
|
-
AlgoliaSearchHelper.prototype.previousPage = function() {
|
|
9897
|
+
AlgoliaSearchHelper.prototype.previousPage = function () {
|
|
10326
9898
|
var page = this.state.page || 0;
|
|
10327
9899
|
return this.setPage(page - 1);
|
|
10328
9900
|
};
|
|
10329
9901
|
|
|
10330
9902
|
/**
|
|
10331
9903
|
* @private
|
|
9904
|
+
* @param {number} page The page number
|
|
9905
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
9906
|
+
* @chainable
|
|
9907
|
+
* @fires change
|
|
10332
9908
|
*/
|
|
10333
9909
|
function setCurrentPage(page) {
|
|
10334
9910
|
if (page < 0) throw new Error('Page requested below 0.');
|
|
10335
|
-
|
|
10336
9911
|
this._change({
|
|
10337
9912
|
state: this.state.setPage(page),
|
|
10338
9913
|
isPageReset: false
|
|
10339
9914
|
});
|
|
10340
|
-
|
|
10341
9915
|
return this;
|
|
10342
9916
|
}
|
|
10343
9917
|
|
|
@@ -10345,7 +9919,7 @@
|
|
|
10345
9919
|
* Change the current page
|
|
10346
9920
|
* @deprecated
|
|
10347
9921
|
* @param {number} page The page number
|
|
10348
|
-
* @return {AlgoliaSearchHelper}
|
|
9922
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10349
9923
|
* @fires change
|
|
10350
9924
|
* @chainable
|
|
10351
9925
|
*/
|
|
@@ -10355,7 +9929,7 @@
|
|
|
10355
9929
|
* Updates the current page.
|
|
10356
9930
|
* @function
|
|
10357
9931
|
* @param {number} page The page number
|
|
10358
|
-
* @return {AlgoliaSearchHelper}
|
|
9932
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10359
9933
|
* @fires change
|
|
10360
9934
|
* @chainable
|
|
10361
9935
|
*/
|
|
@@ -10366,16 +9940,15 @@
|
|
|
10366
9940
|
*
|
|
10367
9941
|
* This method resets the current page to 0.
|
|
10368
9942
|
* @param {string} name the index name
|
|
10369
|
-
* @return {AlgoliaSearchHelper}
|
|
9943
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10370
9944
|
* @fires change
|
|
10371
9945
|
* @chainable
|
|
10372
9946
|
*/
|
|
10373
|
-
AlgoliaSearchHelper.prototype.setIndex = function(name) {
|
|
9947
|
+
AlgoliaSearchHelper.prototype.setIndex = function (name) {
|
|
10374
9948
|
this._change({
|
|
10375
9949
|
state: this.state.resetPage().setIndex(name),
|
|
10376
9950
|
isPageReset: true
|
|
10377
9951
|
});
|
|
10378
|
-
|
|
10379
9952
|
return this;
|
|
10380
9953
|
};
|
|
10381
9954
|
|
|
@@ -10390,34 +9963,32 @@
|
|
|
10390
9963
|
* This method resets the current page to 0.
|
|
10391
9964
|
* @param {string} parameter name of the parameter to update
|
|
10392
9965
|
* @param {any} value new value of the parameter
|
|
10393
|
-
* @return {AlgoliaSearchHelper}
|
|
9966
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10394
9967
|
* @fires change
|
|
10395
9968
|
* @chainable
|
|
10396
9969
|
* @example
|
|
10397
9970
|
* helper.setQueryParameter('hitsPerPage', 20).search();
|
|
10398
9971
|
*/
|
|
10399
|
-
AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
|
|
9972
|
+
AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
|
|
10400
9973
|
this._change({
|
|
10401
9974
|
state: this.state.resetPage().setQueryParameter(parameter, value),
|
|
10402
9975
|
isPageReset: true
|
|
10403
9976
|
});
|
|
10404
|
-
|
|
10405
9977
|
return this;
|
|
10406
9978
|
};
|
|
10407
9979
|
|
|
10408
9980
|
/**
|
|
10409
9981
|
* Set the whole state (warning: will erase previous state)
|
|
10410
9982
|
* @param {SearchParameters} newState the whole new state
|
|
10411
|
-
* @return {AlgoliaSearchHelper}
|
|
9983
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10412
9984
|
* @fires change
|
|
10413
9985
|
* @chainable
|
|
10414
9986
|
*/
|
|
10415
|
-
AlgoliaSearchHelper.prototype.setState = function(newState) {
|
|
9987
|
+
AlgoliaSearchHelper.prototype.setState = function (newState) {
|
|
10416
9988
|
this._change({
|
|
10417
9989
|
state: SearchParameters_1.make(newState),
|
|
10418
9990
|
isPageReset: false
|
|
10419
9991
|
});
|
|
10420
|
-
|
|
10421
9992
|
return this;
|
|
10422
9993
|
};
|
|
10423
9994
|
|
|
@@ -10426,7 +9997,7 @@
|
|
|
10426
9997
|
* Do not use this method unless you know what you are doing. (see the example
|
|
10427
9998
|
* for a legit use case)
|
|
10428
9999
|
* @param {SearchParameters} newState the whole new state
|
|
10429
|
-
* @return {AlgoliaSearchHelper}
|
|
10000
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10430
10001
|
* @example
|
|
10431
10002
|
* helper.on('change', function(state){
|
|
10432
10003
|
* // In this function you might want to find a way to store the state in the url/history
|
|
@@ -10438,7 +10009,7 @@
|
|
|
10438
10009
|
* }
|
|
10439
10010
|
* @chainable
|
|
10440
10011
|
*/
|
|
10441
|
-
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
|
|
10012
|
+
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function (newState) {
|
|
10442
10013
|
this.state = new SearchParameters_1(newState);
|
|
10443
10014
|
return this;
|
|
10444
10015
|
};
|
|
@@ -10466,7 +10037,7 @@
|
|
|
10466
10037
|
* helper.hasRefinements('categories'); // true
|
|
10467
10038
|
*
|
|
10468
10039
|
*/
|
|
10469
|
-
AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
|
|
10040
|
+
AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
|
|
10470
10041
|
if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
|
|
10471
10042
|
return true;
|
|
10472
10043
|
} else if (this.state.isConjunctiveFacet(attribute)) {
|
|
@@ -10491,7 +10062,7 @@
|
|
|
10491
10062
|
*
|
|
10492
10063
|
* @param {string} facet name of the attribute for used for faceting
|
|
10493
10064
|
* @param {string} [value] optional value. If passed will test that this value
|
|
10494
|
-
|
|
10065
|
+
* is filtering the given facet.
|
|
10495
10066
|
* @return {boolean} true if refined
|
|
10496
10067
|
* @example
|
|
10497
10068
|
* helper.isExcludeRefined('color'); // false
|
|
@@ -10504,45 +10075,45 @@
|
|
|
10504
10075
|
* helper.isExcludeRefined('color', 'blue') // false
|
|
10505
10076
|
* helper.isExcludeRefined('color', 'red') // true
|
|
10506
10077
|
*/
|
|
10507
|
-
AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
|
|
10078
|
+
AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
|
|
10508
10079
|
return this.state.isExcludeRefined(facet, value);
|
|
10509
10080
|
};
|
|
10510
10081
|
|
|
10082
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10511
10083
|
/**
|
|
10512
10084
|
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
|
|
10513
10085
|
*/
|
|
10514
|
-
AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
|
|
10086
|
+
AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
|
|
10515
10087
|
return this.state.isDisjunctiveFacetRefined(facet, value);
|
|
10516
10088
|
};
|
|
10517
10089
|
|
|
10518
10090
|
/**
|
|
10519
10091
|
* Check if the string is a currently filtering tag.
|
|
10520
10092
|
* @param {string} tag tag to check
|
|
10521
|
-
* @return {boolean}
|
|
10093
|
+
* @return {boolean} true if the tag is currently refined
|
|
10522
10094
|
*/
|
|
10523
|
-
AlgoliaSearchHelper.prototype.hasTag = function(tag) {
|
|
10095
|
+
AlgoliaSearchHelper.prototype.hasTag = function (tag) {
|
|
10524
10096
|
return this.state.isTagRefined(tag);
|
|
10525
10097
|
};
|
|
10526
10098
|
|
|
10099
|
+
// eslint-disable-next-line valid-jsdoc
|
|
10527
10100
|
/**
|
|
10528
10101
|
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
|
|
10529
10102
|
*/
|
|
10530
|
-
AlgoliaSearchHelper.prototype.isTagRefined = function() {
|
|
10103
|
+
AlgoliaSearchHelper.prototype.isTagRefined = function () {
|
|
10531
10104
|
return this.hasTagRefinements.apply(this, arguments);
|
|
10532
10105
|
};
|
|
10533
10106
|
|
|
10534
|
-
|
|
10535
10107
|
/**
|
|
10536
10108
|
* Get the name of the currently used index.
|
|
10537
|
-
* @return {string}
|
|
10109
|
+
* @return {string} name of the index
|
|
10538
10110
|
* @example
|
|
10539
10111
|
* helper.setIndex('highestPrice_products').getIndex();
|
|
10540
10112
|
* // returns 'highestPrice_products'
|
|
10541
10113
|
*/
|
|
10542
|
-
AlgoliaSearchHelper.prototype.getIndex = function() {
|
|
10114
|
+
AlgoliaSearchHelper.prototype.getIndex = function () {
|
|
10543
10115
|
return this.state.index;
|
|
10544
10116
|
};
|
|
10545
|
-
|
|
10546
10117
|
function getCurrentPage() {
|
|
10547
10118
|
return this.state.page;
|
|
10548
10119
|
}
|
|
@@ -10565,7 +10136,7 @@
|
|
|
10565
10136
|
*
|
|
10566
10137
|
* @return {string[]} The list of tags currently set.
|
|
10567
10138
|
*/
|
|
10568
|
-
AlgoliaSearchHelper.prototype.getTags = function() {
|
|
10139
|
+
AlgoliaSearchHelper.prototype.getTags = function () {
|
|
10569
10140
|
return this.state.tagRefinements;
|
|
10570
10141
|
};
|
|
10571
10142
|
|
|
@@ -10613,50 +10184,41 @@
|
|
|
10613
10184
|
* // }
|
|
10614
10185
|
* // ]
|
|
10615
10186
|
*/
|
|
10616
|
-
AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
|
|
10187
|
+
AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
|
|
10617
10188
|
var refinements = [];
|
|
10618
|
-
|
|
10619
10189
|
if (this.state.isConjunctiveFacet(facetName)) {
|
|
10620
10190
|
var conjRefinements = this.state.getConjunctiveRefinements(facetName);
|
|
10621
|
-
|
|
10622
|
-
conjRefinements.forEach(function(r) {
|
|
10191
|
+
conjRefinements.forEach(function (r) {
|
|
10623
10192
|
refinements.push({
|
|
10624
10193
|
value: r,
|
|
10625
10194
|
type: 'conjunctive'
|
|
10626
10195
|
});
|
|
10627
10196
|
});
|
|
10628
|
-
|
|
10629
10197
|
var excludeRefinements = this.state.getExcludeRefinements(facetName);
|
|
10630
|
-
|
|
10631
|
-
excludeRefinements.forEach(function(r) {
|
|
10198
|
+
excludeRefinements.forEach(function (r) {
|
|
10632
10199
|
refinements.push({
|
|
10633
10200
|
value: r,
|
|
10634
10201
|
type: 'exclude'
|
|
10635
10202
|
});
|
|
10636
10203
|
});
|
|
10637
10204
|
} else if (this.state.isDisjunctiveFacet(facetName)) {
|
|
10638
|
-
var
|
|
10639
|
-
|
|
10640
|
-
disjRefinements.forEach(function(r) {
|
|
10205
|
+
var disjunctiveRefinements = this.state.getDisjunctiveRefinements(facetName);
|
|
10206
|
+
disjunctiveRefinements.forEach(function (r) {
|
|
10641
10207
|
refinements.push({
|
|
10642
10208
|
value: r,
|
|
10643
10209
|
type: 'disjunctive'
|
|
10644
10210
|
});
|
|
10645
10211
|
});
|
|
10646
10212
|
}
|
|
10647
|
-
|
|
10648
10213
|
var numericRefinements = this.state.getNumericRefinements(facetName);
|
|
10649
|
-
|
|
10650
|
-
Object.keys(numericRefinements).forEach(function(operator) {
|
|
10214
|
+
Object.keys(numericRefinements).forEach(function (operator) {
|
|
10651
10215
|
var value = numericRefinements[operator];
|
|
10652
|
-
|
|
10653
10216
|
refinements.push({
|
|
10654
10217
|
value: value,
|
|
10655
10218
|
operator: operator,
|
|
10656
10219
|
type: 'numeric'
|
|
10657
10220
|
});
|
|
10658
10221
|
});
|
|
10659
|
-
|
|
10660
10222
|
return refinements;
|
|
10661
10223
|
};
|
|
10662
10224
|
|
|
@@ -10666,7 +10228,7 @@
|
|
|
10666
10228
|
* @param {string} operator operator applied on the refined values
|
|
10667
10229
|
* @return {Array.<number|number[]>} refined values
|
|
10668
10230
|
*/
|
|
10669
|
-
AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
|
|
10231
|
+
AlgoliaSearchHelper.prototype.getNumericRefinement = function (attribute, operator) {
|
|
10670
10232
|
return this.state.getNumericRefinement(attribute, operator);
|
|
10671
10233
|
};
|
|
10672
10234
|
|
|
@@ -10675,7 +10237,7 @@
|
|
|
10675
10237
|
* @param {string} facetName Hierarchical facet name
|
|
10676
10238
|
* @return {array.<string>} the path as an array of string
|
|
10677
10239
|
*/
|
|
10678
|
-
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
|
|
10240
|
+
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (facetName) {
|
|
10679
10241
|
return this.state.getHierarchicalFacetBreadcrumb(facetName);
|
|
10680
10242
|
};
|
|
10681
10243
|
|
|
@@ -10684,72 +10246,60 @@
|
|
|
10684
10246
|
/**
|
|
10685
10247
|
* Perform the underlying queries
|
|
10686
10248
|
* @private
|
|
10687
|
-
* @
|
|
10249
|
+
* @param {object} options options for the query
|
|
10250
|
+
* @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
|
|
10251
|
+
* @return {undefined} does not return anything
|
|
10688
10252
|
* @fires search
|
|
10689
10253
|
* @fires result
|
|
10690
10254
|
* @fires error
|
|
10691
10255
|
*/
|
|
10692
|
-
AlgoliaSearchHelper.prototype._search = function(options) {
|
|
10256
|
+
AlgoliaSearchHelper.prototype._search = function (options) {
|
|
10693
10257
|
var state = this.state;
|
|
10694
10258
|
var states = [];
|
|
10695
10259
|
var mainQueries = [];
|
|
10696
|
-
|
|
10697
10260
|
if (!options.onlyWithDerivedHelpers) {
|
|
10698
10261
|
mainQueries = requestBuilder_1._getQueries(state.index, state);
|
|
10699
|
-
|
|
10700
10262
|
states.push({
|
|
10701
10263
|
state: state,
|
|
10702
10264
|
queriesCount: mainQueries.length,
|
|
10703
10265
|
helper: this
|
|
10704
10266
|
});
|
|
10705
|
-
|
|
10706
10267
|
this.emit('search', {
|
|
10707
10268
|
state: state,
|
|
10708
10269
|
results: this.lastResults
|
|
10709
10270
|
});
|
|
10710
10271
|
}
|
|
10711
|
-
|
|
10712
|
-
var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
|
|
10272
|
+
var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
|
|
10713
10273
|
var derivedState = derivedHelper.getModifiedState(state);
|
|
10714
|
-
var derivedStateQueries = derivedState.index
|
|
10715
|
-
? requestBuilder_1._getQueries(derivedState.index, derivedState)
|
|
10716
|
-
: [];
|
|
10717
|
-
|
|
10274
|
+
var derivedStateQueries = derivedState.index ? requestBuilder_1._getQueries(derivedState.index, derivedState) : [];
|
|
10718
10275
|
states.push({
|
|
10719
10276
|
state: derivedState,
|
|
10720
10277
|
queriesCount: derivedStateQueries.length,
|
|
10721
10278
|
helper: derivedHelper
|
|
10722
10279
|
});
|
|
10723
|
-
|
|
10724
10280
|
derivedHelper.emit('search', {
|
|
10725
10281
|
state: derivedState,
|
|
10726
10282
|
results: derivedHelper.lastResults
|
|
10727
10283
|
});
|
|
10728
|
-
|
|
10729
10284
|
return derivedStateQueries;
|
|
10730
10285
|
});
|
|
10731
|
-
|
|
10732
10286
|
var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
|
|
10733
|
-
|
|
10734
10287
|
var queryId = this._queryId++;
|
|
10735
10288
|
this._currentNbQueries++;
|
|
10736
|
-
|
|
10737
10289
|
if (!queries.length) {
|
|
10738
|
-
return Promise.resolve({
|
|
10739
|
-
|
|
10740
|
-
);
|
|
10290
|
+
return Promise.resolve({
|
|
10291
|
+
results: []
|
|
10292
|
+
}).then(this._dispatchAlgoliaResponse.bind(this, states, queryId));
|
|
10741
10293
|
}
|
|
10742
|
-
|
|
10743
10294
|
try {
|
|
10744
|
-
this.client.search(queries)
|
|
10745
|
-
.then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
|
|
10746
|
-
.catch(this._dispatchAlgoliaError.bind(this, queryId));
|
|
10295
|
+
this.client.search(queries).then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
|
|
10747
10296
|
} catch (error) {
|
|
10748
10297
|
// If we reach this part, we're in an internal error state
|
|
10749
10298
|
this.emit('error', {
|
|
10750
10299
|
error: error
|
|
10751
10300
|
});
|
|
10752
10301
|
}
|
|
10302
|
+
return undefined;
|
|
10753
10303
|
};
|
|
10754
10304
|
|
|
10755
10305
|
/**
|
|
@@ -10757,33 +10307,27 @@
|
|
|
10757
10307
|
* usable object that merge the results of all the batch requests. It will dispatch
|
|
10758
10308
|
* over the different helper + derived helpers (when there are some).
|
|
10759
10309
|
* @private
|
|
10760
|
-
* @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
|
|
10761
|
-
* state state used for to generate the request
|
|
10310
|
+
* @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
|
|
10762
10311
|
* @param {number} queryId id of the current request
|
|
10763
10312
|
* @param {object} content content of the response
|
|
10764
10313
|
* @return {undefined}
|
|
10765
10314
|
*/
|
|
10766
|
-
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
|
|
10767
|
-
//
|
|
10315
|
+
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (states, queryId, content) {
|
|
10316
|
+
// @TODO remove the number of outdated queries discarded instead of just one
|
|
10768
10317
|
|
|
10769
10318
|
if (queryId < this._lastQueryIdReceived) {
|
|
10770
10319
|
// Outdated answer
|
|
10771
10320
|
return;
|
|
10772
10321
|
}
|
|
10773
|
-
|
|
10774
|
-
this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
|
|
10322
|
+
this._currentNbQueries -= queryId - this._lastQueryIdReceived;
|
|
10775
10323
|
this._lastQueryIdReceived = queryId;
|
|
10776
|
-
|
|
10777
10324
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
10778
|
-
|
|
10779
10325
|
var results = content.results.slice();
|
|
10780
|
-
|
|
10781
|
-
states.forEach(function(s) {
|
|
10326
|
+
states.forEach(function (s) {
|
|
10782
10327
|
var state = s.state;
|
|
10783
10328
|
var queriesCount = s.queriesCount;
|
|
10784
10329
|
var helper = s.helper;
|
|
10785
10330
|
var specificResults = results.splice(0, queriesCount);
|
|
10786
|
-
|
|
10787
10331
|
if (!state.index) {
|
|
10788
10332
|
helper.emit('result', {
|
|
10789
10333
|
results: null,
|
|
@@ -10791,57 +10335,43 @@
|
|
|
10791
10335
|
});
|
|
10792
10336
|
return;
|
|
10793
10337
|
}
|
|
10794
|
-
|
|
10795
|
-
var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
|
|
10796
|
-
|
|
10338
|
+
helper.lastResults = new SearchResults_1(state, specificResults);
|
|
10797
10339
|
helper.emit('result', {
|
|
10798
|
-
results:
|
|
10340
|
+
results: helper.lastResults,
|
|
10799
10341
|
state: state
|
|
10800
10342
|
});
|
|
10801
10343
|
});
|
|
10802
10344
|
};
|
|
10803
|
-
|
|
10804
|
-
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
|
|
10345
|
+
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (queryId, error) {
|
|
10805
10346
|
if (queryId < this._lastQueryIdReceived) {
|
|
10806
10347
|
// Outdated answer
|
|
10807
10348
|
return;
|
|
10808
10349
|
}
|
|
10809
|
-
|
|
10810
10350
|
this._currentNbQueries -= queryId - this._lastQueryIdReceived;
|
|
10811
10351
|
this._lastQueryIdReceived = queryId;
|
|
10812
|
-
|
|
10813
10352
|
this.emit('error', {
|
|
10814
10353
|
error: error
|
|
10815
10354
|
});
|
|
10816
|
-
|
|
10817
10355
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
10818
10356
|
};
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
return query ||
|
|
10822
|
-
facetFilters.length !== 0 ||
|
|
10823
|
-
numericFilters.length !== 0 ||
|
|
10824
|
-
tagFilters.length !== 0;
|
|
10357
|
+
AlgoliaSearchHelper.prototype.containsRefinement = function (query, facetFilters, numericFilters, tagFilters) {
|
|
10358
|
+
return query || facetFilters.length !== 0 || numericFilters.length !== 0 || tagFilters.length !== 0;
|
|
10825
10359
|
};
|
|
10826
10360
|
|
|
10827
10361
|
/**
|
|
10828
10362
|
* Test if there are some disjunctive refinements on the facet
|
|
10829
10363
|
* @private
|
|
10830
10364
|
* @param {string} facet the attribute to test
|
|
10831
|
-
* @return {boolean}
|
|
10365
|
+
* @return {boolean} true if there are refinements on this attribute
|
|
10832
10366
|
*/
|
|
10833
|
-
AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
|
|
10834
|
-
return this.state.disjunctiveRefinements[facet] &&
|
|
10835
|
-
this.state.disjunctiveRefinements[facet].length > 0;
|
|
10367
|
+
AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
|
|
10368
|
+
return this.state.disjunctiveRefinements[facet] && this.state.disjunctiveRefinements[facet].length > 0;
|
|
10836
10369
|
};
|
|
10837
|
-
|
|
10838
|
-
AlgoliaSearchHelper.prototype._change = function(event) {
|
|
10370
|
+
AlgoliaSearchHelper.prototype._change = function (event) {
|
|
10839
10371
|
var state = event.state;
|
|
10840
10372
|
var isPageReset = event.isPageReset;
|
|
10841
|
-
|
|
10842
10373
|
if (state !== this.state) {
|
|
10843
10374
|
this.state = state;
|
|
10844
|
-
|
|
10845
10375
|
this.emit('change', {
|
|
10846
10376
|
state: this.state,
|
|
10847
10377
|
results: this.lastResults,
|
|
@@ -10852,10 +10382,10 @@
|
|
|
10852
10382
|
|
|
10853
10383
|
/**
|
|
10854
10384
|
* Clears the cache of the underlying Algolia client.
|
|
10855
|
-
* @return {AlgoliaSearchHelper}
|
|
10385
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10856
10386
|
*/
|
|
10857
|
-
AlgoliaSearchHelper.prototype.clearCache = function() {
|
|
10858
|
-
this.client.clearCache
|
|
10387
|
+
AlgoliaSearchHelper.prototype.clearCache = function () {
|
|
10388
|
+
if (this.client.clearCache) this.client.clearCache();
|
|
10859
10389
|
return this;
|
|
10860
10390
|
};
|
|
10861
10391
|
|
|
@@ -10863,24 +10393,22 @@
|
|
|
10863
10393
|
* Updates the internal client instance. If the reference of the clients
|
|
10864
10394
|
* are equal then no update is actually done.
|
|
10865
10395
|
* @param {AlgoliaSearch} newClient an AlgoliaSearch client
|
|
10866
|
-
* @return {AlgoliaSearchHelper}
|
|
10396
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10867
10397
|
*/
|
|
10868
|
-
AlgoliaSearchHelper.prototype.setClient = function(newClient) {
|
|
10398
|
+
AlgoliaSearchHelper.prototype.setClient = function (newClient) {
|
|
10869
10399
|
if (this.client === newClient) return this;
|
|
10870
|
-
|
|
10871
10400
|
if (typeof newClient.addAlgoliaAgent === 'function') {
|
|
10872
10401
|
newClient.addAlgoliaAgent('JS Helper (' + version + ')');
|
|
10873
10402
|
}
|
|
10874
10403
|
this.client = newClient;
|
|
10875
|
-
|
|
10876
10404
|
return this;
|
|
10877
10405
|
};
|
|
10878
10406
|
|
|
10879
10407
|
/**
|
|
10880
10408
|
* Gets the instance of the currently used client.
|
|
10881
|
-
* @return {AlgoliaSearch}
|
|
10409
|
+
* @return {AlgoliaSearch} the currently used client
|
|
10882
10410
|
*/
|
|
10883
|
-
AlgoliaSearchHelper.prototype.getClient = function() {
|
|
10411
|
+
AlgoliaSearchHelper.prototype.getClient = function () {
|
|
10884
10412
|
return this.client;
|
|
10885
10413
|
};
|
|
10886
10414
|
|
|
@@ -10901,9 +10429,9 @@
|
|
|
10901
10429
|
* and the SearchParameters that is returned by the call of the
|
|
10902
10430
|
* parameter function.
|
|
10903
10431
|
* @param {function} fn SearchParameters -> SearchParameters
|
|
10904
|
-
* @return {DerivedHelper}
|
|
10432
|
+
* @return {DerivedHelper} a new DerivedHelper
|
|
10905
10433
|
*/
|
|
10906
|
-
AlgoliaSearchHelper.prototype.derive = function(fn) {
|
|
10434
|
+
AlgoliaSearchHelper.prototype.derive = function (fn) {
|
|
10907
10435
|
var derivedHelper = new DerivedHelper_1(this, fn);
|
|
10908
10436
|
this.derivedHelpers.push(derivedHelper);
|
|
10909
10437
|
return derivedHelper;
|
|
@@ -10913,10 +10441,11 @@
|
|
|
10913
10441
|
* This method detaches a derived Helper from the main one. Prefer using the one from the
|
|
10914
10442
|
* derived helper itself, to remove the event listeners too.
|
|
10915
10443
|
* @private
|
|
10916
|
-
* @
|
|
10444
|
+
* @param {DerivedHelper} derivedHelper the derived helper to detach
|
|
10445
|
+
* @return {undefined} nothing is returned
|
|
10917
10446
|
* @throws Error
|
|
10918
10447
|
*/
|
|
10919
|
-
AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
|
|
10448
|
+
AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
|
|
10920
10449
|
var pos = this.derivedHelpers.indexOf(derivedHelper);
|
|
10921
10450
|
if (pos === -1) throw new Error('Derived helper already detached');
|
|
10922
10451
|
this.derivedHelpers.splice(pos, 1);
|
|
@@ -10926,7 +10455,7 @@
|
|
|
10926
10455
|
* This method returns true if there is currently at least one on-going search.
|
|
10927
10456
|
* @return {boolean} true if there is a search pending
|
|
10928
10457
|
*/
|
|
10929
|
-
AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
|
|
10458
|
+
AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
|
|
10930
10459
|
return this._currentNbQueries > 0;
|
|
10931
10460
|
};
|
|
10932
10461
|
|
|
@@ -10977,7 +10506,7 @@
|
|
|
10977
10506
|
* @param {AlgoliaSearch} client an AlgoliaSearch client
|
|
10978
10507
|
* @param {string} index the name of the index to query
|
|
10979
10508
|
* @param {SearchParameters|object} opts an object defining the initial config of the search. It doesn't have to be a {SearchParameters}, just an object containing the properties you need from it.
|
|
10980
|
-
* @return {AlgoliaSearchHelper}
|
|
10509
|
+
* @return {AlgoliaSearchHelper} The helper instance
|
|
10981
10510
|
*/
|
|
10982
10511
|
function algoliasearchHelper(client, index, opts) {
|
|
10983
10512
|
return new algoliasearch_helper(client, index, opts);
|
|
@@ -11010,7 +10539,6 @@
|
|
|
11010
10539
|
* @type {SearchResults}
|
|
11011
10540
|
*/
|
|
11012
10541
|
algoliasearchHelper.SearchResults = SearchResults_1;
|
|
11013
|
-
|
|
11014
10542
|
var algoliasearchHelper_1 = algoliasearchHelper;
|
|
11015
10543
|
|
|
11016
10544
|
var withUsage$l = createDocumentationMessageGenerator({
|
|
@@ -12365,7 +11893,7 @@
|
|
|
12365
11893
|
return obj;
|
|
12366
11894
|
};
|
|
12367
11895
|
|
|
12368
|
-
var merge$
|
|
11896
|
+
var merge$2 = function merge(target, source, options) {
|
|
12369
11897
|
/* eslint no-param-reassign: 0 */
|
|
12370
11898
|
if (!source) {
|
|
12371
11899
|
return target;
|
|
@@ -12569,7 +12097,7 @@
|
|
|
12569
12097
|
isBuffer: isBuffer,
|
|
12570
12098
|
isRegExp: isRegExp,
|
|
12571
12099
|
maybeMap: maybeMap,
|
|
12572
|
-
merge: merge$
|
|
12100
|
+
merge: merge$2
|
|
12573
12101
|
};
|
|
12574
12102
|
|
|
12575
12103
|
var has$1 = Object.prototype.hasOwnProperty;
|
|
@@ -13472,9 +13000,17 @@
|
|
|
13472
13000
|
return function (_ref) {
|
|
13473
13001
|
var instantSearchInstance = _ref.instantSearchInstance;
|
|
13474
13002
|
function topLevelCreateURL(nextState) {
|
|
13003
|
+
var previousUiState =
|
|
13004
|
+
// If only the mainIndex is initialized, we don't yet know what other
|
|
13005
|
+
// index widgets are used. Therefore we fall back to the initialUiState.
|
|
13006
|
+
// We can't indiscriminately use the initialUiState because then we
|
|
13007
|
+
// reintroduce state that was changed by the user.
|
|
13008
|
+
// When there are no widgets, we are sure the user can't yet have made
|
|
13009
|
+
// any changes.
|
|
13010
|
+
instantSearchInstance.mainIndex.getWidgets().length === 0 ? instantSearchInstance._initialUiState : instantSearchInstance.mainIndex.getWidgetUiState({});
|
|
13475
13011
|
var uiState = Object.keys(nextState).reduce(function (acc, indexId) {
|
|
13476
13012
|
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, indexId, nextState[indexId]));
|
|
13477
|
-
},
|
|
13013
|
+
}, previousUiState);
|
|
13478
13014
|
var route = stateMapping.stateToRoute(uiState);
|
|
13479
13015
|
return router.createURL(route);
|
|
13480
13016
|
}
|
|
@@ -13640,6 +13176,9 @@
|
|
|
13640
13176
|
return localParent;
|
|
13641
13177
|
},
|
|
13642
13178
|
createURL: function createURL(nextState) {
|
|
13179
|
+
if (typeof nextState === 'function') {
|
|
13180
|
+
return localInstantSearchInstance._createURL(_defineProperty({}, indexId, nextState(localUiState)));
|
|
13181
|
+
}
|
|
13643
13182
|
return localInstantSearchInstance._createURL(_defineProperty({}, indexId, getLocalWidgetsUiState(localWidgets, {
|
|
13644
13183
|
searchParameters: nextState,
|
|
13645
13184
|
helper: helper
|
|
@@ -13704,7 +13243,7 @@
|
|
|
13704
13243
|
return widgets.indexOf(widget) === -1;
|
|
13705
13244
|
});
|
|
13706
13245
|
if (localInstantSearchInstance && Boolean(widgets.length)) {
|
|
13707
|
-
var
|
|
13246
|
+
var _nextState = widgets.reduce(function (state, widget) {
|
|
13708
13247
|
// the `dispose` method exists at this point we already assert it
|
|
13709
13248
|
var next = widget.dispose({
|
|
13710
13249
|
helper: helper,
|
|
@@ -13714,12 +13253,12 @@
|
|
|
13714
13253
|
return next || state;
|
|
13715
13254
|
}, helper.state);
|
|
13716
13255
|
localUiState = getLocalWidgetsUiState(localWidgets, {
|
|
13717
|
-
searchParameters:
|
|
13256
|
+
searchParameters: _nextState,
|
|
13718
13257
|
helper: helper
|
|
13719
13258
|
});
|
|
13720
13259
|
helper.setState(getLocalWidgetsSearchParameters(localWidgets, {
|
|
13721
13260
|
uiState: localUiState,
|
|
13722
|
-
initialSearchParameters:
|
|
13261
|
+
initialSearchParameters: _nextState
|
|
13723
13262
|
}));
|
|
13724
13263
|
if (localWidgets.length) {
|
|
13725
13264
|
localInstantSearchInstance.scheduleSearch();
|
|
@@ -14049,7 +13588,7 @@
|
|
|
14049
13588
|
};
|
|
14050
13589
|
}
|
|
14051
13590
|
|
|
14052
|
-
var version$1 = '4.56.
|
|
13591
|
+
var version$1 = '4.56.6';
|
|
14053
13592
|
|
|
14054
13593
|
var withUsage$r = createDocumentationMessageGenerator({
|
|
14055
13594
|
name: 'instantsearch'
|