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:
@ -141,29 +141,26 @@ const dataTypeValidator = variant("type", [
|
||||
|
||||
export type CategoryUnion = InferOutput<typeof dataTypeValidator>;
|
||||
|
||||
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"),
|
||||
|
@ -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> = 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)
|
||||
|
Reference in New Issue
Block a user