Skip to content

Commit

Permalink
chore: fuse cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
timc1 committed Aug 16, 2023
1 parent 35e09cc commit 448e6f6
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/useMatches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ export const NO_GROUP = {
priority: Priority.NORMAL,
};

const fuseOptions: Fuse.IFuseOptions<ActionImpl> = {
keys: [
{
name: "name",
weight: 0.5,
},
{
name: "keywords",
getFn: (item) => (item.keywords ?? "").split(","),
weight: 0.5,
},
"subtitle",
],
includeScore: true,
includeMatches: true,
threshold: 0.2,
minMatchCharLength: 1,
};

function order(a, b) {
/**
* Larger the priority = higher up the list
Expand Down Expand Up @@ -74,29 +93,7 @@ export function useMatches() {
return getDeepResults(rootResults);
}, [getDeepResults, rootResults, emptySearch]);

const fuseOptions = {
keys: [
{
name: "name",
weight: 0.5,
},
{
name: "keywords",
getFn: (item) => item.keywords.split(","), // make keyword an array. so fuse can look through words individually
weight: 0.5,
},
"subtitle",
],
includeScore: true,
includeMatches: true,
threshold: 0.2,
minMatchCharLength: 1,
tokenize: (str) => {
// Example: Preserve hyphens and special characters as separate tokens
return str.split(/[\s\-,.!()]+/).filter(Boolean);
},
};
const fuse = new Fuse(filtered, fuseOptions);
const fuse = React.useMemo(() => new Fuse(filtered, fuseOptions), [filtered]);

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

Expand Down

0 comments on commit 448e6f6

Please sign in to comment.