algoliasearch-helper 3.12.0 → 3.13.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.
package/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ 3.13.1 - 2023-06-12
2
+ * docs(site): follow-up improvements (#939) https://github.com/algolia/algoliasearch-helper-js/commit/6a36194d425b2446c6406e74df75c87bf5028454
3
+ * docs: upgrade and simplify tools (#937) https://github.com/algolia/algoliasearch-helper-js/commit/19ccf0b5e6ea00272223f998b05bd3c8f2d904d6
4
+ * docs: upgrade and simplify tools (#937) https://github.com/algolia/algoliasearch-helper-js/commit/d352cc46d506448b9802e3daa756ff1e9e873886
5
+ * fix(SearchResults): use empty facets object for exclusion when results are artificial (#940) https://github.com/algolia/algoliasearch-helper-js/commit/a51e8cb37e10c41ca816be1630bab2078980947b
6
+
7
+ 3.13.0 - 2023-05-03
8
+ * chore: delete renovate (#936) https://github.com/algolia/algoliasearch-helper-js/commit/0e3d8cff722d4a91a04251533636f0860ef3828c
9
+ * feat(DerivedHelper): skip request for empty index (#938) https://github.com/algolia/algoliasearch-helper-js/commit/79caa4b0ca2537c0f4431ee11556464031935436
10
+
1
11
  3.12.0 - 2023-03-03
2
12
  * feat(types): add `queryAfterRemoval` to `SearchResults` (#934) https://github.com/algolia/algoliasearch-helper-js/commit/4fb5a0345f0cf438fb026d8010faf843bd3b0a01
3
13
 
@@ -2664,7 +2664,10 @@ function SearchResults(state, results, options) {
2664
2664
 
2665
2665
  /**
2666
2666
  * sum of the processing time of all the queries
2667
+ * @name processingTimeMS
2667
2668
  * @member {number}
2669
+ * @memberof SearchResults
2670
+ * @instance
2668
2671
  */
2669
2672
  this.processingTimeMS = results.reduce(function(sum, result) {
2670
2673
  return result.processingTimeMS === undefined
@@ -2870,7 +2873,7 @@ function SearchResults(state, results, options) {
2870
2873
 
2871
2874
  self.facets[position] = {
2872
2875
  name: facetName,
2873
- data: mainSubResponse.facets[facetName],
2876
+ data: mainFacets[facetName],
2874
2877
  exhaustive: mainSubResponse.exhaustiveFacetsCount
2875
2878
  };
2876
2879
  excludes.forEach(function(facetValue) {
@@ -2953,7 +2956,33 @@ function extractNormalizedFacetValues(results, attribute) {
2953
2956
  };
2954
2957
  });
2955
2958
  } else if (results._state.isHierarchicalFacet(attribute)) {
2956
- return find(results.hierarchicalFacets, predicate);
2959
+ var hierarchicalFacetValues = find(results.hierarchicalFacets, predicate);
2960
+ if (!hierarchicalFacetValues) return hierarchicalFacetValues;
2961
+
2962
+ var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
2963
+ var currentRefinementSplit = unescapeFacetValue(
2964
+ results._state.getHierarchicalRefinement(attribute)[0] || ''
2965
+ ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
2966
+ currentRefinementSplit.unshift(attribute);
2967
+
2968
+ setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
2969
+
2970
+ return hierarchicalFacetValues;
2971
+ }
2972
+ }
2973
+
2974
+ /**
2975
+ * Set the isRefined of a hierarchical facet result based on the current state.
2976
+ * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
2977
+ * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
2978
+ * @param {number} depth recursion depth in the currentRefinement
2979
+ */
2980
+ function setIsRefined(item, currentRefinement, depth) {
2981
+ item.isRefined = item.name === currentRefinement[depth];
2982
+ if (item.data) {
2983
+ item.data.forEach(function(child) {
2984
+ setIsRefined(child, currentRefinement, depth + 1);
2985
+ });
2957
2986
  }
2958
2987
  }
2959
2988
 
@@ -3577,8 +3606,10 @@ AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
3577
3606
  * @param {number} options.nbHits - Maximum number of answers to retrieve from the Answers Engine. Cannot be greater than 1000.
3578
3607
  *
3579
3608
  * @return {promise} the answer results
3609
+ * @deprecated answers is deprecated and will be replaced with new initiatives
3580
3610
  */
3581
3611
  AlgoliaSearchHelper.prototype.findAnswers = function(options) {
3612
+ console.warn('[algoliasearch-helper] answers is no longer supported');
3582
3613
  var state = this.state;
3583
3614
  var derivedHelper = this.derivedHelpers[0];
3584
3615
  if (!derivedHelper) {
@@ -4591,7 +4622,9 @@ AlgoliaSearchHelper.prototype._search = function(options) {
4591
4622
 
4592
4623
  var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
4593
4624
  var derivedState = derivedHelper.getModifiedState(state);
4594
- var derivedStateQueries = requestBuilder._getQueries(derivedState.index, derivedState);
4625
+ var derivedStateQueries = derivedState.index
4626
+ ? requestBuilder._getQueries(derivedState.index, derivedState)
4627
+ : [];
4595
4628
 
4596
4629
  states.push({
4597
4630
  state: derivedState,
@@ -4608,10 +4641,16 @@ AlgoliaSearchHelper.prototype._search = function(options) {
4608
4641
  });
4609
4642
 
4610
4643
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
4611
- var queryId = this._queryId++;
4612
4644
 
4645
+ var queryId = this._queryId++;
4613
4646
  this._currentNbQueries++;
4614
4647
 
4648
+ if (!queries.length) {
4649
+ return Promise.resolve({results: []}).then(
4650
+ this._dispatchAlgoliaResponse.bind(this, states, queryId)
4651
+ );
4652
+ }
4653
+
4615
4654
  try {
4616
4655
  this.client.search(queries)
4617
4656
  .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
@@ -4656,6 +4695,14 @@ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryI
4656
4695
  var helper = s.helper;
4657
4696
  var specificResults = results.splice(0, queriesCount);
4658
4697
 
4698
+ if (!state.index) {
4699
+ helper.emit('result', {
4700
+ results: null,
4701
+ state: state
4702
+ });
4703
+ return;
4704
+ }
4705
+
4659
4706
  var formattedResponse = helper.lastResults = new SearchResults(state, specificResults);
4660
4707
 
4661
4708
  helper.emit('result', {
@@ -5007,7 +5054,8 @@ function _merge(target, source) {
5007
5054
  for (var key in source) {
5008
5055
  if (
5009
5056
  !Object.prototype.hasOwnProperty.call(source, key) ||
5010
- key === '__proto__'
5057
+ key === '__proto__' ||
5058
+ key === 'constructor'
5011
5059
  ) {
5012
5060
  continue;
5013
5061
  }
@@ -5587,7 +5635,7 @@ module.exports = function isValidUserToken(userToken) {
5587
5635
  },{}],24:[function(require,module,exports){
5588
5636
  'use strict';
5589
5637
 
5590
- module.exports = '3.11.1';
5638
+ module.exports = '3.13.1';
5591
5639
 
5592
5640
  },{}]},{},[1])(1)
5593
5641
  });