react-instantsearch-core 7.7.0 → 7.7.2
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/dist/cjs/lib/useWidget.js +2 -2
- package/dist/cjs/version.js +1 -1
- package/dist/es/lib/useWidget.js +2 -2
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +536 -27
- package/dist/umd/ReactInstantSearchCore.js.map +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
- package/package.json +4 -4
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
var React__default = 'default' in React ? React['default'] : React;
|
|
9
9
|
|
|
10
|
-
var version = '7.7.
|
|
10
|
+
var version = '7.7.2';
|
|
11
11
|
|
|
12
12
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
13
13
|
//
|
|
@@ -335,12 +335,15 @@
|
|
|
335
335
|
* This event contains a {@link SearchResults} object and the
|
|
336
336
|
* {@link SearchParameters} corresponding to this answer.
|
|
337
337
|
* @param {AlgoliaSearchHelper} mainHelper the main helper
|
|
338
|
-
* @param {function} fn the function to create the derived state
|
|
338
|
+
* @param {function} fn the function to create the derived state for search
|
|
339
|
+
* @param {function} recommendFn the function to create the derived state for recommendations
|
|
339
340
|
*/
|
|
340
|
-
function DerivedHelper(mainHelper, fn) {
|
|
341
|
+
function DerivedHelper(mainHelper, fn, recommendFn) {
|
|
341
342
|
this.main = mainHelper;
|
|
342
343
|
this.fn = fn;
|
|
344
|
+
this.recommendFn = recommendFn;
|
|
343
345
|
this.lastResults = null;
|
|
346
|
+
this.lastRecommendResults = null;
|
|
344
347
|
}
|
|
345
348
|
|
|
346
349
|
inherits_1(DerivedHelper, events);
|
|
@@ -359,6 +362,10 @@
|
|
|
359
362
|
return this.fn(parameters);
|
|
360
363
|
};
|
|
361
364
|
|
|
365
|
+
DerivedHelper.prototype.getModifiedRecommendState = function (parameters) {
|
|
366
|
+
return this.recommendFn(parameters);
|
|
367
|
+
};
|
|
368
|
+
|
|
362
369
|
var DerivedHelper_1 = DerivedHelper;
|
|
363
370
|
|
|
364
371
|
/**
|
|
@@ -497,6 +504,92 @@
|
|
|
497
504
|
|
|
498
505
|
var omit = _objectWithoutPropertiesLoose;
|
|
499
506
|
|
|
507
|
+
/**
|
|
508
|
+
* RecommendParameters is the data structure that contains all the information
|
|
509
|
+
* usable for getting recommendations from the Algolia API. It doesn't do the
|
|
510
|
+
* search itself, nor does it contains logic about the parameters.
|
|
511
|
+
* It is an immutable object, therefore it has been created in a way that each
|
|
512
|
+
* changes does not change the object itself but returns a copy with the
|
|
513
|
+
* modification.
|
|
514
|
+
* This object should probably not be instantiated outside of the helper. It
|
|
515
|
+
* will be provided when needed.
|
|
516
|
+
* @constructor
|
|
517
|
+
* @classdesc contains all the parameters for recommendations
|
|
518
|
+
* @param {RecommendParametersOptions} opts the options to create the object
|
|
519
|
+
*/
|
|
520
|
+
function RecommendParameters(opts) {
|
|
521
|
+
opts = opts || {};
|
|
522
|
+
this.params = opts.params || [];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
RecommendParameters.prototype = {
|
|
526
|
+
constructor: RecommendParameters,
|
|
527
|
+
|
|
528
|
+
addParams: function (params) {
|
|
529
|
+
var newParams = this.params.slice();
|
|
530
|
+
var existingParamsIndex = this.params.findIndex(function (currentParams) {
|
|
531
|
+
return currentParams.$$id === params.$$id;
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
if (existingParamsIndex !== -1) {
|
|
535
|
+
newParams.splice(existingParamsIndex, 1, params);
|
|
536
|
+
} else {
|
|
537
|
+
newParams.push(params);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return new RecommendParameters({ params: newParams });
|
|
541
|
+
},
|
|
542
|
+
|
|
543
|
+
removeParams: function (id) {
|
|
544
|
+
return new RecommendParameters({
|
|
545
|
+
params: this.params.filter(function (param) {
|
|
546
|
+
return param.$$id !== id;
|
|
547
|
+
}),
|
|
548
|
+
});
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
addFrequentlyBoughtTogether: function (params) {
|
|
552
|
+
return this.addParams(
|
|
553
|
+
Object.assign({}, params, { model: 'bought-together' })
|
|
554
|
+
);
|
|
555
|
+
},
|
|
556
|
+
|
|
557
|
+
addRelatedProducts: function (params) {
|
|
558
|
+
return this.addParams(
|
|
559
|
+
Object.assign({}, params, { model: 'related-products' })
|
|
560
|
+
);
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
addTrendingItems: function (params) {
|
|
564
|
+
return this.addParams(
|
|
565
|
+
Object.assign({}, params, { model: 'trending-items' })
|
|
566
|
+
);
|
|
567
|
+
},
|
|
568
|
+
|
|
569
|
+
addTrendingFacets: function (params) {
|
|
570
|
+
return this.addParams(
|
|
571
|
+
Object.assign({}, params, { model: 'trending-facets' })
|
|
572
|
+
);
|
|
573
|
+
},
|
|
574
|
+
|
|
575
|
+
addLookingSimilar: function (params) {
|
|
576
|
+
return this.addParams(
|
|
577
|
+
Object.assign({}, params, { model: 'looking-similar' })
|
|
578
|
+
);
|
|
579
|
+
},
|
|
580
|
+
|
|
581
|
+
_buildQueries: function (indexName) {
|
|
582
|
+
return this.params.map(function (params) {
|
|
583
|
+
var query = Object.assign({}, params, { indexName: indexName });
|
|
584
|
+
delete query.$$id;
|
|
585
|
+
|
|
586
|
+
return query;
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
var RecommendParameters_1 = RecommendParameters;
|
|
592
|
+
|
|
500
593
|
function sortObject(obj) {
|
|
501
594
|
return Object.keys(obj)
|
|
502
595
|
.sort()
|
|
@@ -4344,7 +4437,7 @@
|
|
|
4344
4437
|
|
|
4345
4438
|
var SearchResults_1 = SearchResults;
|
|
4346
4439
|
|
|
4347
|
-
var version$1 = '3.
|
|
4440
|
+
var version$1 = '3.18.0';
|
|
4348
4441
|
|
|
4349
4442
|
var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
|
|
4350
4443
|
|
|
@@ -4356,6 +4449,7 @@
|
|
|
4356
4449
|
|
|
4357
4450
|
|
|
4358
4451
|
|
|
4452
|
+
|
|
4359
4453
|
/**
|
|
4360
4454
|
* Event triggered when a parameter is set or updated
|
|
4361
4455
|
* @event AlgoliaSearchHelper#event:change
|
|
@@ -4469,11 +4563,18 @@
|
|
|
4469
4563
|
var opts = options || {};
|
|
4470
4564
|
opts.index = index;
|
|
4471
4565
|
this.state = SearchParameters_1.make(opts);
|
|
4566
|
+
this.recommendState = new RecommendParameters_1({
|
|
4567
|
+
params: opts.recommendState,
|
|
4568
|
+
});
|
|
4472
4569
|
this.lastResults = null;
|
|
4570
|
+
this.lastRecommendResults = null;
|
|
4473
4571
|
this._queryId = 0;
|
|
4572
|
+
this._recommendQueryId = 0;
|
|
4474
4573
|
this._lastQueryIdReceived = -1;
|
|
4574
|
+
this._lastRecommendQueryIdReceived = -1;
|
|
4475
4575
|
this.derivedHelpers = [];
|
|
4476
4576
|
this._currentNbQueries = 0;
|
|
4577
|
+
this._currentNbRecommendQueries = 0;
|
|
4477
4578
|
this._searchResultsOptions = searchResultsOptions;
|
|
4478
4579
|
}
|
|
4479
4580
|
|
|
@@ -4500,6 +4601,21 @@
|
|
|
4500
4601
|
return this;
|
|
4501
4602
|
};
|
|
4502
4603
|
|
|
4604
|
+
/**
|
|
4605
|
+
* Sends the recommendation queries set in the state. When the method is
|
|
4606
|
+
* called, it triggers a `fetch` event. The results will be available through
|
|
4607
|
+
* the `result` event. If an error occurs, an `error` will be fired instead.
|
|
4608
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
4609
|
+
* @fires fetch
|
|
4610
|
+
* @fires result
|
|
4611
|
+
* @fires error
|
|
4612
|
+
* @chainable
|
|
4613
|
+
*/
|
|
4614
|
+
AlgoliaSearchHelper.prototype.recommend = function () {
|
|
4615
|
+
this._recommend();
|
|
4616
|
+
return this;
|
|
4617
|
+
};
|
|
4618
|
+
|
|
4503
4619
|
/**
|
|
4504
4620
|
* Gets the search query parameters that would be sent to the Algolia Client
|
|
4505
4621
|
* for the hits
|
|
@@ -4996,6 +5112,86 @@
|
|
|
4996
5112
|
return this;
|
|
4997
5113
|
};
|
|
4998
5114
|
|
|
5115
|
+
/**
|
|
5116
|
+
* Adds a "frequently bought together" recommendation query.
|
|
5117
|
+
*
|
|
5118
|
+
* @param {FrequentlyBoughtTogetherQuery} params the parameters for the recommendation
|
|
5119
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5120
|
+
* @fires change
|
|
5121
|
+
* @chainable
|
|
5122
|
+
*/
|
|
5123
|
+
AlgoliaSearchHelper.prototype.addFrequentlyBoughtTogether = function (params) {
|
|
5124
|
+
this._recommendChange({
|
|
5125
|
+
state: this.recommendState.addFrequentlyBoughtTogether(params),
|
|
5126
|
+
});
|
|
5127
|
+
|
|
5128
|
+
return this;
|
|
5129
|
+
};
|
|
5130
|
+
|
|
5131
|
+
/**
|
|
5132
|
+
* Adds a "related products" recommendation query.
|
|
5133
|
+
*
|
|
5134
|
+
* @param {RelatedProductsQuery} params the parameters for the recommendation
|
|
5135
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5136
|
+
* @fires change
|
|
5137
|
+
* @chainable
|
|
5138
|
+
*/
|
|
5139
|
+
AlgoliaSearchHelper.prototype.addRelatedProducts = function (params) {
|
|
5140
|
+
this._recommendChange({
|
|
5141
|
+
state: this.recommendState.addRelatedProducts(params),
|
|
5142
|
+
});
|
|
5143
|
+
|
|
5144
|
+
return this;
|
|
5145
|
+
};
|
|
5146
|
+
|
|
5147
|
+
/**
|
|
5148
|
+
* Adds a "trending items" recommendation query.
|
|
5149
|
+
*
|
|
5150
|
+
* @param {TrendingItemsQuery} params the parameters for the recommendation
|
|
5151
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5152
|
+
* @fires change
|
|
5153
|
+
* @chainable
|
|
5154
|
+
*/
|
|
5155
|
+
AlgoliaSearchHelper.prototype.addTrendingItems = function (params) {
|
|
5156
|
+
this._recommendChange({
|
|
5157
|
+
state: this.recommendState.addTrendingItems(params),
|
|
5158
|
+
});
|
|
5159
|
+
|
|
5160
|
+
return this;
|
|
5161
|
+
};
|
|
5162
|
+
|
|
5163
|
+
/**
|
|
5164
|
+
* Adds a "trending facets" recommendation query.
|
|
5165
|
+
*
|
|
5166
|
+
* @param {TrendingFacetsQuery} params the parameters for the recommendation
|
|
5167
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5168
|
+
* @fires change
|
|
5169
|
+
* @chainable
|
|
5170
|
+
*/
|
|
5171
|
+
AlgoliaSearchHelper.prototype.addTrendingFacets = function (params) {
|
|
5172
|
+
this._recommendChange({
|
|
5173
|
+
state: this.recommendState.addTrendingFacets(params),
|
|
5174
|
+
});
|
|
5175
|
+
|
|
5176
|
+
return this;
|
|
5177
|
+
};
|
|
5178
|
+
|
|
5179
|
+
/**
|
|
5180
|
+
* Adds a "looking similar" recommendation query.
|
|
5181
|
+
*
|
|
5182
|
+
* @param {LookingSimilarQuery} params the parameters for the recommendation
|
|
5183
|
+
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5184
|
+
* @fires change
|
|
5185
|
+
* @chainable
|
|
5186
|
+
*/
|
|
5187
|
+
AlgoliaSearchHelper.prototype.addLookingSimilar = function (params) {
|
|
5188
|
+
this._recommendChange({
|
|
5189
|
+
state: this.recommendState.addLookingSimilar(params),
|
|
5190
|
+
});
|
|
5191
|
+
|
|
5192
|
+
return this;
|
|
5193
|
+
};
|
|
5194
|
+
|
|
4999
5195
|
/**
|
|
5000
5196
|
* Removes an numeric filter to an attribute with the `operator` and `value` provided. If the
|
|
5001
5197
|
* filter is not set, it doesn't change the filters.
|
|
@@ -5165,6 +5361,86 @@
|
|
|
5165
5361
|
return this;
|
|
5166
5362
|
};
|
|
5167
5363
|
|
|
5364
|
+
/**
|
|
5365
|
+
* Removes a "frequently bought together" recommendation query.
|
|
5366
|
+
*
|
|
5367
|
+
* @param {string} id identifier of the recommendation widget
|
|
5368
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5369
|
+
* @fires change
|
|
5370
|
+
* @chainable
|
|
5371
|
+
*/
|
|
5372
|
+
AlgoliaSearchHelper.prototype.removeFrequentlyBoughtTogether = function (id) {
|
|
5373
|
+
this._recommendChange({
|
|
5374
|
+
state: this.recommendState.removeParams(id),
|
|
5375
|
+
});
|
|
5376
|
+
|
|
5377
|
+
return this;
|
|
5378
|
+
};
|
|
5379
|
+
|
|
5380
|
+
/**
|
|
5381
|
+
* Removes a "related products" recommendation query.
|
|
5382
|
+
*
|
|
5383
|
+
* @param {string} id identifier of the recommendation widget
|
|
5384
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5385
|
+
* @fires change
|
|
5386
|
+
* @chainable
|
|
5387
|
+
*/
|
|
5388
|
+
AlgoliaSearchHelper.prototype.removeRelatedProducts = function (id) {
|
|
5389
|
+
this._recommendChange({
|
|
5390
|
+
state: this.recommendState.removeParams(id),
|
|
5391
|
+
});
|
|
5392
|
+
|
|
5393
|
+
return this;
|
|
5394
|
+
};
|
|
5395
|
+
|
|
5396
|
+
/**
|
|
5397
|
+
* Removes a "trending items" recommendation query.
|
|
5398
|
+
*
|
|
5399
|
+
* @param {string} id identifier of the recommendation widget
|
|
5400
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5401
|
+
* @fires change
|
|
5402
|
+
* @chainable
|
|
5403
|
+
*/
|
|
5404
|
+
AlgoliaSearchHelper.prototype.removeTrendingItems = function (id) {
|
|
5405
|
+
this._recommendChange({
|
|
5406
|
+
state: this.recommendState.removeParams(id),
|
|
5407
|
+
});
|
|
5408
|
+
|
|
5409
|
+
return this;
|
|
5410
|
+
};
|
|
5411
|
+
|
|
5412
|
+
/**
|
|
5413
|
+
* Removes a "trending facets" recommendation query.
|
|
5414
|
+
*
|
|
5415
|
+
* @param {string} id identifier of the recommendation widget
|
|
5416
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5417
|
+
* @fires change
|
|
5418
|
+
* @chainable
|
|
5419
|
+
*/
|
|
5420
|
+
AlgoliaSearchHelper.prototype.removeTrendingFacets = function (id) {
|
|
5421
|
+
this._recommendChange({
|
|
5422
|
+
state: this.recommendState.removeParams(id),
|
|
5423
|
+
});
|
|
5424
|
+
|
|
5425
|
+
return this;
|
|
5426
|
+
};
|
|
5427
|
+
|
|
5428
|
+
/**
|
|
5429
|
+
* Removes a "looking similar" recommendation query.
|
|
5430
|
+
*
|
|
5431
|
+
* @param {string} id identifier of the recommendation widget
|
|
5432
|
+
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
5433
|
+
* @fires change
|
|
5434
|
+
* @chainable
|
|
5435
|
+
*/
|
|
5436
|
+
AlgoliaSearchHelper.prototype.removeLookingSimilar = function (id) {
|
|
5437
|
+
this._recommendChange({
|
|
5438
|
+
state: this.recommendState.removeParams(id),
|
|
5439
|
+
});
|
|
5440
|
+
|
|
5441
|
+
return this;
|
|
5442
|
+
};
|
|
5443
|
+
|
|
5168
5444
|
/**
|
|
5169
5445
|
* Adds or removes an exclusion filter to a faceted attribute with the `value` provided. If
|
|
5170
5446
|
* the value is set then it removes it, otherwise it adds the filter.
|
|
@@ -5732,6 +6008,85 @@
|
|
|
5732
6008
|
return undefined;
|
|
5733
6009
|
};
|
|
5734
6010
|
|
|
6011
|
+
AlgoliaSearchHelper.prototype._recommend = function () {
|
|
6012
|
+
var searchState = this.state;
|
|
6013
|
+
var recommendState = this.recommendState;
|
|
6014
|
+
var index = this.getIndex();
|
|
6015
|
+
var states = [{ state: recommendState, index: index, helper: this }];
|
|
6016
|
+
|
|
6017
|
+
this.emit('fetch', {
|
|
6018
|
+
recommend: {
|
|
6019
|
+
state: recommendState,
|
|
6020
|
+
results: this.lastRecommendResults,
|
|
6021
|
+
},
|
|
6022
|
+
});
|
|
6023
|
+
|
|
6024
|
+
var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
|
|
6025
|
+
var derivedIndex = derivedHelper.getModifiedState(searchState).index;
|
|
6026
|
+
if (!derivedIndex) {
|
|
6027
|
+
return [];
|
|
6028
|
+
}
|
|
6029
|
+
|
|
6030
|
+
// Contrary to what is done when deriving the search state, we don't want to
|
|
6031
|
+
// provide the current recommend state to the derived helper, as it would
|
|
6032
|
+
// inherit unwanted queries. We instead provide an empty recommend state.
|
|
6033
|
+
var derivedState = derivedHelper.getModifiedRecommendState(
|
|
6034
|
+
new RecommendParameters_1()
|
|
6035
|
+
);
|
|
6036
|
+
states.push({
|
|
6037
|
+
state: derivedState,
|
|
6038
|
+
index: derivedIndex,
|
|
6039
|
+
helper: derivedHelper,
|
|
6040
|
+
});
|
|
6041
|
+
|
|
6042
|
+
derivedHelper.emit('fetch', {
|
|
6043
|
+
recommend: {
|
|
6044
|
+
state: derivedState,
|
|
6045
|
+
results: derivedHelper.lastRecommendResults,
|
|
6046
|
+
},
|
|
6047
|
+
});
|
|
6048
|
+
|
|
6049
|
+
return derivedState._buildQueries(derivedIndex);
|
|
6050
|
+
});
|
|
6051
|
+
|
|
6052
|
+
var queries = Array.prototype.concat.apply(
|
|
6053
|
+
this.recommendState._buildQueries(index),
|
|
6054
|
+
derivedQueries
|
|
6055
|
+
);
|
|
6056
|
+
|
|
6057
|
+
if (queries.length === 0) {
|
|
6058
|
+
return;
|
|
6059
|
+
}
|
|
6060
|
+
|
|
6061
|
+
if (
|
|
6062
|
+
queries.length > 0 &&
|
|
6063
|
+
typeof this.client.getRecommendations === 'undefined'
|
|
6064
|
+
) {
|
|
6065
|
+
// eslint-disable-next-line no-console
|
|
6066
|
+
console.warn(
|
|
6067
|
+
'Please update algoliasearch/lite to the latest version in order to use recommendations widgets.'
|
|
6068
|
+
);
|
|
6069
|
+
return;
|
|
6070
|
+
}
|
|
6071
|
+
|
|
6072
|
+
var queryId = this._recommendQueryId++;
|
|
6073
|
+
this._currentNbRecommendQueries++;
|
|
6074
|
+
|
|
6075
|
+
try {
|
|
6076
|
+
this.client
|
|
6077
|
+
.getRecommendations(queries)
|
|
6078
|
+
.then(this._dispatchRecommendResponse.bind(this, queryId, states))
|
|
6079
|
+
.catch(this._dispatchRecommendError.bind(this, queryId));
|
|
6080
|
+
} catch (error) {
|
|
6081
|
+
// If we reach this part, we're in an internal error state
|
|
6082
|
+
this.emit('error', {
|
|
6083
|
+
error: error,
|
|
6084
|
+
});
|
|
6085
|
+
}
|
|
6086
|
+
|
|
6087
|
+
return;
|
|
6088
|
+
};
|
|
6089
|
+
|
|
5735
6090
|
/**
|
|
5736
6091
|
* Transform the responses as sent by the server and transform them into a user
|
|
5737
6092
|
* usable object that merge the results of all the batch requests. It will dispatch
|
|
@@ -5791,6 +6146,53 @@
|
|
|
5791
6146
|
});
|
|
5792
6147
|
};
|
|
5793
6148
|
|
|
6149
|
+
AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
|
|
6150
|
+
queryId,
|
|
6151
|
+
states,
|
|
6152
|
+
content
|
|
6153
|
+
) {
|
|
6154
|
+
// @TODO remove the number of outdated queries discarded instead of just one
|
|
6155
|
+
|
|
6156
|
+
if (queryId < this._lastRecommendQueryIdReceived) {
|
|
6157
|
+
// Outdated answer
|
|
6158
|
+
return;
|
|
6159
|
+
}
|
|
6160
|
+
|
|
6161
|
+
this._currentNbRecommendQueries -=
|
|
6162
|
+
queryId - this._lastRecommendQueryIdReceived;
|
|
6163
|
+
this._lastRecommendQueryIdReceived = queryId;
|
|
6164
|
+
|
|
6165
|
+
if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
|
|
6166
|
+
|
|
6167
|
+
var results = content.results.slice();
|
|
6168
|
+
|
|
6169
|
+
states.forEach(function (s) {
|
|
6170
|
+
var state = s.state;
|
|
6171
|
+
var helper = s.helper;
|
|
6172
|
+
|
|
6173
|
+
if (!s.index) {
|
|
6174
|
+
// eslint-disable-next-line no-warning-comments
|
|
6175
|
+
// TODO: emit "result" event when events for Recommend are implemented
|
|
6176
|
+
helper.emit('recommend:result', {
|
|
6177
|
+
results: null,
|
|
6178
|
+
state: state,
|
|
6179
|
+
});
|
|
6180
|
+
return;
|
|
6181
|
+
}
|
|
6182
|
+
|
|
6183
|
+
helper.lastRecommendResults = results;
|
|
6184
|
+
|
|
6185
|
+
// eslint-disable-next-line no-warning-comments
|
|
6186
|
+
// TODO: emit "result" event when events for Recommend are implemented
|
|
6187
|
+
helper.emit('recommend:result', {
|
|
6188
|
+
recommend: {
|
|
6189
|
+
results: helper.lastRecommendResults,
|
|
6190
|
+
state: state,
|
|
6191
|
+
},
|
|
6192
|
+
});
|
|
6193
|
+
});
|
|
6194
|
+
};
|
|
6195
|
+
|
|
5794
6196
|
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
|
|
5795
6197
|
queryId,
|
|
5796
6198
|
error
|
|
@@ -5810,6 +6212,26 @@
|
|
|
5810
6212
|
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
|
|
5811
6213
|
};
|
|
5812
6214
|
|
|
6215
|
+
AlgoliaSearchHelper.prototype._dispatchRecommendError = function (
|
|
6216
|
+
queryId,
|
|
6217
|
+
error
|
|
6218
|
+
) {
|
|
6219
|
+
if (queryId < this._lastRecommendQueryIdReceived) {
|
|
6220
|
+
// Outdated answer
|
|
6221
|
+
return;
|
|
6222
|
+
}
|
|
6223
|
+
|
|
6224
|
+
this._currentNbRecommendQueries -=
|
|
6225
|
+
queryId - this._lastRecommendQueryIdReceived;
|
|
6226
|
+
this._lastRecommendQueryIdReceived = queryId;
|
|
6227
|
+
|
|
6228
|
+
this.emit('error', {
|
|
6229
|
+
error: error,
|
|
6230
|
+
});
|
|
6231
|
+
|
|
6232
|
+
if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
|
|
6233
|
+
};
|
|
6234
|
+
|
|
5813
6235
|
AlgoliaSearchHelper.prototype.containsRefinement = function (
|
|
5814
6236
|
query,
|
|
5815
6237
|
facetFilters,
|
|
@@ -5852,6 +6274,27 @@
|
|
|
5852
6274
|
}
|
|
5853
6275
|
};
|
|
5854
6276
|
|
|
6277
|
+
AlgoliaSearchHelper.prototype._recommendChange = function (event) {
|
|
6278
|
+
var state = event.state;
|
|
6279
|
+
|
|
6280
|
+
if (state !== this.recommendState) {
|
|
6281
|
+
this.recommendState = state;
|
|
6282
|
+
|
|
6283
|
+
// eslint-disable-next-line no-warning-comments
|
|
6284
|
+
// TODO: emit "change" event when events for Recommend are implemented
|
|
6285
|
+
this.emit('recommend:change', {
|
|
6286
|
+
search: {
|
|
6287
|
+
results: this.lastResults,
|
|
6288
|
+
state: this.state,
|
|
6289
|
+
},
|
|
6290
|
+
recommend: {
|
|
6291
|
+
results: this.lastRecommendResults,
|
|
6292
|
+
state: this.recommendState,
|
|
6293
|
+
},
|
|
6294
|
+
});
|
|
6295
|
+
}
|
|
6296
|
+
};
|
|
6297
|
+
|
|
5855
6298
|
/**
|
|
5856
6299
|
* Clears the cache of the underlying Algolia client.
|
|
5857
6300
|
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
@@ -5903,10 +6346,11 @@
|
|
|
5903
6346
|
* and the SearchParameters that is returned by the call of the
|
|
5904
6347
|
* parameter function.
|
|
5905
6348
|
* @param {function} fn SearchParameters -> SearchParameters
|
|
6349
|
+
* @param {function} recommendFn RecommendParameters -> RecommendParameters
|
|
5906
6350
|
* @return {DerivedHelper} a new DerivedHelper
|
|
5907
6351
|
*/
|
|
5908
|
-
AlgoliaSearchHelper.prototype.derive = function (fn) {
|
|
5909
|
-
var derivedHelper = new DerivedHelper_1(this, fn);
|
|
6352
|
+
AlgoliaSearchHelper.prototype.derive = function (fn, recommendFn) {
|
|
6353
|
+
var derivedHelper = new DerivedHelper_1(this, fn, recommendFn);
|
|
5910
6354
|
this.derivedHelpers.push(derivedHelper);
|
|
5911
6355
|
return derivedHelper;
|
|
5912
6356
|
};
|
|
@@ -6008,6 +6452,13 @@
|
|
|
6008
6452
|
*/
|
|
6009
6453
|
algoliasearchHelper.SearchParameters = SearchParameters_1;
|
|
6010
6454
|
|
|
6455
|
+
/**
|
|
6456
|
+
* Constructor for the object containing all the parameters for Recommend.
|
|
6457
|
+
* @member module:algoliasearchHelper.RecommendParameters
|
|
6458
|
+
* @type {RecommendParameters}
|
|
6459
|
+
*/
|
|
6460
|
+
algoliasearchHelper.RecommendParameters = RecommendParameters_1;
|
|
6461
|
+
|
|
6011
6462
|
/**
|
|
6012
6463
|
* Constructor for the object containing the results of the search.
|
|
6013
6464
|
* @member module:algoliasearchHelper.SearchResults
|
|
@@ -8438,7 +8889,7 @@
|
|
|
8438
8889
|
|
|
8439
8890
|
// Scenario 1: the widget is added for the first time.
|
|
8440
8891
|
if (!cleanupTimerRef.current) {
|
|
8441
|
-
if (!
|
|
8892
|
+
if (!shouldSsr) {
|
|
8442
8893
|
parentIndex.addWidgets([widget]);
|
|
8443
8894
|
}
|
|
8444
8895
|
}
|
|
@@ -8475,7 +8926,7 @@
|
|
|
8475
8926
|
});
|
|
8476
8927
|
});
|
|
8477
8928
|
};
|
|
8478
|
-
}, [parentIndex, widget,
|
|
8929
|
+
}, [parentIndex, widget, shouldSsr, search, props]);
|
|
8479
8930
|
if (shouldAddWidgetEarly || (waitingForResultsRef === null || waitingForResultsRef === void 0 ? void 0 : (_waitingForResultsRef = waitingForResultsRef.current) === null || _waitingForResultsRef === void 0 ? void 0 : _waitingForResultsRef.status) === 'pending') {
|
|
8480
8931
|
parentIndex.addWidgets([widget]);
|
|
8481
8932
|
}
|
|
@@ -8875,7 +9326,8 @@
|
|
|
8875
9326
|
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
8876
9327
|
}, _typeof$c(obj);
|
|
8877
9328
|
}
|
|
8878
|
-
var _excluded$3 = ["initialSearchParameters"]
|
|
9329
|
+
var _excluded$3 = ["initialSearchParameters"],
|
|
9330
|
+
_excluded2$1 = ["initialRecommendParameters"];
|
|
8879
9331
|
function ownKeys$b(object, enumerableOnly) {
|
|
8880
9332
|
var keys = Object.keys(object);
|
|
8881
9333
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -8987,6 +9439,7 @@
|
|
|
8987
9439
|
*/
|
|
8988
9440
|
function privateHelperSetState(helper, _ref) {
|
|
8989
9441
|
var state = _ref.state,
|
|
9442
|
+
recommendState = _ref.recommendState,
|
|
8990
9443
|
isPageReset = _ref.isPageReset,
|
|
8991
9444
|
_uiState = _ref._uiState;
|
|
8992
9445
|
if (state !== helper.state) {
|
|
@@ -8998,7 +9451,14 @@
|
|
|
8998
9451
|
_uiState: _uiState
|
|
8999
9452
|
});
|
|
9000
9453
|
}
|
|
9454
|
+
if (recommendState !== helper.recommendState) {
|
|
9455
|
+
helper.recommendState = recommendState;
|
|
9456
|
+
|
|
9457
|
+
// eslint-disable-next-line no-warning-comments
|
|
9458
|
+
// TODO: emit "change" event when events for Recommend are implemented
|
|
9459
|
+
}
|
|
9001
9460
|
}
|
|
9461
|
+
|
|
9002
9462
|
function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
9003
9463
|
var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
9004
9464
|
return widgets.reduce(function (uiState, widget) {
|
|
@@ -9017,15 +9477,26 @@
|
|
|
9017
9477
|
function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
|
|
9018
9478
|
var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
|
|
9019
9479
|
rest = _objectWithoutProperties$2(widgetSearchParametersOptions, _excluded$3);
|
|
9020
|
-
return widgets.
|
|
9021
|
-
|
|
9022
|
-
}).reduce(function (state, widget) {
|
|
9023
|
-
if (!widget.getWidgetSearchParameters) {
|
|
9480
|
+
return widgets.reduce(function (state, widget) {
|
|
9481
|
+
if (!widget.getWidgetSearchParameters || isIndexWidget(widget)) {
|
|
9024
9482
|
return state;
|
|
9025
9483
|
}
|
|
9484
|
+
if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
|
|
9485
|
+
return widget.getWidgetParameters(state, rest);
|
|
9486
|
+
}
|
|
9026
9487
|
return widget.getWidgetSearchParameters(state, rest);
|
|
9027
9488
|
}, initialSearchParameters);
|
|
9028
9489
|
}
|
|
9490
|
+
function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
|
|
9491
|
+
var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
|
|
9492
|
+
rest = _objectWithoutProperties$2(widgetRecommendParametersOptions, _excluded2$1);
|
|
9493
|
+
return widgets.reduce(function (state, widget) {
|
|
9494
|
+
if (!isIndexWidget(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
|
|
9495
|
+
return widget.getWidgetParameters(state, rest);
|
|
9496
|
+
}
|
|
9497
|
+
return state;
|
|
9498
|
+
}, initialRecommendParameters);
|
|
9499
|
+
}
|
|
9029
9500
|
function resetPageFromWidgets(widgets) {
|
|
9030
9501
|
var indexWidgets = widgets.filter(isIndexWidget);
|
|
9031
9502
|
if (indexWidgets.length === 0) {
|
|
@@ -9035,6 +9506,7 @@
|
|
|
9035
9506
|
var widgetHelper = widget.getHelper();
|
|
9036
9507
|
privateHelperSetState(widgetHelper, {
|
|
9037
9508
|
state: widgetHelper.state.resetPage(),
|
|
9509
|
+
recommendState: widgetHelper.recommendState,
|
|
9038
9510
|
isPageReset: true
|
|
9039
9511
|
});
|
|
9040
9512
|
resetPageFromWidgets(widget.getWidgets());
|
|
@@ -9130,6 +9602,10 @@
|
|
|
9130
9602
|
uiState: localUiState,
|
|
9131
9603
|
initialSearchParameters: helper.state
|
|
9132
9604
|
}),
|
|
9605
|
+
recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
|
|
9606
|
+
uiState: localUiState,
|
|
9607
|
+
initialRecommendParameters: helper.recommendState
|
|
9608
|
+
}),
|
|
9133
9609
|
_uiState: localUiState
|
|
9134
9610
|
});
|
|
9135
9611
|
|
|
@@ -9226,11 +9702,16 @@
|
|
|
9226
9702
|
index: indexName
|
|
9227
9703
|
})
|
|
9228
9704
|
});
|
|
9705
|
+
var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
|
|
9706
|
+
uiState: localUiState,
|
|
9707
|
+
initialRecommendParameters: new algoliasearchHelper_1.RecommendParameters()
|
|
9708
|
+
});
|
|
9229
9709
|
|
|
9230
9710
|
// This Helper is only used for state management we do not care about the
|
|
9231
9711
|
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
|
|
9232
9712
|
// level is aware of the client.
|
|
9233
9713
|
helper = algoliasearchHelper_1({}, parameters.index, parameters);
|
|
9714
|
+
helper.recommendState = recommendParameters;
|
|
9234
9715
|
|
|
9235
9716
|
// We forward the call to `search` to the "main" instance of the Helper
|
|
9236
9717
|
// which is responsible for managing the queries (it's the only one that is
|
|
@@ -9261,6 +9742,8 @@
|
|
|
9261
9742
|
};
|
|
9262
9743
|
derivedHelper = mainHelper.derive(function () {
|
|
9263
9744
|
return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
|
|
9745
|
+
}, function () {
|
|
9746
|
+
return _this3.getHelper().recommendState;
|
|
9264
9747
|
});
|
|
9265
9748
|
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
9266
9749
|
if (indexInitialResults) {
|
|
@@ -9303,6 +9786,21 @@
|
|
|
9303
9786
|
lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
|
|
9304
9787
|
});
|
|
9305
9788
|
|
|
9789
|
+
// eslint-disable-next-line no-warning-comments
|
|
9790
|
+
// TODO: listen to "result" event when events for Recommend are implemented
|
|
9791
|
+
derivedHelper.on('recommend:result', function (_ref5) {
|
|
9792
|
+
var recommend = _ref5.recommend;
|
|
9793
|
+
// The index does not render the results it schedules a new render
|
|
9794
|
+
// to let all the other indices emit their own results. It allows us to
|
|
9795
|
+
// run the render process in one pass.
|
|
9796
|
+
instantSearchInstance.scheduleRender();
|
|
9797
|
+
|
|
9798
|
+
// the derived helper is the one which actually searches, but the helper
|
|
9799
|
+
// which is exposed e.g. via instance.helper, doesn't search, and thus
|
|
9800
|
+
// does not have access to lastRecommendResults.
|
|
9801
|
+
helper.lastRecommendResults = recommend.results;
|
|
9802
|
+
});
|
|
9803
|
+
|
|
9306
9804
|
// We compute the render state before calling `init` in a separate loop
|
|
9307
9805
|
// to construct the whole render state object that is then passed to
|
|
9308
9806
|
// `init`.
|
|
@@ -9349,9 +9847,9 @@
|
|
|
9349
9847
|
instantSearchInstance.scheduleRender();
|
|
9350
9848
|
}
|
|
9351
9849
|
},
|
|
9352
|
-
render: function render(
|
|
9850
|
+
render: function render(_ref6) {
|
|
9353
9851
|
var _this4 = this;
|
|
9354
|
-
var instantSearchInstance =
|
|
9852
|
+
var instantSearchInstance = _ref6.instantSearchInstance;
|
|
9355
9853
|
// we can't attach a listener to the error event of search, as the error
|
|
9356
9854
|
// then would no longer be thrown for global handlers.
|
|
9357
9855
|
if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
|
|
@@ -9361,6 +9859,14 @@
|
|
|
9361
9859
|
// We only render index widgets if there are no results.
|
|
9362
9860
|
// This makes sure `render` is never called with `results` being `null`.
|
|
9363
9861
|
var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
9862
|
+
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
9863
|
+
if (!widget.shouldRender) {
|
|
9864
|
+
return true;
|
|
9865
|
+
}
|
|
9866
|
+
return widget.shouldRender({
|
|
9867
|
+
instantSearchInstance: instantSearchInstance
|
|
9868
|
+
});
|
|
9869
|
+
});
|
|
9364
9870
|
widgetsToRender.forEach(function (widget) {
|
|
9365
9871
|
if (widget.getRenderState) {
|
|
9366
9872
|
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
|
|
@@ -9418,8 +9924,8 @@
|
|
|
9418
9924
|
getWidgetState: function getWidgetState(uiState) {
|
|
9419
9925
|
return this.getWidgetUiState(uiState);
|
|
9420
9926
|
},
|
|
9421
|
-
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters,
|
|
9422
|
-
var uiState =
|
|
9927
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
|
|
9928
|
+
var uiState = _ref7.uiState;
|
|
9423
9929
|
return getLocalWidgetsSearchParameters(localWidgets, {
|
|
9424
9930
|
uiState: uiState,
|
|
9425
9931
|
initialSearchParameters: searchParameters
|
|
@@ -9439,10 +9945,10 @@
|
|
|
9439
9945
|
}
|
|
9440
9946
|
};
|
|
9441
9947
|
};
|
|
9442
|
-
function storeRenderState(
|
|
9443
|
-
var renderState =
|
|
9444
|
-
instantSearchInstance =
|
|
9445
|
-
parent =
|
|
9948
|
+
function storeRenderState(_ref8) {
|
|
9949
|
+
var renderState = _ref8.renderState,
|
|
9950
|
+
instantSearchInstance = _ref8.instantSearchInstance,
|
|
9951
|
+
parent = _ref8.parent;
|
|
9446
9952
|
var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
|
|
9447
9953
|
instantSearchInstance.renderState = _objectSpread$a(_objectSpread$a({}, instantSearchInstance.renderState), {}, _defineProperty$b({}, parentIndexName, _objectSpread$a(_objectSpread$a({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
9448
9954
|
}
|
|
@@ -11707,7 +12213,7 @@
|
|
|
11707
12213
|
};
|
|
11708
12214
|
}
|
|
11709
12215
|
|
|
11710
|
-
var version$2 = '4.
|
|
12216
|
+
var version$2 = '4.67.0';
|
|
11711
12217
|
|
|
11712
12218
|
function _typeof$k(obj) {
|
|
11713
12219
|
"@babel/helpers - typeof";
|
|
@@ -12201,7 +12707,7 @@
|
|
|
12201
12707
|
// under the hood, we have a different implementation. It should be
|
|
12202
12708
|
// completely transparent for the rest of the codebase. Only this module
|
|
12203
12709
|
// is impacted.
|
|
12204
|
-
return mainHelper.searchOnlyWithDerivedHelpers();
|
|
12710
|
+
return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
|
|
12205
12711
|
};
|
|
12206
12712
|
if (this._searchFunction) {
|
|
12207
12713
|
// this client isn't used to actually search, but required for the helper
|
|
@@ -14221,6 +14727,8 @@
|
|
|
14221
14727
|
if (!escapeHTML) {
|
|
14222
14728
|
return state;
|
|
14223
14729
|
}
|
|
14730
|
+
|
|
14731
|
+
// @MAJOR: set this globally, not in the Hits widget to allow Hits to be conditionally used
|
|
14224
14732
|
return state.setQueryParameters(TAG_PLACEHOLDER);
|
|
14225
14733
|
}
|
|
14226
14734
|
};
|
|
@@ -14463,7 +14971,7 @@
|
|
|
14463
14971
|
}, _typeof$s(obj);
|
|
14464
14972
|
}
|
|
14465
14973
|
var _excluded$9 = ["page"],
|
|
14466
|
-
_excluded2$
|
|
14974
|
+
_excluded2$2 = ["clickAnalytics", "userToken"];
|
|
14467
14975
|
function ownKeys$o(object, enumerableOnly) {
|
|
14468
14976
|
var keys = Object.keys(object);
|
|
14469
14977
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -14579,7 +15087,7 @@
|
|
|
14579
15087
|
var _ref2 = state || {},
|
|
14580
15088
|
clickAnalytics = _ref2.clickAnalytics,
|
|
14581
15089
|
userToken = _ref2.userToken,
|
|
14582
|
-
rest = _objectWithoutProperties$5(_ref2, _excluded2$
|
|
15090
|
+
rest = _objectWithoutProperties$5(_ref2, _excluded2$2);
|
|
14583
15091
|
return rest;
|
|
14584
15092
|
}
|
|
14585
15093
|
function getInMemoryCache() {
|
|
@@ -14800,6 +15308,7 @@
|
|
|
14800
15308
|
var uiState = _ref10.uiState;
|
|
14801
15309
|
var widgetSearchParameters = searchParameters;
|
|
14802
15310
|
if (escapeHTML) {
|
|
15311
|
+
// @MAJOR: set this globally, not in the InfiniteHits widget to allow InfiniteHits to be conditionally used
|
|
14803
15312
|
widgetSearchParameters = searchParameters.setQueryParameters(TAG_PLACEHOLDER);
|
|
14804
15313
|
}
|
|
14805
15314
|
|
|
@@ -16517,7 +17026,7 @@
|
|
|
16517
17026
|
}, _typeof$z(obj);
|
|
16518
17027
|
}
|
|
16519
17028
|
var _excluded$b = ["name", "escapedValue"],
|
|
16520
|
-
_excluded2$
|
|
17029
|
+
_excluded2$3 = ["escapedValue", "value"];
|
|
16521
17030
|
function ownKeys$u(object, enumerableOnly) {
|
|
16522
17031
|
var keys = Object.keys(object);
|
|
16523
17032
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -16702,7 +17211,7 @@
|
|
|
16702
17211
|
var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
|
|
16703
17212
|
var escapedValue = _ref3.escapedValue,
|
|
16704
17213
|
value = _ref3.value,
|
|
16705
|
-
item = _objectWithoutProperties$7(_ref3, _excluded2$
|
|
17214
|
+
item = _objectWithoutProperties$7(_ref3, _excluded2$3);
|
|
16706
17215
|
return _objectSpread$t(_objectSpread$t({}, item), {}, {
|
|
16707
17216
|
value: escapedValue,
|
|
16708
17217
|
label: value
|