diff --git a/scene_search/web/index.html b/scene_search/web/index.html index 22f1c03..023fb8a 100644 --- a/scene_search/web/index.html +++ b/scene_search/web/index.html @@ -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} } @@ -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 = '

' + escapeHtml(scene.title || 'Untitled') + - ' @ ' + formatTs(scene.timestamp_ms) + '

' + - escapeHtml(scene.caption || 'No caption yet') + '
score ' + - (scene.ranking_score == null ? '—' : Number(scene.ranking_score).toFixed(3)) + '
'; + + 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 '
' + formatTs(scene.timestamp_ms) + + ' · ' + escapeHtml(scene.caption || 'No caption yet') + + '
score ' + score + '
'; + }).join(''); + + const moreText = totalMatches > shownMatches + ? ' · showing top ' + shownMatches + : ''; + + el.innerHTML = + '

' + + escapeHtml(item.title || 'Untitled') + + '' + totalMatches + ' matching scene' + + (totalMatches === 1 ? '' : 's') + '

' + + '
Best match @ ' + formatTs(best.timestamp_ms) + '
' + + '
' + escapeHtml(best.caption || 'No caption yet') + '
' + + '
score ' + + (best.ranking_score == null + ? (best.siglip_score == null ? '—' : Number(best.siglip_score).toFixed(3)) + : Number(best.ranking_score).toFixed(3)) + + '
' + + (matches.length > 1 + ? '
View matching scenes' + + moreText + '' + details + '
' + : '') + + '
'; + $('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';