Skip to content

Commit

Permalink
chore: fuse cleanup (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
timc1 authored Aug 16, 2023
1 parent 35e09cc commit f783575
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

1 comment on commit f783575

@vercel
Copy link

@vercel vercel bot commented on f783575 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kbar – ./

kbar.vercel.app
kbar-git-main-timc.vercel.app
kbar-timc.vercel.app

Please sign in to comment.