diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ccc0239b..d6f10399f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Introduced fuzzy search for the quick links of the assistant - Improved the search results of the assistant to only display categories with content - Renamed `Account` to `account` in the `Order` database schema - Improved the language localization for German (`de`) diff --git a/libs/ui/src/lib/assistant/assistant.component.ts b/libs/ui/src/lib/assistant/assistant.component.ts index 22c75b91c..75e770ca7 100644 --- a/libs/ui/src/lib/assistant/assistant.component.ts +++ b/libs/ui/src/lib/assistant/assistant.component.ts @@ -41,6 +41,7 @@ import { MatSelectModule } from '@angular/material/select'; import { RouterModule } from '@angular/router'; import { Account, AssetClass, DataSource } from '@prisma/client'; import { differenceInYears } from 'date-fns'; +import Fuse from 'fuse.js'; import { isFunction } from 'lodash'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { EMPTY, Observable, Subject, merge, of } from 'rxjs'; @@ -642,20 +643,18 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { return acc; }, [] as IRoute[]); - return allRoutes - .filter(({ title }) => { - return title.toLowerCase().includes(searchTerm); - }) - .map(({ routerLink, title }) => { - return { - routerLink, - mode: SearchMode.QUICK_LINK as const, - name: title - }; - }) - .sort((a, b) => { - return a.name.localeCompare(b.name); - }); + const fuse = new Fuse(allRoutes, { + keys: ['title'], + threshold: 0.3 + }); + + return fuse.search(searchTerm).map(({ item: { routerLink, title } }) => { + return { + routerLink, + mode: SearchMode.QUICK_LINK as const, + name: title + }; + }); } private setFilterFormValues() { diff --git a/package-lock.json b/package-lock.json index f5c8ed8af..12ac3a8a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -66,6 +66,7 @@ "countup.js": "2.8.2", "date-fns": "4.1.0", "envalid": "8.0.0", + "fuse.js": "7.1.0", "google-spreadsheet": "3.2.0", "helmet": "7.0.0", "http-status-codes": "2.3.0", @@ -20615,6 +20616,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/fuse.js": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.1.0.tgz", + "integrity": "sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=10" + } + }, "node_modules/gaxios": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.3.3.tgz", diff --git a/package.json b/package.json index f3155dba3..0e72f1664 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "countup.js": "2.8.2", "date-fns": "4.1.0", "envalid": "8.0.0", + "fuse.js": "7.1.0", "google-spreadsheet": "3.2.0", "helmet": "7.0.0", "http-status-codes": "2.3.0",