-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06e33f4
commit 7291693
Showing
18 changed files
with
469 additions
and
393 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import FuzzySearch from "@leeoniya/ufuzzy"; | ||
|
||
const uf = new FuzzySearch(); | ||
const infoThresh = 1e3; | ||
|
||
export function search(haystack: string[], needle: string) { | ||
const idxs = uf.filter(haystack, needle); | ||
|
||
if (idxs !== null && idxs.length > 0) { | ||
// sort/rank only when <= infoThresh | ||
if (idxs.length <= infoThresh) { | ||
const info = uf.info(idxs, haystack, needle); | ||
const order = uf.sort(info, haystack, needle); | ||
return order.map((_o, i) => haystack[info.idx[order[i]]]); | ||
} else { | ||
return idxs.map((_o, i) => haystack[idxs[i]]); | ||
} | ||
} | ||
|
||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.