adds search api

This commit is contained in:
Christian Beutel
2024-03-09 19:05:21 +01:00
parent 1b493f576e
commit 963b589b2d
8 changed files with 133 additions and 69 deletions

View File

@@ -0,0 +1,13 @@
import { ms } from "$lib/meilisearch";
import { error, json, type RequestEvent } from "@sveltejs/kit";
export async function POST(event: RequestEvent) {
const data = await event.request.json()
try {
const r = await ms.index(event.params.index as string).search(data.q, data.options);
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -0,0 +1,15 @@
import { ms } from "$lib/meilisearch";
import { error, json, type RequestEvent } from "@sveltejs/kit";
export async function POST(event: RequestEvent) {
const data = await event.request.json()
try {
const r = await ms.multiSearch({
queries: data.queries
});
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}