feat: improving search

This commit is contained in:
2025-05-04 09:56:41 +01:00
parent 6952aa16da
commit b57a703812
2 changed files with 15 additions and 4 deletions

View File

@ -37,20 +37,27 @@ export const Search = () => {
createEffect(() => {
console.log("DBG: ", images());
setSearchResults(images() ?? []);
console.log(images());
fuze = new Fuse<UserImage>(images() ?? [], {
keys: [
{ name: "data.Name", weight: 2 },
{ name: "rawData", weight: 1 },
],
threshold: 0.4,
threshold: 0.6,
});
});
const onInputChange = (event: InputEvent) => {
const query = (event.target as HTMLInputElement).value;
setSearchQuery(query);
setSearchResults(fuze.search(query).map((s) => s.item));
console.log(query);
if (query.length === 0) {
setSearchResults(images() ?? []);
} else {
setSearchQuery(query);
setSearchResults(fuze.search(query).map((s) => s.item));
}
};
let searchInputRef: HTMLInputElement | undefined;

View File

@ -20,7 +20,11 @@ type SearchImageStore = {
// How wonderfully functional
const getAllValues = (object: object): Array<string> => {
const loop = (acc: Array<string>, next: object): Array<string> => {
for (const _value of Object.values(next)) {
for (const [key, _value] of Object.entries(next)) {
if (key === "ID") {
continue;
}
const value: unknown = _value;
switch (typeof value) {
case "object":