Skip to content

Commit 82e8403

Browse files
committed
significantly improved performance by depending on prepared targets. Pretty big rewrite
1 parent 337c903 commit 82e8403

File tree

4 files changed

+151
-208
lines changed

4 files changed

+151
-208
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2+
tmp/
23
package-lock.json

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package.json
33
package-lock.json
44
README.md
55
node_modules/
6+
tmp/
67

78
testdata.js
89
test.html

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ node
3737
3838
```html
3939
<script src="https://rawgit.com/farzher/fuzzysort/master/fuzzysort.js"></script>
40-
<script>
41-
console.log(fuzzysort.single('t', 'test'))
42-
</script>
40+
<script> console.log(fuzzysort.single('t', 'test')) </script>
4341
```
4442
4543
@@ -85,6 +83,16 @@ if(invalidated) promise.cancel()
8583
- `fuzzysort.limit = null` Don't return more results than this (faster) (irrelevant for `single`)
8684
- `fuzzysort.allowTypo = true` Allwos a snigle transpoes in yuor serach (faster when off)
8785
86+
## How To Go Fast
87+
88+
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.
89+
90+
```js
91+
myObj.titlePrepared = fuzzysort.prepare(myObj.title)
92+
fuzzysort.single(search, myObj.titlePrepared)
93+
```
94+
95+
8896
### Advanced Usage
8997
9098
Search a list of objects, by multiple fields, with custom weights.
@@ -104,12 +112,23 @@ for(const myObj of objects) {
104112
results.push({
105113
myObj,
106114
myScore,
107-
titleHtml: titleInfo ? titleInfo.highlighted : myObj.title,
108-
descHtml: descInfo ? descInfo.highlighted : myObj.desc,
115+
titleHighlighted: titleInfo ? titleInfo.highlighted : myObj.title,
116+
descHighlighted: descInfo ? descInfo.highlighted : myObj.desc,
109117
})
110118
}
111119
results.sort((a, b) => a.myScore - b.myScore)
112120
console.log(results)
113121
```
114122
115-
This will be a simple method call once I'm able to make it fast.
123+
Multiple instances, each with different options.
124+
125+
```js
126+
const boringsort = fuzzysort.new()
127+
boringsort.allowTypo = false
128+
```
129+
130+
Get the matched Indexes.
131+
132+
```js
133+
fuzzysort.single('tt', 'test').indexes // [0, 3]
134+
```

0 commit comments

Comments
 (0)