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
This commit is contained in:
2025-07-24 14:31:08 +01:00
parent 0058cdce40
commit fa71f68de5
2 changed files with 16 additions and 18 deletions

View File

@ -141,29 +141,26 @@ const dataTypeValidator = variant("type", [
export type CategoryUnion = InferOutput<typeof dataTypeValidator>; export type CategoryUnion = InferOutput<typeof dataTypeValidator>;
const imageMetaValidator = strictObject({
ID: pipe(string(), uuid()),
ImageName: string(),
Description: string(),
Image: null_(),
});
const userImageValidator = strictObject({ const userImageValidator = strictObject({
ID: pipe(string(), uuid()), ID: pipe(string(), uuid()),
CreatedAt: pipe(string()), CreatedAt: pipe(string()),
ImageID: pipe(string(), uuid()), ImageID: pipe(string(), uuid()),
UserID: pipe(string(), uuid()), UserID: pipe(string(), uuid()),
Image: strictObject({ Image: imageMetaValidator,
ID: pipe(string(), uuid()),
ImageName: string(),
Description: string(),
Image: null_(),
}),
}); });
const userProcessingImageValidator = strictObject({ const userProcessingImageValidator = strictObject({
ID: pipe(string(), uuid()), ID: pipe(string(), uuid()),
ImageID: pipe(string(), uuid()), ImageID: pipe(string(), uuid()),
UserID: pipe(string(), uuid()), UserID: pipe(string(), uuid()),
Image: strictObject({ Image: imageMetaValidator,
ID: pipe(string(), uuid()),
ImageName: string(),
Description: string(),
Image: null_(),
}),
Status: union([ Status: union([
literal("not-started"), literal("not-started"),
literal("in-progress"), literal("in-progress"),

View File

@ -1,7 +1,6 @@
import { useSearchImageContext } from "@contexts/SearchImageContext"; import { useSearchImageContext } from "@contexts/SearchImageContext";
import { UserImage } from "@network/index"; import { UserImage } from "@network/index";
import Fuse from "fuse.js"; import Fuse from "fuse.js";
import { createEffect } from "solid-js";
// This language is stupid. `keyof` only returns common keys but this somehow doesnt. // This language is stupid. `keyof` only returns common keys but this somehow doesnt.
type KeysOfUnion<T> = T extends T ? keyof T : never; type KeysOfUnion<T> = T extends T ? keyof T : never;
@ -15,8 +14,9 @@ const weightedTerms: Record<
OrganizerID: undefined, OrganizerID: undefined,
Images: undefined, Images: undefined,
Description: 10,
Name: 5, Name: 5,
Description: 2,
Address: 2, Address: 2,
PhoneNumber: 2, PhoneNumber: 2,
@ -25,15 +25,16 @@ const weightedTerms: Record<
CreatedAt: 1, CreatedAt: 1,
StartDateTime: 1, StartDateTime: 1,
EndDateTime: 1, EndDateTime: 1,
Content: 1,
}; };
export const useSearch = () => { export const useSearch = () => {
const { images } = useSearchImageContext(); const { images, userImages } = useSearchImageContext();
const imageDescriptions = () =>
userImages().map((i) => ({ data: { Description: i.Image.Description } }));
return () => return () =>
new Fuse(images(), { new Fuse([...images(), ...imageDescriptions()], {
shouldSort: true, shouldSort: true,
keys: Object.entries(weightedTerms) keys: Object.entries(weightedTerms)
.filter(([, w]) => w != null) .filter(([, w]) => w != null)