instantsearch.js 4.66.1 → 4.67.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/cjs/lib/InstantSearch.js +1 -1
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/index/index.js +68 -13
- package/dist/instantsearch.development.d.ts +25 -2
- package/dist/instantsearch.development.js +485 -30
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +25 -2
- package/dist/instantsearch.production.min.d.ts +25 -2
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/lib/InstantSearch.js +1 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/widget.d.ts +21 -2
- package/es/widgets/index/index.js +68 -13
- package/es/widgets/panel/panel.d.ts +1 -1
- package/package.json +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.
|
|
1
|
+
/*! InstantSearch.js 4.67.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
|
|
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) :
|
|
@@ -6101,12 +6101,15 @@
|
|
|
6101
6101
|
* This event contains a {@link SearchResults} object and the
|
|
6102
6102
|
* {@link SearchParameters} corresponding to this answer.
|
|
6103
6103
|
* @param {AlgoliaSearchHelper} mainHelper the main helper
|
|
6104
|
-
* @param {function} fn the function to create the derived state
|
|
6104
|
+
* @param {function} fn the function to create the derived state for search
|
|
6105
|
+
* @param {function} recommendFn the function to create the derived state for recommendations
|
|
6105
6106
|
*/
|
|
6106
|
-
function DerivedHelper(mainHelper, fn) {
|
|
6107
|
+
function DerivedHelper(mainHelper, fn, recommendFn) {
|
|
6107
6108
|
this.main = mainHelper;
|
|
6108
6109
|
this.fn = fn;
|
|
6110
|
+
this.recommendFn = recommendFn;
|
|
6109
6111
|
this.lastResults = null;
|
|
6112
|
+
this.lastRecommendResults = null;
|
|
6110
6113
|
}
|
|
6111
6114
|
|
|
6112
6115
|
inherits_1(DerivedHelper, events);
|
|
@@ -6125,6 +6128,10 @@
|
|
|
6125
6128
|
return this.fn(parameters);
|
|
6126
6129
|
};
|
|
6127
6130
|
|
|
6131
|
+
DerivedHelper.prototype.getModifiedRecommendState = function (parameters) {
|
|
6132
|
+
return this.recommendFn(parameters);
|
|
6133
|
+
};
|
|
6134
|
+
|
|
6128
6135
|
var DerivedHelper_1 = DerivedHelper;
|
|
6129
6136
|
|
|
6130
6137
|
/**
|
|
@@ -6285,7 +6292,18 @@
|
|
|
6285
6292
|
constructor: RecommendParameters,
|
|
6286
6293
|
|
|
6287
6294
|
addParams: function (params) {
|
|
6288
|
-
|
|
6295
|
+
var newParams = this.params.slice();
|
|
6296
|
+
var existingParamsIndex = this.params.findIndex(function (currentParams) {
|
|
6297
|
+
return currentParams.$$id === params.$$id;
|
|
6298
|
+
});
|
|
6299
|
+
|
|
6300
|
+
if (existingParamsIndex !== -1) {
|
|
6301
|
+
newParams.splice(existingParamsIndex, 1, params);
|
|
6302
|
+
} else {
|
|
6303
|
+
newParams.push(params);
|
|
6304
|
+
}
|
|
6305
|
+
|
|
6306
|
+
return new RecommendParameters({ params: newParams });
|
|
6289
6307
|
},
|
|
6290
6308
|
|
|
6291
6309
|
removeParams: function (id) {
|
|
@@ -6295,6 +6313,45 @@
|
|
|
6295
6313
|
}),
|
|
6296
6314
|
});
|
|
6297
6315
|
},
|
|
6316
|
+
|
|
6317
|
+
addFrequentlyBoughtTogether: function (params) {
|
|
6318
|
+
return this.addParams(
|
|
6319
|
+
Object.assign({}, params, { model: 'bought-together' })
|
|
6320
|
+
);
|
|
6321
|
+
},
|
|
6322
|
+
|
|
6323
|
+
addRelatedProducts: function (params) {
|
|
6324
|
+
return this.addParams(
|
|
6325
|
+
Object.assign({}, params, { model: 'related-products' })
|
|
6326
|
+
);
|
|
6327
|
+
},
|
|
6328
|
+
|
|
6329
|
+
addTrendingItems: function (params) {
|
|
6330
|
+
return this.addParams(
|
|
6331
|
+
Object.assign({}, params, { model: 'trending-items' })
|
|
6332
|
+
);
|
|
6333
|
+
},
|
|
6334
|
+
|
|
6335
|
+
addTrendingFacets: function (params) {
|
|
6336
|
+
return this.addParams(
|
|
6337
|
+
Object.assign({}, params, { model: 'trending-facets' })
|
|
6338
|
+
);
|
|
6339
|
+
},
|
|
6340
|
+
|
|
6341
|
+
addLookingSimilar: function (params) {
|
|
6342
|
+
return this.addParams(
|
|
6343
|
+
Object.assign({}, params, { model: 'looking-similar' })
|
|
6344
|
+
);
|
|
6345
|
+
},
|
|
6346
|
+
|
|
6347
|
+
_buildQueries: function (indexName) {
|
|
6348
|
+
return this.params.map(function (params) {
|
|
6349
|
+
var query = Object.assign({}, params, { indexName: indexName });
|
|
6350
|
+
delete query.$$id;
|
|
6351
|
+
|
|
6352
|
+
return query;
|
|
6353
|
+
});
|
|
6354
|
+
},
|
|
6298
6355
|
};
|
|
6299
6356
|
|
|
6300
6357
|
var RecommendParameters_1 = RecommendParameters;
|
|
@@ -10146,7 +10203,7 @@
|
|
|
10146
10203
|
|
|
10147
10204
|
var SearchResults_1 = SearchResults;
|
|
10148
10205
|
|
|
10149
|
-
var version = '3.
|
|
10206
|
+
var version = '3.18.0';
|
|
10150
10207
|
|
|
10151
10208
|
var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
|
|
10152
10209
|
|
|
@@ -10276,10 +10333,14 @@
|
|
|
10276
10333
|
params: opts.recommendState,
|
|
10277
10334
|
});
|
|
10278
10335
|
this.lastResults = null;
|
|
10336
|
+
this.lastRecommendResults = null;
|
|
10279
10337
|
this._queryId = 0;
|
|
10338
|
+
this._recommendQueryId = 0;
|
|
10280
10339
|
this._lastQueryIdReceived = -1;
|
|
10340
|
+
this._lastRecommendQueryIdReceived = -1;
|
|
10281
10341
|
this.derivedHelpers = [];
|
|
10282
10342
|
this._currentNbQueries = 0;
|
|
10343
|
+
this._currentNbRecommendQueries = 0;
|
|
10283
10344
|
this._searchResultsOptions = searchResultsOptions;
|
|
10284
10345
|
}
|
|
10285
10346
|
|
|
@@ -10306,6 +10367,21 @@
|
|
|
10306
10367
|
return this;
|
|
10307
10368
|
};
|
|
10308
10369
|
|
|
10370
|
+
/**
|
|
10371
|
+
* Sends the recommendation queries set in the state. When the method is
|
|
10372
|
+
* called, it triggers a `fetch` event. The results will be available through
|
|
10373
|
+
* the `result` event. If an error occurs, an `error` will be fired instead.
|
|
10374
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10375
|
+
* @fires fetch
|
|
10376
|
+
* @fires result
|
|
10377
|
+
* @fires error
|
|
10378
|
+
* @chainable
|
|
10379
|
+
*/
|
|
10380
|
+
AlgoliaSearchHelper.prototype.recommend = function () {
|
|
10381
|
+
this._recommend();
|
|
10382
|
+
return this;
|
|
10383
|
+
};
|
|
10384
|
+
|
|
10309
10385
|
/**
|
|
10310
10386
|
* Gets the search query parameters that would be sent to the Algolia Client
|
|
10311
10387
|
* for the hits
|
|
@@ -10802,6 +10878,86 @@
|
|
|
10802
10878
|
return this;
|
|
10803
10879
|
};
|
|
10804
10880
|
|
|
10881
|
+
/**
|
|
10882
|
+
* Adds a "frequently bought together" recommendation query.
|
|
10883
|
+
*
|
|
10884
|
+
* @param {FrequentlyBoughtTogetherQuery} params the parameters for the recommendation
|
|
10885
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10886
|
+
* @fires change
|
|
10887
|
+
* @chainable
|
|
10888
|
+
*/
|
|
10889
|
+
AlgoliaSearchHelper.prototype.addFrequentlyBoughtTogether = function (params) {
|
|
10890
|
+
this._recommendChange({
|
|
10891
|
+
state: this.recommendState.addFrequentlyBoughtTogether(params),
|
|
10892
|
+
});
|
|
10893
|
+
|
|
10894
|
+
return this;
|
|
10895
|
+
};
|
|
10896
|
+
|
|
10897
|
+
/**
|
|
10898
|
+
* Adds a "related products" recommendation query.
|
|
10899
|
+
*
|
|
10900
|
+
* @param {RelatedProductsQuery} params the parameters for the recommendation
|
|
10901
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10902
|
+
* @fires change
|
|
10903
|
+
* @chainable
|
|
10904
|
+
*/
|
|
10905
|
+
AlgoliaSearchHelper.prototype.addRelatedProducts = function (params) {
|
|
10906
|
+
this._recommendChange({
|
|
10907
|
+
state: this.recommendState.addRelatedProducts(params),
|
|
10908
|
+
});
|
|
10909
|
+
|
|
10910
|
+
return this;
|
|
10911
|
+
};
|
|
10912
|
+
|
|
10913
|
+
/**
|
|
10914
|
+
* Adds a "trending items" recommendation query.
|
|
10915
|
+
*
|
|
10916
|
+
* @param {TrendingItemsQuery} params the parameters for the recommendation
|
|
10917
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10918
|
+
* @fires change
|
|
10919
|
+
* @chainable
|
|
10920
|
+
*/
|
|
10921
|
+
AlgoliaSearchHelper.prototype.addTrendingItems = function (params) {
|
|
10922
|
+
this._recommendChange({
|
|
10923
|
+
state: this.recommendState.addTrendingItems(params),
|
|
10924
|
+
});
|
|
10925
|
+
|
|
10926
|
+
return this;
|
|
10927
|
+
};
|
|
10928
|
+
|
|
10929
|
+
/**
|
|
10930
|
+
* Adds a "trending facets" recommendation query.
|
|
10931
|
+
*
|
|
10932
|
+
* @param {TrendingFacetsQuery} params the parameters for the recommendation
|
|
10933
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10934
|
+
* @fires change
|
|
10935
|
+
* @chainable
|
|
10936
|
+
*/
|
|
10937
|
+
AlgoliaSearchHelper.prototype.addTrendingFacets = function (params) {
|
|
10938
|
+
this._recommendChange({
|
|
10939
|
+
state: this.recommendState.addTrendingFacets(params),
|
|
10940
|
+
});
|
|
10941
|
+
|
|
10942
|
+
return this;
|
|
10943
|
+
};
|
|
10944
|
+
|
|
10945
|
+
/**
|
|
10946
|
+
* Adds a "looking similar" recommendation query.
|
|
10947
|
+
*
|
|
10948
|
+
* @param {LookingSimilarQuery} params the parameters for the recommendation
|
|
10949
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
10950
|
+
* @fires change
|
|
10951
|
+
* @chainable
|
|
10952
|
+
*/
|
|
10953
|
+
AlgoliaSearchHelper.prototype.addLookingSimilar = function (params) {
|
|
10954
|
+
this._recommendChange({
|
|
10955
|
+
state: this.recommendState.addLookingSimilar(params),
|
|
10956
|
+
});
|
|
10957
|
+
|
|
10958
|
+
return this;
|
|
10959
|
+
};
|
|
10960
|
+
|
|
10805
10961
|
/**
|
|
10806
10962
|
* Removes an numeric filter to an attribute with the `operator` and `value` provided. If the
|
|
10807
10963
|
* filter is not set, it doesn't change the filters.
|
|
@@ -10971,6 +11127,86 @@
|
|
|
10971
11127
|
return this;
|
|
10972
11128
|
};
|
|
10973
11129
|
|
|
11130
|
+
/**
|
|
11131
|
+
* Removes a "frequently bought together" recommendation query.
|
|
11132
|
+
*
|
|
11133
|
+
* @param {string} id identifier of the recommendation widget
|
|
11134
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
11135
|
+
* @fires change
|
|
11136
|
+
* @chainable
|
|
11137
|
+
*/
|
|
11138
|
+
AlgoliaSearchHelper.prototype.removeFrequentlyBoughtTogether = function (id) {
|
|
11139
|
+
this._recommendChange({
|
|
11140
|
+
state: this.recommendState.removeParams(id),
|
|
11141
|
+
});
|
|
11142
|
+
|
|
11143
|
+
return this;
|
|
11144
|
+
};
|
|
11145
|
+
|
|
11146
|
+
/**
|
|
11147
|
+
* Removes a "related products" recommendation query.
|
|
11148
|
+
*
|
|
11149
|
+
* @param {string} id identifier of the recommendation widget
|
|
11150
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
11151
|
+
* @fires change
|
|
11152
|
+
* @chainable
|
|
11153
|
+
*/
|
|
11154
|
+
AlgoliaSearchHelper.prototype.removeRelatedProducts = function (id) {
|
|
11155
|
+
this._recommendChange({
|
|
11156
|
+
state: this.recommendState.removeParams(id),
|
|
11157
|
+
});
|
|
11158
|
+
|
|
11159
|
+
return this;
|
|
11160
|
+
};
|
|
11161
|
+
|
|
11162
|
+
/**
|
|
11163
|
+
* Removes a "trending items" recommendation query.
|
|
11164
|
+
*
|
|
11165
|
+
* @param {string} id identifier of the recommendation widget
|
|
11166
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
11167
|
+
* @fires change
|
|
11168
|
+
* @chainable
|
|
11169
|
+
*/
|
|
11170
|
+
AlgoliaSearchHelper.prototype.removeTrendingItems = function (id) {
|
|
11171
|
+
this._recommendChange({
|
|
11172
|
+
state: this.recommendState.removeParams(id),
|
|
11173
|
+
});
|
|
11174
|
+
|
|
11175
|
+
return this;
|
|
11176
|
+
};
|
|
11177
|
+
|
|
11178
|
+
/**
|
|
11179
|
+
* Removes a "trending facets" recommendation query.
|
|
11180
|
+
*
|
|
11181
|
+
* @param {string} id identifier of the recommendation widget
|
|
11182
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
11183
|
+
* @fires change
|
|
11184
|
+
* @chainable
|
|
11185
|
+
*/
|
|
11186
|
+
AlgoliaSearchHelper.prototype.removeTrendingFacets = function (id) {
|
|
11187
|
+
this._recommendChange({
|
|
11188
|
+
state: this.recommendState.removeParams(id),
|
|
11189
|
+
});
|
|
11190
|
+
|
|
11191
|
+
return this;
|
|
11192
|
+
};
|
|
11193
|
+
|
|
11194
|
+
/**
|
|
11195
|
+
* Removes a "looking similar" recommendation query.
|
|
11196
|
+
*
|
|
11197
|
+
* @param {string} id identifier of the recommendation widget
|
|
11198
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
11199
|
+
* @fires change
|
|
11200
|
+
* @chainable
|
|
11201
|
+
*/
|
|
11202
|
+
AlgoliaSearchHelper.prototype.removeLookingSimilar = function (id) {
|
|
11203
|
+
this._recommendChange({
|
|
11204
|
+
state: this.recommendState.removeParams(id),
|
|
11205
|
+
});
|
|
11206
|
+
|
|
11207
|
+
return this;
|
|
11208
|
+
};
|
|
11209
|
+
|
|
10974
11210
|
/**
|
|
10975
11211
|
* Adds or removes an exclusion filter to a faceted attribute with the `value` provided. If
|
|
10976
11212
|
* the value is set then it removes it, otherwise it adds the filter.
|
|
@@ -11538,6 +11774,85 @@
|
|
|
11538
11774
|
return undefined;
|
|
11539
11775
|
};
|
|
11540
11776
|
|
|
11777
|
+
AlgoliaSearchHelper.prototype._recommend = function () {
|
|
11778
|
+
var searchState = this.state;
|
|
11779
|
+
var recommendState = this.recommendState;
|
|
11780
|
+
var index = this.getIndex();
|
|
11781
|
+
var states = [{ state: recommendState, index: index, helper: this }];
|
|
11782
|
+
|
|
11783
|
+
this.emit('fetch', {
|
|
11784
|
+
recommend: {
|
|
11785
|
+
state: recommendState,
|
|
11786
|
+
results: this.lastRecommendResults,
|
|
11787
|
+
},
|
|
11788
|
+
});
|
|
11789
|
+
|
|
11790
|
+
var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
|
|
11791
|
+
var derivedIndex = derivedHelper.getModifiedState(searchState).index;
|
|
11792
|
+
if (!derivedIndex) {
|
|
11793
|
+
return [];
|
|
11794
|
+
}
|
|
11795
|
+
|
|
11796
|
+
// Contrary to what is done when deriving the search state, we don't want to
|
|
11797
|
+
// provide the current recommend state to the derived helper, as it would
|
|
11798
|
+
// inherit unwanted queries. We instead provide an empty recommend state.
|
|
11799
|
+
var derivedState = derivedHelper.getModifiedRecommendState(
|
|
11800
|
+
new RecommendParameters_1()
|
|
11801
|
+
);
|
|
11802
|
+
states.push({
|
|
11803
|
+
state: derivedState,
|
|
11804
|
+
index: derivedIndex,
|
|
11805
|
+
helper: derivedHelper,
|
|
11806
|
+
});
|
|
11807
|
+
|
|
11808
|
+
derivedHelper.emit('fetch', {
|
|
11809
|
+
recommend: {
|
|
11810
|
+
state: derivedState,
|
|
11811
|
+
results: derivedHelper.lastRecommendResults,
|
|
11812
|
+
},
|
|
11813
|
+
});
|
|
11814
|
+
|
|
11815
|
+
return derivedState._buildQueries(derivedIndex);
|
|
11816
|
+
});
|
|
11817
|
+
|
|
11818
|
+
var queries = Array.prototype.concat.apply(
|
|
11819
|
+
this.recommendState._buildQueries(index),
|
|
11820
|
+
derivedQueries
|
|
11821
|
+
);
|
|
11822
|
+
|
|
11823
|
+
if (queries.length === 0) {
|
|
11824
|
+
return;
|
|
11825
|
+
}
|
|
11826
|
+
|
|
11827
|
+
if (
|
|
11828
|
+
queries.length > 0 &&
|
|
11829
|
+
typeof this.client.getRecommendations === 'undefined'
|
|
11830
|
+
) {
|
|
11831
|
+
// eslint-disable-next-line no-console
|
|
11832
|
+
console.warn(
|
|
11833
|
+
'Please update algoliasearch/lite to the latest version in order to use recommendations widgets.'
|
|
11834
|
+
);
|
|
11835
|
+
return;
|
|
11836
|
+
}
|
|
11837
|
+
|
|
11838
|
+
var queryId = this._recommendQueryId++;
|
|
11839
|
+
this._currentNbRecommendQueries++;
|
|
11840
|
+
|
|
11841
|
+
try {
|
|
11842
|
+
this.client
|
|
11843
|
+
.getRecommendations(queries)
|
|
11844
|
+
.then(this._dispatchRecommendResponse.bind(this, queryId, states))
|
|
11845
|
+
.catch(this._dispatchRecommendError.bind(this, queryId));
|
|
11846
|
+
} catch (error) {
|
|
11847
|
+
// If we reach this part, we're in an internal error state
|
|
11848
|
+
this.emit('error', {
|
|
11849
|
+
error: error,
|
|
11850
|
+
});
|
|
11851
|
+
}
|
|
11852
|
+
|
|
11853
|
+
return;
|
|
11854
|
+
};
|
|
11855
|
+
|
|
11541
11856
|
/**
|
|
11542
11857
|
* Transform the responses as sent by the server and transform them into a user
|
|
11543
11858
|
* usable object that merge the results of all the batch requests. It will dispatch
|
|
@@ -11597,6 +11912,53 @@
|
|
|
11597
11912
|
});
|
|
11598
11913
|
};
|
|
11599
11914
|
|
|
11915
|
+
AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
|
|
11916
|
+
queryId,
|
|
11917
|
+
states,
|
|
11918
|
+
content
|
|
11919
|
+
) {
|
|
11920
|
+
// @TODO remove the number of outdated queries discarded instead of just one
|
|
11921
|
+
|
|
11922
|
+
if (queryId < this._lastRecommendQueryIdReceived) {
|
|
11923
|
+
// Outdated answer
|
|
11924
|
+
return;
|
|
11925
|
+
}
|
|
11926
|
+
|
|
11927
|
+
this._currentNbRecommendQueries -=
|
|
11928
|
+
queryId - this._lastRecommendQueryIdReceived;
|
|
11929
|
+
this._lastRecommendQueryIdReceived = queryId;
|
|
11930
|
+
|
|
11931
|
+
if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
|
|
11932
|
+
|
|
11933
|
+
var results = content.results.slice();
|
|
11934
|
+
|
|
11935
|
+
states.forEach(function (s) {
|
|
11936
|
+
var state = s.state;
|
|
11937
|
+
var helper = s.helper;
|
|
11938
|
+
|
|
11939
|
+
if (!s.index) {
|
|
11940
|
+
// eslint-disable-next-line no-warning-comments
|
|
11941
|
+
// TODO: emit "result" event when events for Recommend are implemented
|
|
11942
|
+
helper.emit('recommend:result', {
|
|
11943
|
+
results: null,
|
|
11944
|
+
state: state,
|
|
11945
|
+
});
|
|
11946
|
+
return;
|
|
11947
|
+
}
|
|
11948
|
+
|
|
11949
|
+
helper.lastRecommendResults = results;
|
|
11950
|
+
|
|
11951
|
+
// eslint-disable-next-line no-warning-comments
|
|
11952
|
+
// TODO: emit "result" event when events for Recommend are implemented
|
|
11953
|
+
helper.emit('recommend:result', {
|
|
11954
|
+
recommend: {
|
|
11955
|
+
results: helper.lastRecommendResults,
|
|
11956
|
+
state: state,
|
|
11957
|
+
},
|
|
11958
|
+
});
|
|
11959
|
+
});
|
|
11960
|
+
};
|
|
11961
|
+
|
|
11600
11962
|
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
|
|
11601
11963
|
queryId,
|
|
11602
11964
|
error
|
|
@@ -11616,6 +11978,26 @@
|
|
|
11616
11978
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
11617
11979
|
};
|
|
11618
11980
|
|
|
11981
|
+
AlgoliaSearchHelper.prototype._dispatchRecommendError = function (
|
|
11982
|
+
queryId,
|
|
11983
|
+
error
|
|
11984
|
+
) {
|
|
11985
|
+
if (queryId < this._lastRecommendQueryIdReceived) {
|
|
11986
|
+
// Outdated answer
|
|
11987
|
+
return;
|
|
11988
|
+
}
|
|
11989
|
+
|
|
11990
|
+
this._currentNbRecommendQueries -=
|
|
11991
|
+
queryId - this._lastRecommendQueryIdReceived;
|
|
11992
|
+
this._lastRecommendQueryIdReceived = queryId;
|
|
11993
|
+
|
|
11994
|
+
this.emit('error', {
|
|
11995
|
+
error: error,
|
|
11996
|
+
});
|
|
11997
|
+
|
|
11998
|
+
if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
|
|
11999
|
+
};
|
|
12000
|
+
|
|
11619
12001
|
AlgoliaSearchHelper.prototype.containsRefinement = function (
|
|
11620
12002
|
query,
|
|
11621
12003
|
facetFilters,
|
|
@@ -11666,6 +12048,16 @@
|
|
|
11666
12048
|
|
|
11667
12049
|
// eslint-disable-next-line no-warning-comments
|
|
11668
12050
|
// TODO: emit "change" event when events for Recommend are implemented
|
|
12051
|
+
this.emit('recommend:change', {
|
|
12052
|
+
search: {
|
|
12053
|
+
results: this.lastResults,
|
|
12054
|
+
state: this.state,
|
|
12055
|
+
},
|
|
12056
|
+
recommend: {
|
|
12057
|
+
results: this.lastRecommendResults,
|
|
12058
|
+
state: this.recommendState,
|
|
12059
|
+
},
|
|
12060
|
+
});
|
|
11669
12061
|
}
|
|
11670
12062
|
};
|
|
11671
12063
|
|
|
@@ -11720,10 +12112,11 @@
|
|
|
11720
12112
|
* and the SearchParameters that is returned by the call of the
|
|
11721
12113
|
* parameter function.
|
|
11722
12114
|
* @param {function} fn SearchParameters -> SearchParameters
|
|
12115
|
+
* @param {function} recommendFn RecommendParameters -> RecommendParameters
|
|
11723
12116
|
* @return {DerivedHelper} a new DerivedHelper
|
|
11724
12117
|
*/
|
|
11725
|
-
AlgoliaSearchHelper.prototype.derive = function (fn) {
|
|
11726
|
-
var derivedHelper = new DerivedHelper_1(this, fn);
|
|
12118
|
+
AlgoliaSearchHelper.prototype.derive = function (fn, recommendFn) {
|
|
12119
|
+
var derivedHelper = new DerivedHelper_1(this, fn, recommendFn);
|
|
11727
12120
|
this.derivedHelpers.push(derivedHelper);
|
|
11728
12121
|
return derivedHelper;
|
|
11729
12122
|
};
|
|
@@ -11825,6 +12218,13 @@
|
|
|
11825
12218
|
*/
|
|
11826
12219
|
algoliasearchHelper.SearchParameters = SearchParameters_1;
|
|
11827
12220
|
|
|
12221
|
+
/**
|
|
12222
|
+
* Constructor for the object containing all the parameters for Recommend.
|
|
12223
|
+
* @member module:algoliasearchHelper.RecommendParameters
|
|
12224
|
+
* @type {RecommendParameters}
|
|
12225
|
+
*/
|
|
12226
|
+
algoliasearchHelper.RecommendParameters = RecommendParameters_1;
|
|
12227
|
+
|
|
11828
12228
|
/**
|
|
11829
12229
|
* Constructor for the object containing the results of the search.
|
|
11830
12230
|
* @member module:algoliasearchHelper.SearchResults
|
|
@@ -14413,7 +14813,8 @@
|
|
|
14413
14813
|
};
|
|
14414
14814
|
};
|
|
14415
14815
|
|
|
14416
|
-
var _excluded$7 = ["initialSearchParameters"]
|
|
14816
|
+
var _excluded$7 = ["initialSearchParameters"],
|
|
14817
|
+
_excluded2$2 = ["initialRecommendParameters"];
|
|
14417
14818
|
var withUsage$q = createDocumentationMessageGenerator({
|
|
14418
14819
|
name: 'index-widget'
|
|
14419
14820
|
});
|
|
@@ -14424,6 +14825,7 @@
|
|
|
14424
14825
|
*/
|
|
14425
14826
|
function privateHelperSetState(helper, _ref) {
|
|
14426
14827
|
var state = _ref.state,
|
|
14828
|
+
recommendState = _ref.recommendState,
|
|
14427
14829
|
isPageReset = _ref.isPageReset,
|
|
14428
14830
|
_uiState = _ref._uiState;
|
|
14429
14831
|
if (state !== helper.state) {
|
|
@@ -14435,7 +14837,14 @@
|
|
|
14435
14837
|
_uiState: _uiState
|
|
14436
14838
|
});
|
|
14437
14839
|
}
|
|
14840
|
+
if (recommendState !== helper.recommendState) {
|
|
14841
|
+
helper.recommendState = recommendState;
|
|
14842
|
+
|
|
14843
|
+
// eslint-disable-next-line no-warning-comments
|
|
14844
|
+
// TODO: emit "change" event when events for Recommend are implemented
|
|
14845
|
+
}
|
|
14438
14846
|
}
|
|
14847
|
+
|
|
14439
14848
|
function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
14440
14849
|
var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
14441
14850
|
return widgets.reduce(function (uiState, widget) {
|
|
@@ -14454,15 +14863,26 @@
|
|
|
14454
14863
|
function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
|
|
14455
14864
|
var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
|
|
14456
14865
|
rest = _objectWithoutProperties(widgetSearchParametersOptions, _excluded$7);
|
|
14457
|
-
return widgets.
|
|
14458
|
-
|
|
14459
|
-
}).reduce(function (state, widget) {
|
|
14460
|
-
if (!widget.getWidgetSearchParameters) {
|
|
14866
|
+
return widgets.reduce(function (state, widget) {
|
|
14867
|
+
if (!widget.getWidgetSearchParameters || isIndexWidget(widget)) {
|
|
14461
14868
|
return state;
|
|
14462
14869
|
}
|
|
14870
|
+
if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
|
|
14871
|
+
return widget.getWidgetParameters(state, rest);
|
|
14872
|
+
}
|
|
14463
14873
|
return widget.getWidgetSearchParameters(state, rest);
|
|
14464
14874
|
}, initialSearchParameters);
|
|
14465
14875
|
}
|
|
14876
|
+
function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
|
|
14877
|
+
var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
|
|
14878
|
+
rest = _objectWithoutProperties(widgetRecommendParametersOptions, _excluded2$2);
|
|
14879
|
+
return widgets.reduce(function (state, widget) {
|
|
14880
|
+
if (!isIndexWidget(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
|
|
14881
|
+
return widget.getWidgetParameters(state, rest);
|
|
14882
|
+
}
|
|
14883
|
+
return state;
|
|
14884
|
+
}, initialRecommendParameters);
|
|
14885
|
+
}
|
|
14466
14886
|
function resetPageFromWidgets(widgets) {
|
|
14467
14887
|
var indexWidgets = widgets.filter(isIndexWidget);
|
|
14468
14888
|
if (indexWidgets.length === 0) {
|
|
@@ -14472,6 +14892,7 @@
|
|
|
14472
14892
|
var widgetHelper = widget.getHelper();
|
|
14473
14893
|
privateHelperSetState(widgetHelper, {
|
|
14474
14894
|
state: widgetHelper.state.resetPage(),
|
|
14895
|
+
recommendState: widgetHelper.recommendState,
|
|
14475
14896
|
isPageReset: true
|
|
14476
14897
|
});
|
|
14477
14898
|
resetPageFromWidgets(widget.getWidgets());
|
|
@@ -14567,6 +14988,10 @@
|
|
|
14567
14988
|
uiState: localUiState,
|
|
14568
14989
|
initialSearchParameters: helper.state
|
|
14569
14990
|
}),
|
|
14991
|
+
recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
|
|
14992
|
+
uiState: localUiState,
|
|
14993
|
+
initialRecommendParameters: helper.recommendState
|
|
14994
|
+
}),
|
|
14570
14995
|
_uiState: localUiState
|
|
14571
14996
|
});
|
|
14572
14997
|
|
|
@@ -14663,11 +15088,16 @@
|
|
|
14663
15088
|
index: indexName
|
|
14664
15089
|
})
|
|
14665
15090
|
});
|
|
15091
|
+
var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
|
|
15092
|
+
uiState: localUiState,
|
|
15093
|
+
initialRecommendParameters: new algoliasearchHelper_1.RecommendParameters()
|
|
15094
|
+
});
|
|
14666
15095
|
|
|
14667
15096
|
// This Helper is only used for state management we do not care about the
|
|
14668
15097
|
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
|
|
14669
15098
|
// level is aware of the client.
|
|
14670
15099
|
helper = algoliasearchHelper_1({}, parameters.index, parameters);
|
|
15100
|
+
helper.recommendState = recommendParameters;
|
|
14671
15101
|
|
|
14672
15102
|
// We forward the call to `search` to the "main" instance of the Helper
|
|
14673
15103
|
// which is responsible for managing the queries (it's the only one that is
|
|
@@ -14698,6 +15128,8 @@
|
|
|
14698
15128
|
};
|
|
14699
15129
|
derivedHelper = mainHelper.derive(function () {
|
|
14700
15130
|
return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray(resolveSearchParameters(_this3))));
|
|
15131
|
+
}, function () {
|
|
15132
|
+
return _this3.getHelper().recommendState;
|
|
14701
15133
|
});
|
|
14702
15134
|
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
14703
15135
|
if (indexInitialResults) {
|
|
@@ -14746,6 +15178,21 @@
|
|
|
14746
15178
|
lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
|
|
14747
15179
|
});
|
|
14748
15180
|
|
|
15181
|
+
// eslint-disable-next-line no-warning-comments
|
|
15182
|
+
// TODO: listen to "result" event when events for Recommend are implemented
|
|
15183
|
+
derivedHelper.on('recommend:result', function (_ref5) {
|
|
15184
|
+
var recommend = _ref5.recommend;
|
|
15185
|
+
// The index does not render the results it schedules a new render
|
|
15186
|
+
// to let all the other indices emit their own results. It allows us to
|
|
15187
|
+
// run the render process in one pass.
|
|
15188
|
+
instantSearchInstance.scheduleRender();
|
|
15189
|
+
|
|
15190
|
+
// the derived helper is the one which actually searches, but the helper
|
|
15191
|
+
// which is exposed e.g. via instance.helper, doesn't search, and thus
|
|
15192
|
+
// does not have access to lastRecommendResults.
|
|
15193
|
+
helper.lastRecommendResults = recommend.results;
|
|
15194
|
+
});
|
|
15195
|
+
|
|
14749
15196
|
// We compute the render state before calling `init` in a separate loop
|
|
14750
15197
|
// to construct the whole render state object that is then passed to
|
|
14751
15198
|
// `init`.
|
|
@@ -14796,9 +15243,9 @@
|
|
|
14796
15243
|
instantSearchInstance.scheduleRender();
|
|
14797
15244
|
}
|
|
14798
15245
|
},
|
|
14799
|
-
render: function render(
|
|
15246
|
+
render: function render(_ref6) {
|
|
14800
15247
|
var _this4 = this;
|
|
14801
|
-
var instantSearchInstance =
|
|
15248
|
+
var instantSearchInstance = _ref6.instantSearchInstance;
|
|
14802
15249
|
// we can't attach a listener to the error event of search, as the error
|
|
14803
15250
|
// then would no longer be thrown for global handlers.
|
|
14804
15251
|
if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
|
|
@@ -14808,6 +15255,14 @@
|
|
|
14808
15255
|
// We only render index widgets if there are no results.
|
|
14809
15256
|
// This makes sure `render` is never called with `results` being `null`.
|
|
14810
15257
|
var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
15258
|
+
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
15259
|
+
if (!widget.shouldRender) {
|
|
15260
|
+
return true;
|
|
15261
|
+
}
|
|
15262
|
+
return widget.shouldRender({
|
|
15263
|
+
instantSearchInstance: instantSearchInstance
|
|
15264
|
+
});
|
|
15265
|
+
});
|
|
14811
15266
|
widgetsToRender.forEach(function (widget) {
|
|
14812
15267
|
if (widget.getRenderState) {
|
|
14813
15268
|
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
|
|
@@ -14866,8 +15321,8 @@
|
|
|
14866
15321
|
_warning(false, 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.') ;
|
|
14867
15322
|
return this.getWidgetUiState(uiState);
|
|
14868
15323
|
},
|
|
14869
|
-
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters,
|
|
14870
|
-
var uiState =
|
|
15324
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
|
|
15325
|
+
var uiState = _ref7.uiState;
|
|
14871
15326
|
return getLocalWidgetsSearchParameters(localWidgets, {
|
|
14872
15327
|
uiState: uiState,
|
|
14873
15328
|
initialSearchParameters: searchParameters
|
|
@@ -14887,10 +15342,10 @@
|
|
|
14887
15342
|
}
|
|
14888
15343
|
};
|
|
14889
15344
|
};
|
|
14890
|
-
function storeRenderState(
|
|
14891
|
-
var renderState =
|
|
14892
|
-
instantSearchInstance =
|
|
14893
|
-
parent =
|
|
15345
|
+
function storeRenderState(_ref8) {
|
|
15346
|
+
var renderState = _ref8.renderState,
|
|
15347
|
+
instantSearchInstance = _ref8.instantSearchInstance,
|
|
15348
|
+
parent = _ref8.parent;
|
|
14894
15349
|
var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
|
|
14895
15350
|
instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
14896
15351
|
}
|
|
@@ -14960,7 +15415,7 @@
|
|
|
14960
15415
|
};
|
|
14961
15416
|
}
|
|
14962
15417
|
|
|
14963
|
-
var version$1 = '4.
|
|
15418
|
+
var version$1 = '4.67.0';
|
|
14964
15419
|
|
|
14965
15420
|
var withUsage$r = createDocumentationMessageGenerator({
|
|
14966
15421
|
name: 'instantsearch'
|
|
@@ -15323,7 +15778,7 @@
|
|
|
15323
15778
|
// under the hood, we have a different implementation. It should be
|
|
15324
15779
|
// completely transparent for the rest of the codebase. Only this module
|
|
15325
15780
|
// is impacted.
|
|
15326
|
-
return mainHelper.searchOnlyWithDerivedHelpers();
|
|
15781
|
+
return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
|
|
15327
15782
|
};
|
|
15328
15783
|
if (this._searchFunction) {
|
|
15329
15784
|
// this client isn't used to actually search, but required for the helper
|
|
@@ -16636,7 +17091,7 @@
|
|
|
16636
17091
|
}
|
|
16637
17092
|
|
|
16638
17093
|
var _excluded$e = ["hit", "attribute", "cssClasses"],
|
|
16639
|
-
_excluded2$
|
|
17094
|
+
_excluded2$3 = ["isHighlighted"];
|
|
16640
17095
|
function ReverseHighlight$1(_ref) {
|
|
16641
17096
|
var hit = _ref.hit,
|
|
16642
17097
|
attribute = _ref.attribute,
|
|
@@ -16649,7 +17104,7 @@
|
|
|
16649
17104
|
var value = _ref2.value;
|
|
16650
17105
|
return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
|
|
16651
17106
|
var isHighlighted = _ref3.isHighlighted,
|
|
16652
|
-
rest = _objectWithoutProperties(_ref3, _excluded2$
|
|
17107
|
+
rest = _objectWithoutProperties(_ref3, _excluded2$3);
|
|
16653
17108
|
return _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
16654
17109
|
isHighlighted: !isHighlighted
|
|
16655
17110
|
});
|
|
@@ -16677,7 +17132,7 @@
|
|
|
16677
17132
|
}
|
|
16678
17133
|
|
|
16679
17134
|
var _excluded$g = ["hit", "attribute", "cssClasses"],
|
|
16680
|
-
_excluded2$
|
|
17135
|
+
_excluded2$4 = ["isHighlighted"];
|
|
16681
17136
|
function ReverseSnippet$1(_ref) {
|
|
16682
17137
|
var hit = _ref.hit,
|
|
16683
17138
|
attribute = _ref.attribute,
|
|
@@ -16690,7 +17145,7 @@
|
|
|
16690
17145
|
var value = _ref2.value;
|
|
16691
17146
|
return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
|
|
16692
17147
|
var isHighlighted = _ref3.isHighlighted,
|
|
16693
|
-
rest = _objectWithoutProperties(_ref3, _excluded2$
|
|
17148
|
+
rest = _objectWithoutProperties(_ref3, _excluded2$4);
|
|
16694
17149
|
return _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
16695
17150
|
isHighlighted: !isHighlighted
|
|
16696
17151
|
});
|
|
@@ -18041,7 +18496,7 @@
|
|
|
18041
18496
|
};
|
|
18042
18497
|
|
|
18043
18498
|
var _excluded$k = ["initialZoom", "initialPosition", "templates", "cssClasses", "builtInMarker", "customHTMLMarker", "enableRefine", "enableClearMapRefinement", "enableRefineControl", "container", "googleReference"],
|
|
18044
|
-
_excluded2$
|
|
18499
|
+
_excluded2$5 = ["item"],
|
|
18045
18500
|
_excluded3 = ["item"];
|
|
18046
18501
|
var withUsage$y = createDocumentationMessageGenerator({
|
|
18047
18502
|
name: 'geo-search'
|
|
@@ -18143,7 +18598,7 @@
|
|
|
18143
18598
|
var customHTMLMarker = isCustomHTMLMarker && _objectSpread2(_objectSpread2({}, defaultCustomHTMLMarker), userCustomHTMLMarker);
|
|
18144
18599
|
var createBuiltInMarker = function createBuiltInMarker(_ref2) {
|
|
18145
18600
|
var item = _ref2.item,
|
|
18146
|
-
rest = _objectWithoutProperties(_ref2, _excluded2$
|
|
18601
|
+
rest = _objectWithoutProperties(_ref2, _excluded2$5);
|
|
18147
18602
|
return new googleReference.maps.Marker(_objectSpread2(_objectSpread2(_objectSpread2({}, builtInMarker.createOptions(item)), rest), {}, {
|
|
18148
18603
|
// @ts-expect-error @types/googlemaps doesn't document this
|
|
18149
18604
|
__id: item.objectID,
|
|
@@ -20083,7 +20538,7 @@
|
|
|
20083
20538
|
};
|
|
20084
20539
|
|
|
20085
20540
|
var _excluded$n = ["placesReference", "defaultPosition"],
|
|
20086
|
-
_excluded2$
|
|
20541
|
+
_excluded2$6 = ["places"];
|
|
20087
20542
|
|
|
20088
20543
|
/* Places.js is an optional dependency, no error should be reported if the package is missing */
|
|
20089
20544
|
/** @ts-ignore */
|
|
@@ -20139,7 +20594,7 @@
|
|
|
20139
20594
|
var hasPositionSet = position !== defaultPosition.join(',');
|
|
20140
20595
|
if (!hasPositionSet && !state.query) {
|
|
20141
20596
|
var places = uiState.places,
|
|
20142
|
-
uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$
|
|
20597
|
+
uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$6);
|
|
20143
20598
|
return uiStateWithoutPlaces;
|
|
20144
20599
|
}
|
|
20145
20600
|
return _objectSpread2(_objectSpread2({}, uiState), {}, {
|