feat: improving search
This commit is contained in:
@ -37,20 +37,27 @@ export const Search = () => {
|
|||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
console.log("DBG: ", images());
|
console.log("DBG: ", images());
|
||||||
setSearchResults(images() ?? []);
|
setSearchResults(images() ?? []);
|
||||||
|
console.log(images());
|
||||||
|
|
||||||
fuze = new Fuse<UserImage>(images() ?? [], {
|
fuze = new Fuse<UserImage>(images() ?? [], {
|
||||||
keys: [
|
keys: [
|
||||||
{ name: "data.Name", weight: 2 },
|
{ name: "data.Name", weight: 2 },
|
||||||
{ name: "rawData", weight: 1 },
|
{ name: "rawData", weight: 1 },
|
||||||
],
|
],
|
||||||
threshold: 0.4,
|
threshold: 0.6,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const onInputChange = (event: InputEvent) => {
|
const onInputChange = (event: InputEvent) => {
|
||||||
const query = (event.target as HTMLInputElement).value;
|
const query = (event.target as HTMLInputElement).value;
|
||||||
|
console.log(query);
|
||||||
|
|
||||||
|
if (query.length === 0) {
|
||||||
|
setSearchResults(images() ?? []);
|
||||||
|
} else {
|
||||||
setSearchQuery(query);
|
setSearchQuery(query);
|
||||||
setSearchResults(fuze.search(query).map((s) => s.item));
|
setSearchResults(fuze.search(query).map((s) => s.item));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let searchInputRef: HTMLInputElement | undefined;
|
let searchInputRef: HTMLInputElement | undefined;
|
||||||
|
@ -20,7 +20,11 @@ type SearchImageStore = {
|
|||||||
// How wonderfully functional
|
// How wonderfully functional
|
||||||
const getAllValues = (object: object): Array<string> => {
|
const getAllValues = (object: object): Array<string> => {
|
||||||
const loop = (acc: Array<string>, next: 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;
|
const value: unknown = _value;
|
||||||
switch (typeof value) {
|
switch (typeof value) {
|
||||||
case "object":
|
case "object":
|
||||||
|
Reference in New Issue
Block a user