You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85-65Lines changed: 85 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,24 +3,30 @@
3
3
Fast fuzzy-search - the native replacement for `fuzzaldrin-plus`
4
4
5
5
# What is fuzzaldrin-plus-fast?
6
-
* Fuzzaldrin plus is an awesome library that provides fuzzy-search that is more targeted towards filenames.
7
-
* Fuzzaldrin-plus-fast is a rewrite of the library in native C++ to make it fast. The goal is to make it a few hundred millisecond filter times for a dataset with 1M entries. This performance is helpful in Atom's fuzzy finder to open files from large projects such as Chrome/Mozilla.
6
+
7
+
- Fuzzaldrin plus is an awesome library that provides fuzzy-search that is more targeted towards filenames.
8
+
- Fuzzaldrin-plus-fast is a rewrite of the library in native C++ to make it fast. The goal is to make it a few hundred millisecond filter times for a dataset with 1M entries. This performance is helpful in Atom's fuzzy finder to open files from large projects such as Chrome/Mozilla.
8
9
9
10
### Extra featuers
11
+
10
12
Fuzzaldrin-plus-fast:
13
+
11
14
- provides `filterTree` function which allows to fuzzy filter text in nested tree-like objects.
12
15
- allows setting the candidates only once using `ArrayFilterer` and `TreeFilterer` classes, and then, perform `filter` multiple times. This is much more efficient than calling the `filter` or `filterTree` functions directly every time.
13
16
14
17
# How performance is improved?
18
+
15
19
Fuzzaldrin-plus-fast achieves 10x-20x performance improvement over Fuzzaldrin plus for chromium project with 300K files. This high performance is achieved using the following techniques.
16
-
* Converting Javascript/CoffeeScript code to native C++ bindings provides 4x performance benefit.
17
-
* Use multiple threads to parallelize computation to achieve another 4x performance benefit. Currently, up to 8 threads are used if there are more than 10K candidates to filter.
18
-
* Some miscellaneous improvements provide additional benefit.
20
+
21
+
- Converting Javascript/CoffeeScript code to native C++ bindings provides 4x performance benefit.
22
+
- Use multiple threads to parallelize computation to achieve another 4x performance benefit. Currently, up to 8 threads are used if there are more than 10K candidates to filter.
23
+
- Some miscellaneous improvements provide additional benefit.
19
24
20
25
This project potentially solves the following Atom fuzzy-finder issues if used.
21
26
https://github.com/atom/fuzzy-finder/issues/271 and https://github.com/atom/fuzzy-finder/issues/88
22
27
23
28
# Is the API the same?
29
+
24
30
API is backward compatible with Fuzzaldrin and Fuzzaldrin-plus. Additional functions are provided to achieve better performance that could suit your needs
ArrayFilterer is a class that allows to set the `candidates` only once and perform filtering on them multiple times. This is much more efficient than calling the `filter` function directly.
83
+
74
84
```typescript
75
85
exportclassArrayFilterer<T> {
76
-
constructor()
77
-
78
-
/** The method to set the candidates that are going to be filtered
79
-
* @paramcandidates An array of tree objects.
80
-
* @paramdataKey (optional) if `candidates` is an array of objects, pass the key in the object which holds the data. dataKey can be the options object passed to `filter` method (but this is deprecated).
/** The method to set the candidates that are going to be filtered
89
+
* @paramcandidates An array of tree objects.
90
+
* @paramdataKey (optional) if `candidates` is an array of objects, pass the key in the object which holds the data. dataKey can be the options object passed to `filter` method (but this is deprecated).
@@ -107,59 +118,57 @@ Sort and filter the given Tree candidates by matching them against the given que
107
118
108
119
A **tree object** is an object in which each entry stores the data in its dataKey and it has (may have) some children (with a similar structure) in its childrenKey. See the following example.
109
120
110
-
*`candidates` An array of tree objects.
111
-
*`query` A string query to match each candidate against.
112
-
*`dataKey` the key of the object (and its children) which holds the data
113
-
*`childrenKey` the key of the object (and its children) which hold the children
114
-
*`options` options
115
-
*`returns` An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
121
+
-`candidates` An array of tree objects.
122
+
-`query` A string query to match each candidate against.
123
+
-`dataKey` the key of the object (and its children) which holds the data
124
+
-`childrenKey` the key of the object (and its children) which hold the children
125
+
-`options` options
126
+
-`returns` An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
**Performance Note**: use `TreeFilterer` class if you call the `filterTree` function multiple times on a certain set of candidates. `filterTree` internally uses this class, however, in each call it sets the candidates from scratch which can slow down the process.
138
145
139
146
### TreeFilterer class
147
+
140
148
`TreeFilterer` is a class that allows to set the `candidates` only once and perform filtering on them multiple times. This is much more efficient than calling the `filterTree` function directly.
141
149
142
150
```typescript
143
151
exportclassTreeFilterer<T> {
144
-
constructor()
145
-
146
-
/** The method to set the candidates that are going to be filtered
147
-
* @paramcandidates An array of tree objects.
148
-
* @paramdataKey the key of the object (and its children) which holds the data (defaults to `"data"`)
149
-
* @paramchildrenKey the key of the object (and its children) which hold the children (defaults to `"children"`)
/** The method to perform the filtering on the already set candidates
154
-
* @paramquery A string query to match each candidate against.
155
-
* @paramoptions options
156
-
* @return An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
/** The method to perform the filtering on the already set candidates
162
+
* @paramquery A string query to match each candidate against.
163
+
* @paramoptions options
164
+
* @return An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
Gives an array of indices at which the query matches the given string
206
+
196
207
```js
197
-
const { match } =require('fuzzaldrin-plus-fast')
208
+
const { match } =require("fuzzaldrin-plus-fast")
198
209
199
-
match('Hello World', 'he') // [0, 1]
200
-
match('Hello World', 'wor') // [6, 7, 8]
201
-
match('Hello World', 'elwor') // [1, 2, 6, 7, 8]
210
+
match("Hello World", "he")// [0, 1]
211
+
match("Hello World", "wor")// [6, 7, 8]
212
+
match("Hello World", "elwor") // [1, 2, 6, 7, 8]
202
213
```
203
214
204
215
### wrap (string, query, options = {})
216
+
205
217
Gives an HTML/Markdown string that highlights the range for which the match happens
218
+
206
219
```js
207
-
wrap("helloworld", "he")
220
+
wrap("helloworld", "he")
208
221
```
222
+
209
223
<strongclass="highlight">he</strong>lloworld
224
+
210
225
```js
211
226
wrap("Hello world", "he")
212
227
```
228
+
213
229
<strongclass="highlight">He</strong>llo world
214
230
215
231
### options
232
+
216
233
In all the above functions, you can pass an optional object with the following keys
234
+
217
235
```typescript
218
236
{
219
237
/** only for `filter` function */
@@ -237,11 +255,13 @@ In all the above functions, you can pass an optional object with the following k
237
255
```
238
256
239
257
# Info for Developers
258
+
240
259
## How to release the package to npm?
241
260
242
-
* Bump up version in package.json.
243
-
* Create a new release tag in Github, for the bumped version. This should trigger builds in GitHub Actions. The binaries will be uploaded to the action's page.
244
-
* Manually download the prebuilt binaries from GitHub and publish.
261
+
- Bump up version in package.json.
262
+
- Create a new release tag in Github, for the bumped version. This should trigger builds in GitHub Actions. The binaries will be uploaded to the action's page.
263
+
- Manually download the prebuilt binaries from GitHub and publish.
0 commit comments