mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
Implement fuzzy page search using fuse.js (#86)
This commit is contained in:
@@ -5,6 +5,7 @@ import formatSeconds from "./useFormatSeconds";
|
||||
import useDebouncedRef from "./useDebouncedRef";
|
||||
import createSubPaths from "./useCreateSubPaths";
|
||||
import { readLocalStorage, writeLocalStorage } from "./useLocalStorage";
|
||||
import useFuse from "./useFuse";
|
||||
|
||||
export {
|
||||
readLocalStorage,
|
||||
@@ -15,4 +16,5 @@ export {
|
||||
useVisibility,
|
||||
formatSeconds,
|
||||
putCommas,
|
||||
useFuse,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useFuse } from "@vueuse/integrations/useFuse";
|
||||
import { Ref } from "vue";
|
||||
|
||||
/**
|
||||
* Fuzzy search using Fuse.js
|
||||
* @param query The query to search for
|
||||
* @param data The list to search in
|
||||
* @param fuseOptions Fuse.js options
|
||||
* @returns A ref containing the search results
|
||||
*/
|
||||
export default (query: string, data: any[], fuseOptions: object) => {
|
||||
const { results } = useFuse(query, data, {
|
||||
matchAllWhenSearchEmpty: true,
|
||||
fuseOptions: { ...fuseOptions, threshold: 0.3, ignoreLocation: true },
|
||||
});
|
||||
|
||||
return results;
|
||||
};
|
||||
Reference in New Issue
Block a user