Comparing version 1.2.0 to 1.3.0
## Release History | ||
* 1.3.0 make weights configurable #12 | ||
* 1.2.0 Add keepScores to SortParams [backward compatible] #10 | ||
@@ -4,0 +6,0 @@ |
@@ -140,5 +140,5 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
var Frecency = function () { | ||
// Attribute to use as the search result's id. | ||
// Max number of IDs that should be stored in frecency to limit the object size. | ||
// Max number of timestamps to save for recent selections of a result. | ||
// Used to create key that will be used to save frecency data in localStorage. | ||
function Frecency(_ref) { | ||
@@ -149,3 +149,6 @@ var key = _ref.key, | ||
idAttribute = _ref.idAttribute, | ||
storageProvider = _ref.storageProvider; | ||
storageProvider = _ref.storageProvider, | ||
exactQueryMatchWeight = _ref.exactQueryMatchWeight, | ||
subQueryMatchWeight = _ref.subQueryMatchWeight, | ||
recentSelectionsMatchWeight = _ref.recentSelectionsMatchWeight; | ||
classCallCheck(this, Frecency); | ||
@@ -161,2 +164,5 @@ | ||
this._localStorageEnabled = Boolean(this._storageProvider); | ||
this._exactQueryMatchWeight = exactQueryMatchWeight || 1.0; | ||
this._subQueryMatchWeight = subQueryMatchWeight || 0.7; | ||
this._recentSelectionsMatchWeight = recentSelectionsMatchWeight || 0.5; | ||
@@ -173,5 +179,5 @@ this._frecency = this._getFrecencyData(); | ||
// Max number of IDs that should be stored in frecency to limit the object size. | ||
// Attribute to use as the search result's id. | ||
// Used to create key that will be used to save frecency data in localStorage. | ||
// Max number of timestamps to save for recent selections of a result. | ||
@@ -466,3 +472,3 @@ | ||
if (_selection) { | ||
result._frecencyScore = _this._calculateScore(_selection.selectedAt, _selection.timesSelected, now); | ||
result._frecencyScore = _this._exactQueryMatchWeight * _this._calculateScore(_selection.selectedAt, _selection.timesSelected, now); | ||
return; | ||
@@ -492,3 +498,3 @@ } | ||
// Reduce the score because this is not an exact query match. | ||
result._frecencyScore = 0.7 * _this._calculateScore(_selection2.selectedAt, _selection2.timesSelected, now); | ||
result._frecencyScore = _this._subQueryMatchWeight * _this._calculateScore(_selection2.selectedAt, _selection2.timesSelected, now); | ||
return; | ||
@@ -517,3 +523,3 @@ } | ||
// Reduce the score because this is not an exact query match. | ||
result._frecencyScore = 0.5 * _this._calculateScore(selection.selectedAt, selection.timesSelected, now); | ||
result._frecencyScore = _this._recentSelectionsMatchWeight * _this._calculateScore(selection.selectedAt, selection.timesSelected, now); | ||
return; | ||
@@ -520,0 +526,0 @@ } |
@@ -131,5 +131,5 @@ 'use strict'; | ||
var Frecency = function () { | ||
// Attribute to use as the search result's id. | ||
// Max number of IDs that should be stored in frecency to limit the object size. | ||
// Max number of timestamps to save for recent selections of a result. | ||
// Used to create key that will be used to save frecency data in localStorage. | ||
function Frecency(_ref) { | ||
@@ -140,3 +140,6 @@ var key = _ref.key, | ||
idAttribute = _ref.idAttribute, | ||
storageProvider = _ref.storageProvider; | ||
storageProvider = _ref.storageProvider, | ||
exactQueryMatchWeight = _ref.exactQueryMatchWeight, | ||
subQueryMatchWeight = _ref.subQueryMatchWeight, | ||
recentSelectionsMatchWeight = _ref.recentSelectionsMatchWeight; | ||
classCallCheck(this, Frecency); | ||
@@ -152,2 +155,5 @@ | ||
this._localStorageEnabled = Boolean(this._storageProvider); | ||
this._exactQueryMatchWeight = exactQueryMatchWeight || 1.0; | ||
this._subQueryMatchWeight = subQueryMatchWeight || 0.7; | ||
this._recentSelectionsMatchWeight = recentSelectionsMatchWeight || 0.5; | ||
@@ -164,5 +170,5 @@ this._frecency = this._getFrecencyData(); | ||
// Max number of IDs that should be stored in frecency to limit the object size. | ||
// Attribute to use as the search result's id. | ||
// Used to create key that will be used to save frecency data in localStorage. | ||
// Max number of timestamps to save for recent selections of a result. | ||
@@ -457,3 +463,3 @@ | ||
if (_selection) { | ||
result._frecencyScore = _this._calculateScore(_selection.selectedAt, _selection.timesSelected, now); | ||
result._frecencyScore = _this._exactQueryMatchWeight * _this._calculateScore(_selection.selectedAt, _selection.timesSelected, now); | ||
return; | ||
@@ -483,3 +489,3 @@ } | ||
// Reduce the score because this is not an exact query match. | ||
result._frecencyScore = 0.7 * _this._calculateScore(_selection2.selectedAt, _selection2.timesSelected, now); | ||
result._frecencyScore = _this._subQueryMatchWeight * _this._calculateScore(_selection2.selectedAt, _selection2.timesSelected, now); | ||
return; | ||
@@ -508,3 +514,3 @@ } | ||
// Reduce the score because this is not an exact query match. | ||
result._frecencyScore = 0.5 * _this._calculateScore(selection.selectedAt, selection.timesSelected, now); | ||
result._frecencyScore = _this._recentSelectionsMatchWeight * _this._calculateScore(selection.selectedAt, selection.timesSelected, now); | ||
return; | ||
@@ -511,0 +517,0 @@ } |
{ | ||
"name": "frecency", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Frecency sorting for search results.", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -141,1 +141,14 @@ # Frecency | ||
``` | ||
### Configure weights | ||
Differents weights are applied depending on what kind of match it is about | ||
```js | ||
new Frecency({ | ||
key: 'people', | ||
exactQueryMatchWeight: 0.9, // default to 1.0 | ||
subQueryMatchWeight: 0.5, // default to 0.7 | ||
recentSelectionsMatchWeight: 0.1, // default to 0.5 | ||
}); | ||
``` |
@@ -22,3 +22,7 @@ // @flow | ||
constructor({ key, timestampsLimit, recentSelectionsLimit, idAttribute, storageProvider }: FrecencyOptions) { | ||
_exactQueryMatchWeight: number; | ||
_subQueryMatchWeight: number; | ||
_recentSelectionsMatchWeight: number; | ||
constructor({ key, timestampsLimit, recentSelectionsLimit, idAttribute, storageProvider, exactQueryMatchWeight, subQueryMatchWeight, recentSelectionsMatchWeight }: FrecencyOptions) { | ||
if (!key) throw new Error('key is required.'); | ||
@@ -32,2 +36,5 @@ | ||
this._localStorageEnabled = Boolean(this._storageProvider); | ||
this._exactQueryMatchWeight = exactQueryMatchWeight || 1.0; | ||
this._subQueryMatchWeight = subQueryMatchWeight || 0.7; | ||
this._recentSelectionsMatchWeight = recentSelectionsMatchWeight || 0.5; | ||
@@ -297,3 +304,3 @@ this._frecency = this._getFrecencyData(); | ||
if (selection) { | ||
result._frecencyScore = this._calculateScore(selection.selectedAt, | ||
result._frecencyScore = this._exactQueryMatchWeight * this._calculateScore(selection.selectedAt, | ||
selection.timesSelected, now); | ||
@@ -317,3 +324,3 @@ return; | ||
// Reduce the score because this is not an exact query match. | ||
result._frecencyScore = 0.7 * this._calculateScore(selection.selectedAt, | ||
result._frecencyScore = this._subQueryMatchWeight * this._calculateScore(selection.selectedAt, | ||
selection.timesSelected, now); | ||
@@ -328,3 +335,3 @@ return; | ||
// Reduce the score because this is not an exact query match. | ||
result._frecencyScore = 0.5 * this._calculateScore(selection.selectedAt, | ||
result._frecencyScore = this._recentSelectionsMatchWeight * this._calculateScore(selection.selectedAt, | ||
selection.timesSelected, now); | ||
@@ -331,0 +338,0 @@ return; |
@@ -60,3 +60,6 @@ // @flow | ||
idAttribute?: string | Function, | ||
storageProvider?: StorageProvider | ||
storageProvider?: StorageProvider, | ||
exactQueryMatchWeight?: number, | ||
subQueryMatchWeight?: number, | ||
recentSelectionsMatchWeight?: number, | ||
}; | ||
@@ -63,0 +66,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61819
1324
154