algoliasearch-helper 3.18.0 → 3.20.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/dist/algoliasearch.helper.js +189 -48
- package/dist/algoliasearch.helper.js.map +10 -4
- package/dist/algoliasearch.helper.min.js +2 -2
- package/dist/algoliasearch.helper.min.js.map +1 -1
- package/index.d.ts +68 -10
- package/package.json +2 -2
- package/src/RecommendParameters/index.js +11 -14
- package/src/RecommendResults/index.js +28 -0
- package/src/algoliasearch.helper.js +59 -11
- package/src/functions/flat.js +6 -0
- package/src/utils/sortAndMergeRecommendations.js +56 -0
- package/src/version.js +1 -1
|
@@ -383,7 +383,7 @@ algoliasearchHelper.SearchResults = SearchResults;
|
|
|
383
383
|
|
|
384
384
|
module.exports = algoliasearchHelper;
|
|
385
385
|
|
|
386
|
-
},{"./src/RecommendParameters":4,"./src/SearchParameters":
|
|
386
|
+
},{"./src/RecommendParameters":4,"./src/SearchParameters":7,"./src/SearchResults":9,"./src/algoliasearch.helper":10,"./src/version":28}],3:[function(require,module,exports){
|
|
387
387
|
'use strict';
|
|
388
388
|
|
|
389
389
|
var EventEmitter = require('@algolia/events');
|
|
@@ -433,7 +433,7 @@ DerivedHelper.prototype.getModifiedRecommendState = function (parameters) {
|
|
|
433
433
|
|
|
434
434
|
module.exports = DerivedHelper;
|
|
435
435
|
|
|
436
|
-
},{"../functions/inherits":
|
|
436
|
+
},{"../functions/inherits":18,"@algolia/events":1}],4:[function(require,module,exports){
|
|
437
437
|
'use strict';
|
|
438
438
|
|
|
439
439
|
/**
|
|
@@ -459,15 +459,8 @@ RecommendParameters.prototype = {
|
|
|
459
459
|
|
|
460
460
|
addParams: function (params) {
|
|
461
461
|
var newParams = this.params.slice();
|
|
462
|
-
var existingParamsIndex = this.params.findIndex(function (currentParams) {
|
|
463
|
-
return currentParams.$$id === params.$$id;
|
|
464
|
-
});
|
|
465
462
|
|
|
466
|
-
|
|
467
|
-
newParams.splice(existingParamsIndex, 1, params);
|
|
468
|
-
} else {
|
|
469
|
-
newParams.push(params);
|
|
470
|
-
}
|
|
463
|
+
newParams.push(params);
|
|
471
464
|
|
|
472
465
|
return new RecommendParameters({ params: newParams });
|
|
473
466
|
},
|
|
@@ -510,13 +503,17 @@ RecommendParameters.prototype = {
|
|
|
510
503
|
);
|
|
511
504
|
},
|
|
512
505
|
|
|
513
|
-
_buildQueries: function (indexName) {
|
|
514
|
-
return this.params
|
|
515
|
-
|
|
516
|
-
|
|
506
|
+
_buildQueries: function (indexName, cache) {
|
|
507
|
+
return this.params
|
|
508
|
+
.filter(function (params) {
|
|
509
|
+
return cache[params.$$id] === undefined;
|
|
510
|
+
})
|
|
511
|
+
.map(function (params) {
|
|
512
|
+
var query = Object.assign({}, params, { indexName: indexName });
|
|
513
|
+
delete query.$$id;
|
|
517
514
|
|
|
518
|
-
|
|
519
|
-
|
|
515
|
+
return query;
|
|
516
|
+
});
|
|
520
517
|
},
|
|
521
518
|
};
|
|
522
519
|
|
|
@@ -525,6 +522,36 @@ module.exports = RecommendParameters;
|
|
|
525
522
|
},{}],5:[function(require,module,exports){
|
|
526
523
|
'use strict';
|
|
527
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Constructor for SearchResults
|
|
527
|
+
* @class
|
|
528
|
+
* @classdesc SearchResults contains the results of a query to Algolia using the
|
|
529
|
+
* {@link AlgoliaSearchHelper}.
|
|
530
|
+
* @param {RecommendParameters} state state that led to the response
|
|
531
|
+
* @param {Record<string,RecommendResultItem>} results the results from algolia client
|
|
532
|
+
**/
|
|
533
|
+
function RecommendResults(state, results) {
|
|
534
|
+
this._state = state;
|
|
535
|
+
this._rawResults = results;
|
|
536
|
+
|
|
537
|
+
// eslint-disable-next-line consistent-this
|
|
538
|
+
var self = this;
|
|
539
|
+
|
|
540
|
+
state.params.forEach(function (param) {
|
|
541
|
+
var id = param.$$id;
|
|
542
|
+
self[id] = results[id];
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
RecommendResults.prototype = {
|
|
547
|
+
constructor: RecommendResults,
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
module.exports = RecommendResults;
|
|
551
|
+
|
|
552
|
+
},{}],6:[function(require,module,exports){
|
|
553
|
+
'use strict';
|
|
554
|
+
|
|
528
555
|
/**
|
|
529
556
|
* Functions to manipulate refinement lists
|
|
530
557
|
*
|
|
@@ -696,7 +723,7 @@ var lib = {
|
|
|
696
723
|
|
|
697
724
|
module.exports = lib;
|
|
698
725
|
|
|
699
|
-
},{"../functions/defaultsPure":
|
|
726
|
+
},{"../functions/defaultsPure":12,"../functions/objectHasKeys":21,"../functions/omit":22}],7:[function(require,module,exports){
|
|
700
727
|
'use strict';
|
|
701
728
|
|
|
702
729
|
var defaultsPure = require('../functions/defaultsPure');
|
|
@@ -2385,7 +2412,7 @@ SearchParameters.prototype = {
|
|
|
2385
2412
|
*/
|
|
2386
2413
|
module.exports = SearchParameters;
|
|
2387
2414
|
|
|
2388
|
-
},{"../functions/defaultsPure":
|
|
2415
|
+
},{"../functions/defaultsPure":12,"../functions/find":14,"../functions/intersection":19,"../functions/merge":20,"../functions/objectHasKeys":21,"../functions/omit":22,"../functions/valToNumber":24,"../utils/isValidUserToken":26,"./RefinementList":6}],8:[function(require,module,exports){
|
|
2389
2416
|
'use strict';
|
|
2390
2417
|
|
|
2391
2418
|
module.exports = generateTrees;
|
|
@@ -2589,7 +2616,7 @@ function format(
|
|
|
2589
2616
|
};
|
|
2590
2617
|
}
|
|
2591
2618
|
|
|
2592
|
-
},{"../functions/escapeFacetValue":
|
|
2619
|
+
},{"../functions/escapeFacetValue":13,"../functions/find":14,"../functions/formatSort":17,"../functions/orderBy":23}],9:[function(require,module,exports){
|
|
2593
2620
|
'use strict';
|
|
2594
2621
|
|
|
2595
2622
|
var compact = require('../functions/compact');
|
|
@@ -3749,7 +3776,7 @@ function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
|
|
|
3749
3776
|
|
|
3750
3777
|
module.exports = SearchResults;
|
|
3751
3778
|
|
|
3752
|
-
},{"../functions/compact":
|
|
3779
|
+
},{"../functions/compact":11,"../functions/defaultsPure":12,"../functions/escapeFacetValue":13,"../functions/find":14,"../functions/findIndex":15,"../functions/formatSort":17,"../functions/merge":20,"../functions/orderBy":23,"./generate-hierarchical-tree":8}],10:[function(require,module,exports){
|
|
3753
3780
|
'use strict';
|
|
3754
3781
|
|
|
3755
3782
|
var EventEmitter = require('@algolia/events');
|
|
@@ -3761,9 +3788,11 @@ var merge = require('./functions/merge');
|
|
|
3761
3788
|
var objectHasKeys = require('./functions/objectHasKeys');
|
|
3762
3789
|
var omit = require('./functions/omit');
|
|
3763
3790
|
var RecommendParameters = require('./RecommendParameters');
|
|
3791
|
+
var RecommendResults = require('./RecommendResults');
|
|
3764
3792
|
var requestBuilder = require('./requestBuilder');
|
|
3765
3793
|
var SearchParameters = require('./SearchParameters');
|
|
3766
3794
|
var SearchResults = require('./SearchResults');
|
|
3795
|
+
var sortAndMergeRecommendations = require('./utils/sortAndMergeRecommendations');
|
|
3767
3796
|
var version = require('./version');
|
|
3768
3797
|
|
|
3769
3798
|
/**
|
|
@@ -3892,6 +3921,7 @@ function AlgoliaSearchHelper(client, index, options, searchResultsOptions) {
|
|
|
3892
3921
|
this._currentNbQueries = 0;
|
|
3893
3922
|
this._currentNbRecommendQueries = 0;
|
|
3894
3923
|
this._searchResultsOptions = searchResultsOptions;
|
|
3924
|
+
this.recommendCache = {};
|
|
3895
3925
|
}
|
|
3896
3926
|
|
|
3897
3927
|
inherits(AlgoliaSearchHelper, EventEmitter);
|
|
@@ -4680,7 +4710,7 @@ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
|
|
|
4680
4710
|
/**
|
|
4681
4711
|
* Removes a "frequently bought together" recommendation query.
|
|
4682
4712
|
*
|
|
4683
|
-
* @param {
|
|
4713
|
+
* @param {number} id identifier of the recommendation widget
|
|
4684
4714
|
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
4685
4715
|
* @fires change
|
|
4686
4716
|
* @chainable
|
|
@@ -4696,7 +4726,7 @@ AlgoliaSearchHelper.prototype.removeFrequentlyBoughtTogether = function (id) {
|
|
|
4696
4726
|
/**
|
|
4697
4727
|
* Removes a "related products" recommendation query.
|
|
4698
4728
|
*
|
|
4699
|
-
* @param {
|
|
4729
|
+
* @param {number} id identifier of the recommendation widget
|
|
4700
4730
|
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
4701
4731
|
* @fires change
|
|
4702
4732
|
* @chainable
|
|
@@ -4712,7 +4742,7 @@ AlgoliaSearchHelper.prototype.removeRelatedProducts = function (id) {
|
|
|
4712
4742
|
/**
|
|
4713
4743
|
* Removes a "trending items" recommendation query.
|
|
4714
4744
|
*
|
|
4715
|
-
* @param {
|
|
4745
|
+
* @param {number} id identifier of the recommendation widget
|
|
4716
4746
|
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
4717
4747
|
* @fires change
|
|
4718
4748
|
* @chainable
|
|
@@ -4728,7 +4758,7 @@ AlgoliaSearchHelper.prototype.removeTrendingItems = function (id) {
|
|
|
4728
4758
|
/**
|
|
4729
4759
|
* Removes a "trending facets" recommendation query.
|
|
4730
4760
|
*
|
|
4731
|
-
* @param {
|
|
4761
|
+
* @param {number} id identifier of the recommendation widget
|
|
4732
4762
|
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
4733
4763
|
* @fires change
|
|
4734
4764
|
* @chainable
|
|
@@ -4744,7 +4774,7 @@ AlgoliaSearchHelper.prototype.removeTrendingFacets = function (id) {
|
|
|
4744
4774
|
/**
|
|
4745
4775
|
* Removes a "looking similar" recommendation query.
|
|
4746
4776
|
*
|
|
4747
|
-
* @param {
|
|
4777
|
+
* @param {number} id identifier of the recommendation widget
|
|
4748
4778
|
* @returns {AlgoliaSearchHelper} Method is chainable, it returns itself
|
|
4749
4779
|
* @fires change
|
|
4750
4780
|
* @chainable
|
|
@@ -5329,6 +5359,9 @@ AlgoliaSearchHelper.prototype._recommend = function () {
|
|
|
5329
5359
|
var recommendState = this.recommendState;
|
|
5330
5360
|
var index = this.getIndex();
|
|
5331
5361
|
var states = [{ state: recommendState, index: index, helper: this }];
|
|
5362
|
+
var ids = recommendState.params.map(function (param) {
|
|
5363
|
+
return param.$$id;
|
|
5364
|
+
});
|
|
5332
5365
|
|
|
5333
5366
|
this.emit('fetch', {
|
|
5334
5367
|
recommend: {
|
|
@@ -5337,6 +5370,8 @@ AlgoliaSearchHelper.prototype._recommend = function () {
|
|
|
5337
5370
|
},
|
|
5338
5371
|
});
|
|
5339
5372
|
|
|
5373
|
+
var cache = this.recommendCache;
|
|
5374
|
+
|
|
5340
5375
|
var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
|
|
5341
5376
|
var derivedIndex = derivedHelper.getModifiedState(searchState).index;
|
|
5342
5377
|
if (!derivedIndex) {
|
|
@@ -5355,6 +5390,13 @@ AlgoliaSearchHelper.prototype._recommend = function () {
|
|
|
5355
5390
|
helper: derivedHelper,
|
|
5356
5391
|
});
|
|
5357
5392
|
|
|
5393
|
+
ids = Array.prototype.concat.apply(
|
|
5394
|
+
ids,
|
|
5395
|
+
derivedState.params.map(function (param) {
|
|
5396
|
+
return param.$$id;
|
|
5397
|
+
})
|
|
5398
|
+
);
|
|
5399
|
+
|
|
5358
5400
|
derivedHelper.emit('fetch', {
|
|
5359
5401
|
recommend: {
|
|
5360
5402
|
state: derivedState,
|
|
@@ -5362,11 +5404,11 @@ AlgoliaSearchHelper.prototype._recommend = function () {
|
|
|
5362
5404
|
},
|
|
5363
5405
|
});
|
|
5364
5406
|
|
|
5365
|
-
return derivedState._buildQueries(derivedIndex);
|
|
5407
|
+
return derivedState._buildQueries(derivedIndex, cache);
|
|
5366
5408
|
});
|
|
5367
5409
|
|
|
5368
5410
|
var queries = Array.prototype.concat.apply(
|
|
5369
|
-
this.recommendState._buildQueries(index),
|
|
5411
|
+
this.recommendState._buildQueries(index, cache),
|
|
5370
5412
|
derivedQueries
|
|
5371
5413
|
);
|
|
5372
5414
|
|
|
@@ -5380,7 +5422,7 @@ AlgoliaSearchHelper.prototype._recommend = function () {
|
|
|
5380
5422
|
) {
|
|
5381
5423
|
// eslint-disable-next-line no-console
|
|
5382
5424
|
console.warn(
|
|
5383
|
-
'Please update algoliasearch/lite to the latest version in order to use
|
|
5425
|
+
'Please update algoliasearch/lite to the latest version in order to use recommend widgets.'
|
|
5384
5426
|
);
|
|
5385
5427
|
return;
|
|
5386
5428
|
}
|
|
@@ -5391,7 +5433,7 @@ AlgoliaSearchHelper.prototype._recommend = function () {
|
|
|
5391
5433
|
try {
|
|
5392
5434
|
this.client
|
|
5393
5435
|
.getRecommendations(queries)
|
|
5394
|
-
.then(this._dispatchRecommendResponse.bind(this, queryId, states))
|
|
5436
|
+
.then(this._dispatchRecommendResponse.bind(this, queryId, states, ids))
|
|
5395
5437
|
.catch(this._dispatchRecommendError.bind(this, queryId));
|
|
5396
5438
|
} catch (error) {
|
|
5397
5439
|
// If we reach this part, we're in an internal error state
|
|
@@ -5465,6 +5507,7 @@ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
|
|
|
5465
5507
|
AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
|
|
5466
5508
|
queryId,
|
|
5467
5509
|
states,
|
|
5510
|
+
ids,
|
|
5468
5511
|
content
|
|
5469
5512
|
) {
|
|
5470
5513
|
// @TODO remove the number of outdated queries discarded instead of just one
|
|
@@ -5480,7 +5523,39 @@ AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
|
|
|
5480
5523
|
|
|
5481
5524
|
if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty');
|
|
5482
5525
|
|
|
5483
|
-
var
|
|
5526
|
+
var cache = this.recommendCache;
|
|
5527
|
+
|
|
5528
|
+
var idsMap = {};
|
|
5529
|
+
ids
|
|
5530
|
+
.filter(function (id) {
|
|
5531
|
+
return cache[id] === undefined;
|
|
5532
|
+
})
|
|
5533
|
+
.forEach(function (id, index) {
|
|
5534
|
+
if (!idsMap[id]) idsMap[id] = [];
|
|
5535
|
+
|
|
5536
|
+
idsMap[id].push(index);
|
|
5537
|
+
});
|
|
5538
|
+
|
|
5539
|
+
Object.keys(idsMap).forEach(function (id) {
|
|
5540
|
+
var indices = idsMap[id];
|
|
5541
|
+
var firstResult = content.results[indices[0]];
|
|
5542
|
+
if (indices.length === 1) {
|
|
5543
|
+
cache[id] = firstResult;
|
|
5544
|
+
return;
|
|
5545
|
+
}
|
|
5546
|
+
cache[id] = Object.assign({}, firstResult, {
|
|
5547
|
+
hits: sortAndMergeRecommendations(
|
|
5548
|
+
indices.map(function (idx) {
|
|
5549
|
+
return content.results[idx].hits;
|
|
5550
|
+
})
|
|
5551
|
+
),
|
|
5552
|
+
});
|
|
5553
|
+
});
|
|
5554
|
+
|
|
5555
|
+
var results = {};
|
|
5556
|
+
ids.forEach(function (id) {
|
|
5557
|
+
results[id] = cache[id];
|
|
5558
|
+
});
|
|
5484
5559
|
|
|
5485
5560
|
states.forEach(function (s) {
|
|
5486
5561
|
var state = s.state;
|
|
@@ -5496,7 +5571,7 @@ AlgoliaSearchHelper.prototype._dispatchRecommendResponse = function (
|
|
|
5496
5571
|
return;
|
|
5497
5572
|
}
|
|
5498
5573
|
|
|
5499
|
-
helper.lastRecommendResults = results;
|
|
5574
|
+
helper.lastRecommendResults = new RecommendResults(state, results);
|
|
5500
5575
|
|
|
5501
5576
|
// eslint-disable-next-line no-warning-comments
|
|
5502
5577
|
// TODO: emit "result" event when events for Recommend are implemented
|
|
@@ -5711,7 +5786,7 @@ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
|
|
|
5711
5786
|
|
|
5712
5787
|
module.exports = AlgoliaSearchHelper;
|
|
5713
5788
|
|
|
5714
|
-
},{"./DerivedHelper":3,"./RecommendParameters":4,"./SearchParameters":
|
|
5789
|
+
},{"./DerivedHelper":3,"./RecommendParameters":4,"./RecommendResults":5,"./SearchParameters":7,"./SearchResults":9,"./functions/escapeFacetValue":13,"./functions/inherits":18,"./functions/merge":20,"./functions/objectHasKeys":21,"./functions/omit":22,"./requestBuilder":25,"./utils/sortAndMergeRecommendations":27,"./version":28,"@algolia/events":1}],11:[function(require,module,exports){
|
|
5715
5790
|
'use strict';
|
|
5716
5791
|
|
|
5717
5792
|
module.exports = function compact(array) {
|
|
@@ -5722,7 +5797,7 @@ module.exports = function compact(array) {
|
|
|
5722
5797
|
return array.filter(Boolean);
|
|
5723
5798
|
};
|
|
5724
5799
|
|
|
5725
|
-
},{}],
|
|
5800
|
+
},{}],12:[function(require,module,exports){
|
|
5726
5801
|
'use strict';
|
|
5727
5802
|
|
|
5728
5803
|
// NOTE: this behaves like lodash/defaults, but doesn't mutate the target
|
|
@@ -5745,7 +5820,7 @@ module.exports = function defaultsPure() {
|
|
|
5745
5820
|
}, {});
|
|
5746
5821
|
};
|
|
5747
5822
|
|
|
5748
|
-
},{}],
|
|
5823
|
+
},{}],13:[function(require,module,exports){
|
|
5749
5824
|
'use strict';
|
|
5750
5825
|
|
|
5751
5826
|
/**
|
|
@@ -5777,7 +5852,7 @@ module.exports = {
|
|
|
5777
5852
|
unescapeFacetValue: unescapeFacetValue,
|
|
5778
5853
|
};
|
|
5779
5854
|
|
|
5780
|
-
},{}],
|
|
5855
|
+
},{}],14:[function(require,module,exports){
|
|
5781
5856
|
'use strict';
|
|
5782
5857
|
|
|
5783
5858
|
// @MAJOR can be replaced by native Array#find when we change support
|
|
@@ -5795,7 +5870,7 @@ module.exports = function find(array, comparator) {
|
|
|
5795
5870
|
return undefined;
|
|
5796
5871
|
};
|
|
5797
5872
|
|
|
5798
|
-
},{}],
|
|
5873
|
+
},{}],15:[function(require,module,exports){
|
|
5799
5874
|
'use strict';
|
|
5800
5875
|
|
|
5801
5876
|
// @MAJOR can be replaced by native Array#findIndex when we change support
|
|
@@ -5812,7 +5887,15 @@ module.exports = function find(array, comparator) {
|
|
|
5812
5887
|
return -1;
|
|
5813
5888
|
};
|
|
5814
5889
|
|
|
5815
|
-
},{}],
|
|
5890
|
+
},{}],16:[function(require,module,exports){
|
|
5891
|
+
// @MAJOR: remove this function and use Array.prototype.flat
|
|
5892
|
+
module.exports = function flat(arr) {
|
|
5893
|
+
return arr.reduce(function (acc, val) {
|
|
5894
|
+
return acc.concat(val);
|
|
5895
|
+
}, []);
|
|
5896
|
+
};
|
|
5897
|
+
|
|
5898
|
+
},{}],17:[function(require,module,exports){
|
|
5816
5899
|
'use strict';
|
|
5817
5900
|
|
|
5818
5901
|
var find = require('./find');
|
|
@@ -5853,7 +5936,7 @@ module.exports = function formatSort(sortBy, defaults) {
|
|
|
5853
5936
|
);
|
|
5854
5937
|
};
|
|
5855
5938
|
|
|
5856
|
-
},{"./find":
|
|
5939
|
+
},{"./find":14}],18:[function(require,module,exports){
|
|
5857
5940
|
'use strict';
|
|
5858
5941
|
|
|
5859
5942
|
function inherits(ctor, superCtor) {
|
|
@@ -5869,7 +5952,7 @@ function inherits(ctor, superCtor) {
|
|
|
5869
5952
|
|
|
5870
5953
|
module.exports = inherits;
|
|
5871
5954
|
|
|
5872
|
-
},{}],
|
|
5955
|
+
},{}],19:[function(require,module,exports){
|
|
5873
5956
|
'use strict';
|
|
5874
5957
|
|
|
5875
5958
|
function intersection(arr1, arr2) {
|
|
@@ -5883,7 +5966,7 @@ function intersection(arr1, arr2) {
|
|
|
5883
5966
|
|
|
5884
5967
|
module.exports = intersection;
|
|
5885
5968
|
|
|
5886
|
-
},{}],
|
|
5969
|
+
},{}],20:[function(require,module,exports){
|
|
5887
5970
|
'use strict';
|
|
5888
5971
|
|
|
5889
5972
|
function clone(value) {
|
|
@@ -5969,7 +6052,7 @@ function merge(target) {
|
|
|
5969
6052
|
|
|
5970
6053
|
module.exports = merge;
|
|
5971
6054
|
|
|
5972
|
-
},{}],
|
|
6055
|
+
},{}],21:[function(require,module,exports){
|
|
5973
6056
|
'use strict';
|
|
5974
6057
|
|
|
5975
6058
|
function objectHasKeys(obj) {
|
|
@@ -5978,7 +6061,7 @@ function objectHasKeys(obj) {
|
|
|
5978
6061
|
|
|
5979
6062
|
module.exports = objectHasKeys;
|
|
5980
6063
|
|
|
5981
|
-
},{}],
|
|
6064
|
+
},{}],22:[function(require,module,exports){
|
|
5982
6065
|
'use strict';
|
|
5983
6066
|
|
|
5984
6067
|
// https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
|
|
@@ -5999,7 +6082,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
5999
6082
|
|
|
6000
6083
|
module.exports = _objectWithoutPropertiesLoose;
|
|
6001
6084
|
|
|
6002
|
-
},{}],
|
|
6085
|
+
},{}],23:[function(require,module,exports){
|
|
6003
6086
|
'use strict';
|
|
6004
6087
|
|
|
6005
6088
|
function compareAscending(value, other) {
|
|
@@ -6081,7 +6164,7 @@ function orderBy(collection, iteratees, orders) {
|
|
|
6081
6164
|
|
|
6082
6165
|
module.exports = orderBy;
|
|
6083
6166
|
|
|
6084
|
-
},{}],
|
|
6167
|
+
},{}],24:[function(require,module,exports){
|
|
6085
6168
|
'use strict';
|
|
6086
6169
|
|
|
6087
6170
|
function valToNumber(v) {
|
|
@@ -6100,7 +6183,7 @@ function valToNumber(v) {
|
|
|
6100
6183
|
|
|
6101
6184
|
module.exports = valToNumber;
|
|
6102
6185
|
|
|
6103
|
-
},{}],
|
|
6186
|
+
},{}],25:[function(require,module,exports){
|
|
6104
6187
|
'use strict';
|
|
6105
6188
|
|
|
6106
6189
|
var merge = require('./functions/merge');
|
|
@@ -6550,7 +6633,7 @@ var requestBuilder = {
|
|
|
6550
6633
|
|
|
6551
6634
|
module.exports = requestBuilder;
|
|
6552
6635
|
|
|
6553
|
-
},{"./functions/merge":
|
|
6636
|
+
},{"./functions/merge":20}],26:[function(require,module,exports){
|
|
6554
6637
|
'use strict';
|
|
6555
6638
|
|
|
6556
6639
|
module.exports = function isValidUserToken(userToken) {
|
|
@@ -6560,10 +6643,68 @@ module.exports = function isValidUserToken(userToken) {
|
|
|
6560
6643
|
return /^[a-zA-Z0-9_-]{1,64}$/.test(userToken);
|
|
6561
6644
|
};
|
|
6562
6645
|
|
|
6563
|
-
},{}],
|
|
6646
|
+
},{}],27:[function(require,module,exports){
|
|
6647
|
+
'use strict';
|
|
6648
|
+
|
|
6649
|
+
var find = require('../functions/find');
|
|
6650
|
+
var flat = require('../functions/flat');
|
|
6651
|
+
|
|
6652
|
+
function getAverageIndices(indexTracker, nrOfObjs) {
|
|
6653
|
+
var avgIndices = [];
|
|
6654
|
+
|
|
6655
|
+
Object.keys(indexTracker).forEach(function (key) {
|
|
6656
|
+
if (indexTracker[key].count < 2) {
|
|
6657
|
+
indexTracker[key].indexSum += 100;
|
|
6658
|
+
}
|
|
6659
|
+
avgIndices.push({
|
|
6660
|
+
objectID: key,
|
|
6661
|
+
avgOfIndices: indexTracker[key].indexSum / nrOfObjs,
|
|
6662
|
+
});
|
|
6663
|
+
});
|
|
6664
|
+
|
|
6665
|
+
return avgIndices.sort(function (a, b) {
|
|
6666
|
+
return a.avgOfIndices > b.avgOfIndices ? 1 : -1;
|
|
6667
|
+
});
|
|
6668
|
+
}
|
|
6669
|
+
|
|
6670
|
+
function sortAndMergeRecommendations(results) {
|
|
6671
|
+
var indexTracker = {};
|
|
6672
|
+
|
|
6673
|
+
results.forEach(function (hits) {
|
|
6674
|
+
hits.forEach(function (hit, index) {
|
|
6675
|
+
if (!indexTracker[hit.objectID]) {
|
|
6676
|
+
indexTracker[hit.objectID] = { indexSum: index, count: 1 };
|
|
6677
|
+
} else {
|
|
6678
|
+
indexTracker[hit.objectID] = {
|
|
6679
|
+
indexSum: indexTracker[hit.objectID].indexSum + index,
|
|
6680
|
+
count: indexTracker[hit.objectID].count + 1,
|
|
6681
|
+
};
|
|
6682
|
+
}
|
|
6683
|
+
});
|
|
6684
|
+
});
|
|
6685
|
+
|
|
6686
|
+
var sortedAverageIndices = getAverageIndices(indexTracker, results.length);
|
|
6687
|
+
|
|
6688
|
+
var finalOrder = sortedAverageIndices.reduce(function (
|
|
6689
|
+
orderedHits,
|
|
6690
|
+
avgIndexRef
|
|
6691
|
+
) {
|
|
6692
|
+
var result = find(flat(results), function (hit) {
|
|
6693
|
+
return hit.objectID === avgIndexRef.objectID;
|
|
6694
|
+
});
|
|
6695
|
+
return result ? orderedHits.concat(result) : orderedHits;
|
|
6696
|
+
},
|
|
6697
|
+
[]);
|
|
6698
|
+
|
|
6699
|
+
return finalOrder;
|
|
6700
|
+
}
|
|
6701
|
+
|
|
6702
|
+
module.exports = sortAndMergeRecommendations;
|
|
6703
|
+
|
|
6704
|
+
},{"../functions/find":14,"../functions/flat":16}],28:[function(require,module,exports){
|
|
6564
6705
|
'use strict';
|
|
6565
6706
|
|
|
6566
|
-
module.exports = '3.
|
|
6707
|
+
module.exports = '3.20.0';
|
|
6567
6708
|
|
|
6568
6709
|
},{}]},{},[2])(2)
|
|
6569
6710
|
});
|