Skip to content

Commit f783575

Browse files
authored
chore: fuse cleanup (#329)
1 parent 35e09cc commit f783575

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/useMatches.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ export const NO_GROUP = {
99
priority: Priority.NORMAL,
1010
};
1111

12+
const fuseOptions: Fuse.IFuseOptions<ActionImpl> = {
13+
keys: [
14+
{
15+
name: "name",
16+
weight: 0.5,
17+
},
18+
{
19+
name: "keywords",
20+
getFn: (item) => (item.keywords ?? "").split(","),
21+
weight: 0.5,
22+
},
23+
"subtitle",
24+
],
25+
includeScore: true,
26+
includeMatches: true,
27+
threshold: 0.2,
28+
minMatchCharLength: 1,
29+
};
30+
1231
function order(a, b) {
1332
/**
1433
* Larger the priority = higher up the list
@@ -74,29 +93,7 @@ export function useMatches() {
7493
return getDeepResults(rootResults);
7594
}, [getDeepResults, rootResults, emptySearch]);
7695

77-
const fuseOptions = {
78-
keys: [
79-
{
80-
name: "name",
81-
weight: 0.5,
82-
},
83-
{
84-
name: "keywords",
85-
getFn: (item) => item.keywords.split(","), // make keyword an array. so fuse can look through words individually
86-
weight: 0.5,
87-
},
88-
"subtitle",
89-
],
90-
includeScore: true,
91-
includeMatches: true,
92-
threshold: 0.2,
93-
minMatchCharLength: 1,
94-
tokenize: (str) => {
95-
// Example: Preserve hyphens and special characters as separate tokens
96-
return str.split(/[\s\-,.!()]+/).filter(Boolean);
97-
},
98-
};
99-
const fuse = new Fuse(filtered, fuseOptions);
96+
const fuse = React.useMemo(() => new Fuse(filtered, fuseOptions), [filtered]);
10097

10198
const matches = useInternalMatches(filtered, search, fuse);
10299

0 commit comments

Comments
 (0)