From 26cb7b80e33ebcaa8ae8571f86d2a9122a807ecb Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 4 Jan 2024 22:50:44 -0300 Subject: [PATCH] siempre conseguir ultima entry para busqueda --- sitio/src/routes/search/+page.server.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sitio/src/routes/search/+page.server.ts b/sitio/src/routes/search/+page.server.ts index fcd96d4..e00b488 100644 --- a/sitio/src/routes/search/+page.server.ts +++ b/sitio/src/routes/search/+page.server.ts @@ -7,12 +7,14 @@ 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 sqlQuery = sql`select p.ean, p.name, p.image_url as imageUrl from precios_fts f + const sqlQuery = sql`select p.ean, p.name, p.image_url as imageUrl, p.fetched_at from precios_fts f join precios p on p.ean = f.ean where f.name match ${`"${query}"`} - group by p.ean;`; + group by p.ean + having max(p.fetched_at);`; results = db.all(sqlQuery); } return { query, results }; }; +// order by p.fetched_at