algoliasearch-helper 3.25.0 → 3.26.1

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.
@@ -3577,8 +3577,8 @@ SearchResults.prototype.getFacetValues = function (attribute, opts) {
3577
3577
 
3578
3578
  return recSort(
3579
3579
  function (data, facetName) {
3580
+ var facetOrdering = getFacetOrdering(results, facetName);
3580
3581
  if (options.facetOrdering) {
3581
- var facetOrdering = getFacetOrdering(results, facetName);
3582
3582
  if (facetOrdering) {
3583
3583
  return sortViaFacetOrdering(data, facetOrdering);
3584
3584
  }
@@ -3586,7 +3586,24 @@ SearchResults.prototype.getFacetValues = function (attribute, opts) {
3586
3586
 
3587
3587
  if (Array.isArray(options.sortBy)) {
3588
3588
  var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
3589
- return orderBy(data, order[0], order[1]);
3589
+ var items = orderBy(data, order[0], order[1]);
3590
+
3591
+ var hide =
3592
+ facetOrdering && facetOrdering.hide ? facetOrdering.hide : [];
3593
+ if (hide.length > 0) {
3594
+ var visible = [];
3595
+ items.forEach(function (item) {
3596
+ // hierarchical facets get sorted using their raw name
3597
+ var name = item.path || item.name;
3598
+ if (hide.indexOf(name) === -1) {
3599
+ visible.push(item);
3600
+ }
3601
+ });
3602
+
3603
+ return visible;
3604
+ }
3605
+
3606
+ return items;
3590
3607
  } else if (typeof options.sortBy === 'function') {
3591
3608
  return vanillaSortFn(options.sortBy, data);
3592
3609
  }
@@ -4230,6 +4247,16 @@ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
4230
4247
  query: query,
4231
4248
  });
4232
4249
 
4250
+ var hide =
4251
+ (this.lastResults &&
4252
+ this.lastResults.index === state.index &&
4253
+ this.lastResults.renderingContent &&
4254
+ this.lastResults.renderingContent.facetOrdering &&
4255
+ this.lastResults.renderingContent.facetOrdering.values &&
4256
+ this.lastResults.renderingContent.facetOrdering.values[facet] &&
4257
+ this.lastResults.renderingContent.facetOrdering.values[facet].hide) ||
4258
+ [];
4259
+
4233
4260
  return searchForFacetValuesPromise.then(
4234
4261
  function addIsRefined(content) {
4235
4262
  self._currentNbQueries--;
@@ -4237,12 +4264,19 @@ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
4237
4264
 
4238
4265
  content = Array.isArray(content) ? content[0] : content;
4239
4266
 
4240
- content.facetHits.forEach(function (f) {
4267
+ content.facetHits = content.facetHits.reduce(function (acc, f) {
4268
+ if (hide.indexOf(f.value) > -1) {
4269
+ return acc;
4270
+ }
4271
+
4241
4272
  f.escapedValue = escapeFacetValue(f.value);
4242
4273
  f.isRefined = isDisjunctive
4243
4274
  ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
4244
4275
  : state.isFacetRefined(facet, f.escapedValue);
4245
- });
4276
+
4277
+ acc.push(f);
4278
+ return acc;
4279
+ }, []);
4246
4280
 
4247
4281
  return content;
4248
4282
  },
@@ -6986,7 +7020,7 @@ module.exports = sortAndMergeRecommendations;
6986
7020
  },{"../functions/find":14,"../functions/flat":16}],29:[function(require,module,exports){
6987
7021
  'use strict';
6988
7022
 
6989
- module.exports = '3.25.0';
7023
+ module.exports = '3.26.1';
6990
7024
 
6991
7025
  },{}]},{},[2])(2)
6992
7026
  });