Skip to content

Commit

Permalink
replace relevancy with fuse.js for command search
Browse files Browse the repository at this point in the history
  • Loading branch information
LoV432 committed Feb 16, 2024
1 parent b0aa7de commit 444ba9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions app/components/Suggestions.server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use client';
import { allCommands } from '../lib/all-commands';
//@ts-ignore
import relevancy from 'relevancy';
import Fuse from 'fuse.js';

const fuseSearch = new Fuse(allCommands, {
threshold: 0.05
});

export default function Suggestions({
suggestionText,
Expand Down Expand Up @@ -78,25 +81,23 @@ export default function Suggestions({
});
}
}
const filterdCommands = fuseSearch.search(suggestionText);

let filterdCommands = allCommands.filter((s) => s.includes(suggestionText));
filterdCommands = relevancy.sort(filterdCommands, suggestionText);

return filterdCommands.slice(0, 10).map((command) => {
return filterdCommands.slice(0, 15).map((command) => {
return (
<button
key={command}
onClick={() => autoFill(command)}
key={command.item}
onClick={() => autoFill(command.item)}
onKeyUp={(e) => {
if (e.key === 'Enter') {
autoFill(command);
autoFill(command.item);
}
}}
onKeyDown={moveFocus}
className="suggestions btn btn-active m-1 scroll-m-3 rounded border-zinc-700 border-opacity-60"
tabIndex={0}
>
{command}
{command.item}
</button>
);
});
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"dependencies": {
"@fabricio-191/valve-server-query": "^4.1.9",
"@maxmind/geoip2-node": "^5.0.0",
"fuse.js": "^7.0.0",
"jotai": "^2.6.4",
"jotai-location": "^0.5.2",
"mysql2": "^3.7.0",
"next": "14.0.3",
"patch-package": "^8.0.0",
"react": "^18",
"react-dom": "^18",
"relevancy": "0.2.0",
"toml": "^3.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 444ba9c

Please sign in to comment.