From fa71f68de5f861f91c31be6560d7352e8d19eb17 Mon Sep 17 00:00:00 2001 From: John Costa Date: Thu, 24 Jul 2025 14:31:08 +0100 Subject: [PATCH] wip: search feature for image descriptions The search only works for entities currently, but we need to make it useful for images too. This also goes back to entity vs image question. I don't think people find the entities super useful actually? But I know they could be. I need to find a way for them to properly co-exist --- frontend/src/network/index.ts | 21 +++++++++------------ frontend/src/pages/search/search.ts | 13 +++++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 17181e2..04c17e8 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -141,29 +141,26 @@ const dataTypeValidator = variant("type", [ export type CategoryUnion = InferOutput; +const imageMetaValidator = strictObject({ + ID: pipe(string(), uuid()), + ImageName: string(), + Description: string(), + Image: null_(), +}); + const userImageValidator = strictObject({ ID: pipe(string(), uuid()), CreatedAt: pipe(string()), ImageID: pipe(string(), uuid()), UserID: pipe(string(), uuid()), - Image: strictObject({ - ID: pipe(string(), uuid()), - ImageName: string(), - Description: string(), - Image: null_(), - }), + Image: imageMetaValidator, }); const userProcessingImageValidator = strictObject({ ID: pipe(string(), uuid()), ImageID: pipe(string(), uuid()), UserID: pipe(string(), uuid()), - Image: strictObject({ - ID: pipe(string(), uuid()), - ImageName: string(), - Description: string(), - Image: null_(), - }), + Image: imageMetaValidator, Status: union([ literal("not-started"), literal("in-progress"), diff --git a/frontend/src/pages/search/search.ts b/frontend/src/pages/search/search.ts index bbd23ce..2e9e92c 100644 --- a/frontend/src/pages/search/search.ts +++ b/frontend/src/pages/search/search.ts @@ -1,7 +1,6 @@ import { useSearchImageContext } from "@contexts/SearchImageContext"; import { UserImage } from "@network/index"; import Fuse from "fuse.js"; -import { createEffect } from "solid-js"; // This language is stupid. `keyof` only returns common keys but this somehow doesnt. type KeysOfUnion = T extends T ? keyof T : never; @@ -15,8 +14,9 @@ const weightedTerms: Record< OrganizerID: undefined, Images: undefined, + Description: 10, + Name: 5, - Description: 2, Address: 2, PhoneNumber: 2, @@ -25,15 +25,16 @@ const weightedTerms: Record< CreatedAt: 1, StartDateTime: 1, EndDateTime: 1, - - Content: 1, }; export const useSearch = () => { - const { images } = useSearchImageContext(); + const { images, userImages } = useSearchImageContext(); + + const imageDescriptions = () => + userImages().map((i) => ({ data: { Description: i.Image.Description } })); return () => - new Fuse(images(), { + new Fuse([...images(), ...imageDescriptions()], { shouldSort: true, keys: Object.entries(weightedTerms) .filter(([, w]) => w != null)