add number of search results
This commit is contained in:
parent
c855bfdbc1
commit
9b3d594f1d
@ -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)
|
||||
|
||||
@ -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 = '<h5>Suchergebnisse:</h5>';
|
||||
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 = `<h5>${total} Treffer</h5>`;
|
||||
|
||||
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 = '<p>No results found.</p>';
|
||||
resultsDiv.innerHTML = `<h5>${total} Treffer</h5><p>Keine Treffer gefunden.</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user