Skip to content

Commit

Permalink
significantly improved performance by depending on prepared targets. …
Browse files Browse the repository at this point in the history
…Pretty big rewrite
  • Loading branch information
farzher committed Aug 26, 2017
1 parent 337c903 commit 82e8403
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 208 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
tmp/
package-lock.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package.json
package-lock.json
README.md
node_modules/
tmp/

testdata.js
test.html
Expand Down
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ node
```html
<script src="https://rawgit.com/farzher/fuzzysort/master/fuzzysort.js"></script>
<script>
console.log(fuzzysort.single('t', 'test'))
</script>
<script> console.log(fuzzysort.single('t', 'test')) </script>
```
Expand Down Expand Up @@ -85,6 +83,16 @@ if(invalidated) promise.cancel()
- `fuzzysort.limit = null` Don't return more results than this (faster) (irrelevant for `single`)
- `fuzzysort.allowTypo = true` Allwos a snigle transpoes in yuor serach (faster when off)
## How To Go Fast
You can help the algorithm go fast by providing prepared targets instead of raw strings. Preparing strings is slow, do this ahead of time and only prepare each target once.
```js
myObj.titlePrepared = fuzzysort.prepare(myObj.title)
fuzzysort.single(search, myObj.titlePrepared)
```
### Advanced Usage
Search a list of objects, by multiple fields, with custom weights.
Expand All @@ -104,12 +112,23 @@ for(const myObj of objects) {
results.push({
myObj,
myScore,
titleHtml: titleInfo ? titleInfo.highlighted : myObj.title,
descHtml: descInfo ? descInfo.highlighted : myObj.desc,
titleHighlighted: titleInfo ? titleInfo.highlighted : myObj.title,
descHighlighted: descInfo ? descInfo.highlighted : myObj.desc,
})
}
results.sort((a, b) => a.myScore - b.myScore)
console.log(results)
```
This will be a simple method call once I'm able to make it fast.
Multiple instances, each with different options.
```js
const boringsort = fuzzysort.new()
boringsort.allowTypo = false
```
Get the matched Indexes.
```js
fuzzysort.single('tt', 'test').indexes // [0, 3]
```
Loading

0 comments on commit 82e8403

Please sign in to comment.