Render grouped item search results

This commit is contained in:
Sleeps
2026-10-07 17:03:21 +01:00
parent 8aff833340
commit dc04125246
+59 -8
View File
@@ -34,6 +34,11 @@
.result img { width:180px; height:102px; object-fit:cover; background:#08090b; }
.result .body { padding:12px 12px 12px 0; }
.result h3 { margin:0 0 6px; }
.scene-details { margin-top:10px; border-top:1px solid #282d36; padding-top:8px; }
.scene-details summary { cursor:pointer; color:#cbd5e1; }
.scene-match { padding:8px 0; border-bottom:1px solid #232832; }
.scene-match:last-child { border-bottom:0; }
.match-count { display:inline-block; margin-left:6px; font-size:.82rem; color:#9ca3af; font-weight:500; }
code { background:#101318; padding:2px 5px; border-radius:5px; }
@media(max-width:640px){ .result{grid-template-columns:1fr}.result img{width:100%;height:auto}.result .body{padding:0 12px 12px} }
</style>
@@ -571,20 +576,66 @@
thumbnailUrls.forEach(URL.revokeObjectURL);
thumbnailUrls = [];
$('results').innerHTML = '';
$('searchStatus').className = 'status muted';
$('searchStatus').textContent = 'Searching…';
try {
const data = await api('/api/search?q=' + encodeURIComponent(q) + '&scene_limit=20&item_limit=10');
const scenes = data.scenes || [];
$('searchStatus').textContent = scenes.length + ' scene match' + (scenes.length === 1 ? '' : 'es');
for (const scene of scenes) {
const items = data.items || [];
const candidateScenes = Number(data.candidate_scene_count || data.scene_count || 0);
$('searchStatus').textContent =
items.length + ' title match' + (items.length === 1 ? '' : 'es') +
(candidateScenes ? ' from ' + candidateScenes + ' scene candidate' +
(candidateScenes === 1 ? '' : 's') : '');
for (const item of items) {
const matches = Array.isArray(item.matching_scenes) && item.matching_scenes.length
? item.matching_scenes
: [{
frame_id: null,
timestamp_ms: item.best_timestamp_ms,
caption: item.best_caption,
ranking_score: item.ranking_score,
siglip_score: item.siglip_score
}];
const best = matches[0];
const totalMatches = Number(item.scene_matches || matches.length || 1);
const shownMatches = matches.length;
const el = document.createElement('article');
el.className = 'result';
el.innerHTML = '<img alt=""><div class="body"><h3>' + escapeHtml(scene.title || 'Untitled') +
' <span class="muted">@ ' + formatTs(scene.timestamp_ms) + '</span></h3><div>' +
escapeHtml(scene.caption || 'No caption yet') + '</div><div class="muted" style="margin-top:6px">score ' +
(scene.ranking_score == null ? '—' : Number(scene.ranking_score).toFixed(3)) + '</div></div>';
const details = matches.map(scene => {
const score = scene.ranking_score == null
? (scene.siglip_score == null ? '—' : Number(scene.siglip_score).toFixed(3))
: Number(scene.ranking_score).toFixed(3);
return '<div class="scene-match"><strong>' + formatTs(scene.timestamp_ms) +
'</strong> · ' + escapeHtml(scene.caption || 'No caption yet') +
'<div class="muted">score ' + score + '</div></div>';
}).join('');
const moreText = totalMatches > shownMatches
? ' · showing top ' + shownMatches
: '';
el.innerHTML =
'<img alt=""><div class="body"><h3>' +
escapeHtml(item.title || 'Untitled') +
'<span class="match-count">' + totalMatches + ' matching scene' +
(totalMatches === 1 ? '' : 's') + '</span></h3>' +
'<div><strong>Best match @ ' + formatTs(best.timestamp_ms) + '</strong></div>' +
'<div style="margin-top:4px">' + escapeHtml(best.caption || 'No caption yet') + '</div>' +
'<div class="muted" style="margin-top:6px">score ' +
(best.ranking_score == null
? (best.siglip_score == null ? '—' : Number(best.siglip_score).toFixed(3))
: Number(best.ranking_score).toFixed(3)) +
'</div>' +
(matches.length > 1
? '<details class="scene-details"><summary>View matching scenes' +
moreText + '</summary>' + details + '</details>'
: '') +
'</div>';
$('results').appendChild(el);
if (scene.frame_id) loadThumbnail(scene.frame_id, el.querySelector('img'));
if (best.frame_id) loadThumbnail(best.frame_id, el.querySelector('img'));
}
} catch (e) {
$('searchStatus').className = 'status error';