feat(search): „+ weitere Ergebnisse"-Button für lokale und Web-Suche
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m20s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m20s
Die Ergebnislisten waren oft kurz, weil lokale Suche auf LIMIT 30 und die Web-Suche auf die erste SearXNG-Seite beschränkt war. Jetzt lässt sich beides nachladen. - `searchLocal` nimmt jetzt einen `offset` und der `/api/recipes/search`- Endpoint einen `?offset=`-Parameter. - `searchWeb` nimmt jetzt eine `pageno`-Option und reicht sie als `pageno`-Parameter an SearXNG weiter. `pageno=1` wird weggelassen, damit bestehendes Verhalten unverändert bleibt. - `/search` und `/search/web` zeigen unterhalb der Liste einen „+ weitere Ergebnisse"-Button. Beide deduplizieren nachgeladene Hits (ID bzw. URL), weil SearXNG das gleiche Ergebnis auf zwei Seiten liefern kann. Kein Endless-Scroll: expliziter Button ist mobil robuster und spart die teure Thumbnail-Enrichment-Roundtrip-Zeit, die bei jeder neuen Web-Seite anfällt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import type { SearchHit } from '$lib/server/recipes/search-local';
|
||||
|
||||
const PAGE_SIZE = 30;
|
||||
|
||||
let query = $state(($page.url.searchParams.get('q') ?? '').trim());
|
||||
let hits = $state<SearchHit[]>([]);
|
||||
let loading = $state(false);
|
||||
let loadingMore = $state(false);
|
||||
let exhausted = $state(false);
|
||||
let searched = $state(false);
|
||||
let canWebSearch = $state(false);
|
||||
|
||||
@@ -13,9 +17,13 @@
|
||||
loading = true;
|
||||
searched = true;
|
||||
canWebSearch = true;
|
||||
const res = await fetch(`/api/recipes/search?q=${encodeURIComponent(q)}`);
|
||||
exhausted = false;
|
||||
const res = await fetch(
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${PAGE_SIZE}`
|
||||
);
|
||||
const body = await res.json();
|
||||
hits = body.hits;
|
||||
exhausted = hits.length < PAGE_SIZE;
|
||||
loading = false;
|
||||
if (hits.length === 0) {
|
||||
// Kein lokaler Treffer → automatisch im Internet weitersuchen.
|
||||
@@ -24,6 +32,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMore() {
|
||||
if (loadingMore || exhausted || !query) return;
|
||||
loadingMore = true;
|
||||
try {
|
||||
const res = await fetch(
|
||||
`/api/recipes/search?q=${encodeURIComponent(query)}&limit=${PAGE_SIZE}&offset=${hits.length}`
|
||||
);
|
||||
const body = await res.json();
|
||||
const more = body.hits as SearchHit[];
|
||||
// Gegen Doppel-Treffer absichern (z.B. Race oder identisches bm25-Scoring).
|
||||
const seen = new Set(hits.map((h) => h.id));
|
||||
const deduped = more.filter((h) => !seen.has(h.id));
|
||||
hits = [...hits, ...deduped];
|
||||
if (more.length < PAGE_SIZE) exhausted = true;
|
||||
} finally {
|
||||
loadingMore = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
const q = ($page.url.searchParams.get('q') ?? '').trim();
|
||||
query = q;
|
||||
@@ -80,6 +107,13 @@
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{#if !exhausted}
|
||||
<div class="more-cta">
|
||||
<button class="more-btn" onclick={loadMore} disabled={loadingMore}>
|
||||
{loadingMore ? 'Lade …' : '+ weitere Ergebnisse'}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if canWebSearch}
|
||||
<div class="web-cta">
|
||||
<a class="web-btn" href={`/search/web?q=${encodeURIComponent(query)}`}>
|
||||
@@ -173,6 +207,27 @@
|
||||
font-size: 0.8rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.more-cta {
|
||||
margin-top: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
.more-btn {
|
||||
padding: 0.7rem 1.25rem;
|
||||
background: white;
|
||||
color: #2b6a3d;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 10px;
|
||||
font-size: 0.95rem;
|
||||
min-height: 44px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.more-btn:hover:not(:disabled) {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.more-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: progress;
|
||||
}
|
||||
.web-cta {
|
||||
margin-top: 1.25rem;
|
||||
text-align: center;
|
||||
|
||||
Reference in New Issue
Block a user