diff --git a/package.json b/package.json index 1ccada5d..b5855349 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "embla-carousel-autoplay": "^8.5.2", "embla-carousel-svelte": "^8.5.2", "flexsearch": "^0.8.147", - "fuse.js": "^7.1.0", "idb": "^8.0.2", "localforage": "^1.10.0", "lodash": "^4.17.21", diff --git a/src/interface/components/store/Backgrounds.svelte b/src/interface/components/store/Backgrounds.svelte index 307af84a..a6bcc6eb 100644 --- a/src/interface/components/store/Backgrounds.svelte +++ b/src/interface/components/store/Backgrounds.svelte @@ -2,7 +2,7 @@ import { hasEnoughStorageSpace, isIndexedDBSupported, writeData, openDatabase, readAllData, deleteData } from '@/interface/hooks/BackgroundDataLoader'; import Spinner from '../Spinner.svelte'; import { settingsState } from '@/seqta/utils/listeners/SettingsState' - import Fuse from 'fuse.js'; + import { Index } from 'flexsearch'; import { backgroundUpdates } from '@/interface/hooks/BackgroundUpdates' import { ThemeManager } from '@/plugins/built-in/themes/theme-manager' @@ -20,19 +20,12 @@ let savedBackgrounds = $state([]); let installingBackgrounds = $state>(new Set()); let debugInfo = $state(''); + let searchIndex = $state(null); // New state variables let activeTab = $state<'all' | 'installed' | 'photos' | 'videos'>('all'); let sortBy = $state<'newest' | 'popular' | 'name'>('newest'); - // Add Fuse.js options - const fuseOptions = { - keys: ['name', 'description'], - threshold: 0.4, - ignoreLocation: true - }; - let fuse: Fuse; - // Existing functions const loadStore = async () => { try { @@ -43,7 +36,19 @@ } const data = await response.json(); backgrounds = data.backgrounds; - fuse = new Fuse(backgrounds, fuseOptions); + + // Initialize FlexSearch index + const index = new Index({ + tokenize: "forward", + preset: "score" + }); + + // Add backgrounds to the index + backgrounds.forEach((bg, i) => { + index.add(i, bg.name + " " + bg.description); + }); + + searchIndex = index; debugInfo = `Loaded ${backgrounds.length} backgrounds`; await loadSavedBackgrounds(); } catch (e) { @@ -74,14 +79,10 @@ let filteredBackgrounds = $derived((() => { let filtered = backgrounds; - // Use Fuse.js search if there's a search term - if (searchTerm.trim()) { - // @ts-ignore - if (fuse) { - filtered = fuse.search(searchTerm).map((result: any) => result.item) ?? []; - } else { - filtered = backgrounds.filter(bg => bg.name.toLowerCase().includes(searchTerm.toLowerCase())); - } + // Use FlexSearch if there's a search term + if (searchTerm.trim() && searchIndex) { + const results = searchIndex.search(searchTerm) as number[]; + filtered = results.map(i => backgrounds[i]); } // Apply category filtering diff --git a/src/plugins/built-in/globalSearch/SearchBar.svelte b/src/plugins/built-in/globalSearch/SearchBar.svelte index 9346b4b5..e84250cc 100644 --- a/src/plugins/built-in/globalSearch/SearchBar.svelte +++ b/src/plugins/built-in/globalSearch/SearchBar.svelte @@ -1,6 +1,6 @@