From ec9ba5c53d53aa0fbf51ba70176ad03ec3a3581f Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 25 Jan 2024 17:16:03 -0300 Subject: [PATCH] search: buscar keywords por separado y escapar fixes #21 --- sitio/src/routes/search/+page.server.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sitio/src/routes/search/+page.server.ts b/sitio/src/routes/search/+page.server.ts index af5db94..ba04a2e 100644 --- a/sitio/src/routes/search/+page.server.ts +++ b/sitio/src/routes/search/+page.server.ts @@ -8,9 +8,15 @@ export const load: PageServerLoad = async ({ url }) => { const query = url.searchParams.get("q"); let results: null | { ean: string; name: string; imageUrl: string }[] = null; if (query) { + const sQuery = query + .replaceAll(`"`, `""`) + .split(" ") + .map((s) => `"${s}"`) + .join(" "); + console.debug(sQuery); const sqlQuery = sql`select p.ean, p.name, p.image_url as imageUrl from precios_fts f join precios p on p.ean = f.ean - where f.name match ${`"${query}"`} + where f.name match ${sQuery} group by p.ean having max(p.fetched_at) order by p.in_stock desc;`;