diff --git a/app/components/Suggestions.server.tsx b/app/components/Suggestions.server.tsx index 6f1277e..9b962d4 100644 --- a/app/components/Suggestions.server.tsx +++ b/app/components/Suggestions.server.tsx @@ -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, @@ -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 ( ); }); diff --git a/package-lock.json b/package-lock.json index 0f2d237..c971d2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "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", @@ -18,7 +19,6 @@ "patch-package": "^8.0.0", "react": "^18", "react-dom": "^18", - "relevancy": "0.2.0", "toml": "^3.0.0" }, "devDependencies": { @@ -977,6 +977,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/fuse.js": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.0.0.tgz", + "integrity": "sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==", + "engines": { + "node": ">=10" + } + }, "node_modules/generate-function": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", @@ -2094,14 +2102,6 @@ "node": ">=8.10.0" } }, - "node_modules/relevancy": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/relevancy/-/relevancy-0.2.0.tgz", - "integrity": "sha512-82t+iJxDkkMQvGDmw9uttVedyXqyN2gQKXjHcMzG3HcKXomjYJD0lBLL/7fZ7O+CRmcjPPKPc4Ye8HuyZQWTEw==", - "engines": { - "node": "*" - } - }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", diff --git a/package.json b/package.json index 6fa7709..a8b936e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "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", @@ -19,7 +20,6 @@ "patch-package": "^8.0.0", "react": "^18", "react-dom": "^18", - "relevancy": "0.2.0", "toml": "^3.0.0" }, "devDependencies": {