frecency
Advanced tools
Comparing version 1.0.3 to 1.0.4
## Release History | ||
* 1.0.4 Improve readme and install instructions. | ||
* 1.0.3 Add license. | ||
@@ -4,0 +6,0 @@ |
{ | ||
"name": "frecency", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Frecency sorting for search results.", | ||
@@ -5,0 +5,0 @@ "browser": { |
@@ -7,10 +7,10 @@ # Frecency | ||
1) Install the npm module: | ||
Install the npm module: | ||
```sh | ||
npm install @mixmaxhq/frecency | ||
npm install frecency | ||
``` | ||
2) Import Frecency into your code and create a Frecency instance. | ||
Import Frecency into your code and create an instance of Frecency. | ||
```js | ||
import Frecency from '@mixmaxhq/frecency'; | ||
import Frecency from 'frecency'; | ||
@@ -22,3 +22,3 @@ export const peopleFrecency = new Frecency({ | ||
3) When you select a search result in your code, update frecency: | ||
When you select a search result in your code, update frecency: | ||
```js | ||
@@ -35,19 +35,22 @@ onSelect: (searchQuery, selectedResult) => { | ||
4) Before you display search results to your users, sort the result using frecency: | ||
Before you display search results to your users, sort the results using frecency: | ||
```js | ||
onSearch: (searchQuery) => { | ||
... | ||
// Search results received from a search API. | ||
const searchResults = [{ | ||
_id: '57b409d4feea972a68ba1101', | ||
name: 'Brad Vogel', | ||
email: 'brad@mixmax.com' | ||
}, { | ||
_id: '57a09ceb7abdf9cb2c35818c', | ||
name: 'Brad Neuberg', | ||
email: 'neuberg@gmail.com' | ||
}, { | ||
... | ||
}]; | ||
return peopleFrecency.sort({ | ||
searchQuery, | ||
results: [{ | ||
_id: '57b409d4feea972a68ba1101', | ||
name: 'Brad Vogel', | ||
email: 'brad@mixmax.com' | ||
}, { | ||
_id: '57a09ceb7abdf9cb2c35818c', | ||
name: 'Brad Neuberg', | ||
email: 'neuberg@gmail.com' | ||
}, { | ||
... | ||
}] | ||
results: searchResults | ||
}); | ||
@@ -58,3 +61,4 @@ } | ||
## Configuring Frecency | ||
Frecency will sort on `_id` by default. You can change this by setting an `idAttribute`: | ||
Frecency will sort on the `_id` attribute by default. You can change this by setting an | ||
`idAttribute` in the constructor: | ||
```js | ||
@@ -66,2 +70,4 @@ const frecency = new Frecency({ | ||
// OR | ||
const frecency = new Frecency({ | ||
@@ -78,3 +84,3 @@ key: 'people', | ||
// Also accepts a function if your search results contains a | ||
// `idAttribute` also accepts a function if your search results contain a | ||
// mix of different types. | ||
@@ -92,2 +98,4 @@ const frecency = new Frecency({ | ||
// OR | ||
frecency.save({ | ||
@@ -99,7 +107,7 @@ searchQuery, | ||
Frecency saves timestamps of your recent selections to calculate a score. | ||
More timestamps result in more granular frecency scores, but frecency data takes up more | ||
Frecency saves timestamps of your recent selections to calculate a score and rank you results. | ||
More timestamps means more granular frecency scores, but frecency data will take up more | ||
space in localStorage. | ||
You can modify this with an option in the constructor. | ||
You can modify the number of timestamps saved with an option in the constructor. | ||
```js | ||
@@ -106,0 +114,0 @@ new Frecency({ |
39018
122