feat(search): Domain-Filter als Dropdown im Suchfeld
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
Links im großen Suchfeld ein Slider-Icon mit Badge („Alle" oder „2/5"), das ein Dropdown-Menü mit allen Whitelist-Domains als Checkboxen öffnet. Auswahl wird per localStorage persistiert und gilt global — Header-Such- Dropdown konsumiert den gleichen Store und sendet den domains-Parameter bei jedem Fetch mit. Leere Menge heißt „alle aktiv", damit neu vom Admin freigeschaltete Domains automatisch dabei sind. Aktive Auswahl landet als explizite Intersection mit der Whitelist serverseitig. - searchLocal nimmt jetzt optional string[] domains → `source_domain IN (…)`. - searchWeb nimmt jetzt opts.domains → site:-Filter auf die Auswahl eingeschränkt. Nicht-Whitelist-Einträge werden ignoriert. - API-Endpoints: `?domains=a.de,b.de`. - Neuer Client-Store $lib/client/search-filter.svelte.ts. - Neue Komponente $lib/components/SearchFilter.svelte (mobile-tauglich, 44px Touch-Targets, Badge auf engen Screens versteckt). Home-Seite re-runt die Suche bei Filter-Änderung automatisch (150ms debounce), ohne dass der User neu tippen muss. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -30,15 +30,16 @@ export function searchLocal(
|
||||
db: Database.Database,
|
||||
query: string,
|
||||
limit = 30,
|
||||
offset = 0
|
||||
offset = 0,
|
||||
domains: string[] = []
|
||||
): SearchHit[] {
|
||||
const fts = buildFtsQuery(query);
|
||||
if (!fts) return [];
|
||||
|
||||
// bm25: lower is better. Use weights: title > tags > ingredients > description
|
||||
return db
|
||||
.prepare(
|
||||
`SELECT r.id,
|
||||
const hasFilter = domains.length > 0;
|
||||
const placeholders = hasFilter ? domains.map(() => '?').join(',') : '';
|
||||
const sql = `SELECT r.id,
|
||||
r.title,
|
||||
r.description,
|
||||
r.image_path,
|
||||
@@ -48,10 +49,13 @@ export function searchLocal(
|
||||
FROM recipe r
|
||||
JOIN recipe_fts f ON f.rowid = r.id
|
||||
WHERE recipe_fts MATCH ?
|
||||
${hasFilter ? `AND r.source_domain IN (${placeholders})` : ''}
|
||||
ORDER BY bm25(recipe_fts, 10.0, 0.5, 2.0, 5.0)
|
||||
LIMIT ? OFFSET ?`
|
||||
)
|
||||
.all(fts, limit, offset) as SearchHit[];
|
||||
LIMIT ? OFFSET ?`;
|
||||
const params = hasFilter
|
||||
? [fts, ...domains, limit, offset]
|
||||
: [fts, limit, offset];
|
||||
return db.prepare(sql).all(...params) as SearchHit[];
|
||||
}
|
||||
|
||||
export function listRecentRecipes(
|
||||
|
||||
@@ -287,12 +287,18 @@ export async function searchWeb(
|
||||
limit?: number;
|
||||
enrichThumbnails?: boolean;
|
||||
pageno?: number;
|
||||
domains?: string[];
|
||||
} = {}
|
||||
): Promise<WebHit[]> {
|
||||
const trimmed = query.trim();
|
||||
if (!trimmed) return [];
|
||||
const domains = listDomains(db).map((d) => d.domain);
|
||||
if (domains.length === 0) return [];
|
||||
const allDomains = listDomains(db).map((d) => d.domain);
|
||||
if (allDomains.length === 0) return [];
|
||||
// Optionaler Domain-Filter: Intersection mit der Whitelist, damit der
|
||||
// Filter nie außerhalb der erlaubten Domains sucht.
|
||||
const whitelist = new Set(allDomains);
|
||||
const filtered = opts.domains?.filter((d) => whitelist.has(d)) ?? [];
|
||||
const domains = filtered.length > 0 ? filtered : allDomains;
|
||||
|
||||
const searxngUrl = opts.searxngUrl ?? process.env.SEARXNG_URL ?? 'http://localhost:8888';
|
||||
const limit = opts.limit ?? 20;
|
||||
|
||||
Reference in New Issue
Block a user