From 9b3d594f1d5acb954759203981bde5ba0ed20f3b Mon Sep 17 00:00:00 2001 From: lelo Date: Mon, 26 Jan 2026 17:20:05 +0000 Subject: [PATCH] add number of search results --- search.py | 5 +++-- static/search.js | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/search.py b/search.py index 3ea090b..387028f 100644 --- a/search.py +++ b/search.py @@ -108,6 +108,7 @@ def searchcommand(): sql += " WHERE " + " AND ".join(conditions) cursor.execute(sql, params) raw_results = cursor.fetchall() + total_results = len(raw_results) # Process results results = [] @@ -135,5 +136,5 @@ def searchcommand(): results.sort(key=lambda x: x.get(key, 0), reverse=True) # Limit results - results = results[:100] - return jsonify(results=results) + results = results[:20] + return jsonify(results=results, total=total_results) diff --git a/static/search.js b/static/search.js index 72ce144..9173b18 100644 --- a/static/search.js +++ b/static/search.js @@ -6,12 +6,16 @@ function initSearch() { // Function to render search results from a response object function renderResults(data) { const resultsDiv = document.getElementById('results'); - resultsDiv.innerHTML = '
Suchergebnisse:
'; + const results = Array.isArray(data.results) ? data.results : []; + const total = Number.isFinite(data.total) ? data.total : results.length; + const shown = results.length; + const remaining = Math.max(0, total - shown); + resultsDiv.innerHTML = `
${total} Treffer
`; const audioExts = ['.mp3', '.wav', '.ogg', '.m4a', '.flac']; - if (data.results && data.results.length > 0) { - data.results.forEach(file => { + if (results.length > 0) { + results.forEach(file => { const card = document.createElement('div'); const filenameWithoutExtension = file.filename.split('.').slice(0, -1).join('.'); const parentFolder = file.relative_path.split('/').slice(0, -1).join('/'); @@ -35,10 +39,16 @@ function initSearch() { `; resultsDiv.appendChild(card); }); + if (remaining > 0) { + const more = document.createElement('p'); + more.className = 'text-muted'; + more.textContent = `und weitere ${remaining} Treffer`; + resultsDiv.appendChild(more); + } attachEventListeners(); attachSearchFolderButtons(); } else { - resultsDiv.innerHTML = '

No results found.

'; + resultsDiv.innerHTML = `
${total} Treffer

Keine Treffer gefunden.

`; } }