feat: improving search
This commit is contained in:
@ -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;
|
||||
|
@ -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":
|
||||
|
Reference in New Issue
Block a user