algoliasearch-helper 3.14.2 → 3.16.0

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/README.md CHANGED
@@ -24,7 +24,6 @@ This module is the companion of the [algolia/algoliasearch-client-javascript](ht
24
24
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
25
25
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
26
26
 
27
-
28
27
  - [Features](#features)
29
28
  - [Examples](#examples)
30
29
  - [Vanilla JavaScript](#vanilla-javascript)
@@ -338,10 +338,11 @@ var SearchResults = require('./src/SearchResults');
338
338
  * @param {AlgoliaSearch} client an AlgoliaSearch client
339
339
  * @param {string} index the name of the index to query
340
340
  * @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.
341
+ * @param {SearchResultsOptions|object} searchResultsOptions an object defining the options to use when creating the search results.
341
342
  * @return {AlgoliaSearchHelper} The helper instance
342
343
  */
343
- function algoliasearchHelper(client, index, opts) {
344
- return new AlgoliaSearchHelper(client, index, opts);
344
+ function algoliasearchHelper(client, index, opts, searchResultsOptions) {
345
+ return new AlgoliaSearchHelper(client, index, opts, searchResultsOptions);
345
346
  }
346
347
 
347
348
  /**
@@ -2586,7 +2587,6 @@ function findMatchingHierarchicalFacetFromAttributeName(
2586
2587
  );
2587
2588
  }
2588
2589
 
2589
- // eslint-disable-next-line valid-jsdoc
2590
2590
  /**
2591
2591
  * Constructor for SearchResults
2592
2592
  * @class
@@ -2594,6 +2594,7 @@ function findMatchingHierarchicalFacetFromAttributeName(
2594
2594
  * {@link AlgoliaSearchHelper}.
2595
2595
  * @param {SearchParameters} state state that led to the response
2596
2596
  * @param {array.<object>} results the results from algolia client
2597
+ * @param {object} options options to control results content
2597
2598
  * @example <caption>SearchResults of the first query in
2598
2599
  * <a href="http://demos.algolia.com/instant-search-demo">the instant search demo</a></caption>
2599
2600
  {
@@ -2731,8 +2732,14 @@ function SearchResults(state, results, options) {
2731
2732
  });
2732
2733
 
2733
2734
  // Make every key of the result options reachable from the instance
2734
- Object.keys(options || {}).forEach(function (key) {
2735
- self[key] = options[key];
2735
+ var opts = merge(
2736
+ {
2737
+ persistHierarchicalRootCount: false,
2738
+ },
2739
+ options
2740
+ );
2741
+ Object.keys(opts).forEach(function (key) {
2742
+ self[key] = opts[key];
2736
2743
  });
2737
2744
 
2738
2745
  /**
@@ -3082,9 +3089,13 @@ function SearchResults(state, results, options) {
3082
3089
  // We want
3083
3090
  // | beers (5)
3084
3091
  // > IPA (5)
3092
+ // @MAJOR: remove this legacy behaviour in next major version
3085
3093
  var defaultData = {};
3086
3094
 
3087
- if (currentRefinement.length > 0) {
3095
+ if (
3096
+ currentRefinement.length > 0 &&
3097
+ !self.persistHierarchicalRootCount
3098
+ ) {
3088
3099
  var root = currentRefinement[0].split(separator)[0];
3089
3100
  defaultData[root] =
3090
3101
  self.hierarchicalFacets[position][attributeIndex].data[root];
@@ -3751,8 +3762,9 @@ var version = require('./version');
3751
3762
  * @param {SearchParameters | object} options an object defining the initial
3752
3763
  * config of the search. It doesn't have to be a {SearchParameters},
3753
3764
  * just an object containing the properties you need from it.
3765
+ * @param {SearchResultsOptions|object} searchResultsOptions an object defining the options to use when creating the search results.
3754
3766
  */
3755
- function AlgoliaSearchHelper(client, index, options) {
3767
+ function AlgoliaSearchHelper(client, index, options, searchResultsOptions) {
3756
3768
  if (typeof client.addAlgoliaAgent === 'function') {
3757
3769
  client.addAlgoliaAgent('JS Helper (' + version + ')');
3758
3770
  }
@@ -3766,6 +3778,7 @@ function AlgoliaSearchHelper(client, index, options) {
3766
3778
  this._lastQueryIdReceived = -1;
3767
3779
  this.derivedHelpers = [];
3768
3780
  this._currentNbQueries = 0;
3781
+ this._searchResultsOptions = searchResultsOptions;
3769
3782
  }
3770
3783
 
3771
3784
  inherits(AlgoliaSearchHelper, EventEmitter);
@@ -5038,6 +5051,9 @@ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
5038
5051
  queryId,
5039
5052
  content
5040
5053
  ) {
5054
+ // eslint-disable-next-line consistent-this
5055
+ var self = this;
5056
+
5041
5057
  // @TODO remove the number of outdated queries discarded instead of just one
5042
5058
 
5043
5059
  if (queryId < this._lastQueryIdReceived) {
@@ -5066,7 +5082,11 @@ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
5066
5082
  return;
5067
5083
  }
5068
5084
 
5069
- helper.lastResults = new SearchResults(state, specificResults);
5085
+ helper.lastResults = new SearchResults(
5086
+ state,
5087
+ specificResults,
5088
+ self._searchResultsOptions
5089
+ );
5070
5090
 
5071
5091
  helper.emit('result', {
5072
5092
  results: helper.lastResults,
@@ -6081,7 +6101,7 @@ module.exports = function isValidUserToken(userToken) {
6081
6101
  },{}],24:[function(require,module,exports){
6082
6102
  'use strict';
6083
6103
 
6084
- module.exports = '3.14.2';
6104
+ module.exports = '3.16.0';
6085
6105
 
6086
6106
  },{}]},{},[2])(2)
6087
6107
  });