search: buscar keywords por separado y escapar

fixes #21
This commit is contained in:
Cat /dev/Nulo 2024-01-25 17:16:03 -03:00
parent c687ea1484
commit ec9ba5c53d

View file

@ -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;`;