fix: trace debug — show Stranger_NNN for unnamed traces instead of unknown
This commit is contained in:
+130
-27
@@ -20,26 +20,52 @@
|
||||
{{ loading ? '搜尋中...' : '搜尋' }}
|
||||
</button>
|
||||
</div>
|
||||
<!-- Mode Selector -->
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="text-gray-400 text-sm">搜尋模式:</span>
|
||||
<select
|
||||
v-model="searchMode"
|
||||
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
|
||||
>
|
||||
<option value="vector">向量搜尋 (Vector)</option>
|
||||
<option value="bm25">關鍵字搜尋 (BM25)</option>
|
||||
<option value="hybrid">混合搜尋 (Hybrid)</option>
|
||||
<option value="smart">智慧搜尋 (Smart)</option>
|
||||
</select>
|
||||
<div class="flex flex-wrap items-center gap-4">
|
||||
<!-- Result Type -->
|
||||
<div class="flex items-center space-x-2">
|
||||
<span class="text-gray-400 text-sm">搜尋類型:</span>
|
||||
<select
|
||||
v-model="searchType"
|
||||
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
|
||||
>
|
||||
<option value="chunk">文字區塊 (Chunk)</option>
|
||||
<option value="trace">臉部軌跡 (Trace)</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Mode Selector -->
|
||||
<div v-if="searchType === 'chunk'" class="flex items-center space-x-2">
|
||||
<span class="text-gray-400 text-sm">搜尋模式:</span>
|
||||
<select
|
||||
v-model="searchMode"
|
||||
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
|
||||
>
|
||||
<option value="vector">向量搜尋 (Vector)</option>
|
||||
<option value="bm25">關鍵字搜尋 (BM25)</option>
|
||||
<option value="hybrid">混合搜尋 (Hybrid)</option>
|
||||
<option value="smart">智慧搜尋 (Smart)</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- File Selector -->
|
||||
<div class="flex items-center space-x-2">
|
||||
<span class="text-gray-400 text-sm">搜尋檔案:</span>
|
||||
<select
|
||||
v-model="selectedFileUuid"
|
||||
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm max-w-[300px] focus:outline-none focus:border-blue-500"
|
||||
>
|
||||
<option value="">所有檔案</option>
|
||||
<option v-for="f in files" :key="f.file_uuid" :value="f.file_uuid">
|
||||
{{ f.file_name?.substring(0, 40) || f.file_uuid }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="text-gray-500 text-xs">
|
||||
{{ modeDescription }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
<div v-if="results.length > 0" class="space-y-4">
|
||||
<!-- Results: Chunks -->
|
||||
<div v-if="searchType === 'chunk' && results.length > 0" class="space-y-4">
|
||||
<h3 class="text-xl font-semibold">搜尋結果 ({{ results.length }})</h3>
|
||||
<div class="grid gap-4">
|
||||
<div
|
||||
@@ -98,10 +124,41 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- No Results -->
|
||||
<div v-else-if="searched && !loading" class="text-center py-12 text-gray-500">
|
||||
<!-- No Results: Chunks -->
|
||||
<div v-else-if="searchType === 'chunk' && searched && !loading" class="text-center py-12 text-gray-500">
|
||||
找不到符合的結果
|
||||
</div>
|
||||
|
||||
<!-- Results: Traces -->
|
||||
<div v-if="searchType === 'trace' && traceResults.length > 0" class="space-y-4">
|
||||
<h3 class="text-xl font-semibold">Trace 搜尋結果 ({{ traceResults.length }})</h3>
|
||||
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
|
||||
<div
|
||||
v-for="trace in traceResults"
|
||||
:key="trace.trace_id"
|
||||
@click="goToTrace(trace)"
|
||||
class="bg-gray-800 rounded-lg border border-gray-700 overflow-hidden cursor-pointer hover:border-blue-500 transition"
|
||||
>
|
||||
<div class="aspect-square bg-gray-700 flex items-center justify-center overflow-hidden">
|
||||
<img
|
||||
:src="getTraceThumbnail(trace)"
|
||||
alt="Trace"
|
||||
class="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
<div class="p-3 space-y-1">
|
||||
<div class="text-sm font-semibold text-blue-300">Trace #{{ trace.trace_id }}</div>
|
||||
<div class="text-xs text-gray-400">{{ trace.face_count }} faces, {{ trace.duration_sec?.toFixed(1) || '?' }}s</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- No Results: Traces -->
|
||||
<div v-else-if="searchType === 'trace' && searched && !loading" class="text-center py-12 text-gray-500">
|
||||
找不到符合的 Trace
|
||||
</div>
|
||||
</div>
|
||||
<!-- Player Modal -->
|
||||
<div v-if="player.visible" class="fixed inset-0 bg-black bg-opacity-80 z-50 flex items-center justify-center p-4" @click.self="player.visible = false">
|
||||
@@ -113,6 +170,7 @@
|
||||
</div>
|
||||
<video
|
||||
ref="videoPlayer"
|
||||
:key="player.url"
|
||||
:src="player.url"
|
||||
class="w-full"
|
||||
controls
|
||||
@@ -126,7 +184,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, reactive } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { searchVideos, getCurrentConfig } from '@/api/client'
|
||||
import { searchVideos, getVideos, getCurrentConfig } from '@/api/client'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -147,19 +205,32 @@ const playChunk = (hit: SearchHit) => {
|
||||
player.title = hit.text.substring(0, 80)
|
||||
player.start = hit.start
|
||||
player.end = hit.end
|
||||
player.url = `${config.api_base_url}/api/v1/file/${hit.vid}/video#t=${hit.start},${hit.end}`
|
||||
player.url = `${config.api_base_url}/api/v1/file/${hit.vid}/video?start=${hit.start}&end=${hit.end}`
|
||||
}
|
||||
|
||||
const seekToStart = () => {
|
||||
const el = videoPlayer.value
|
||||
if (el) {
|
||||
if (!el || !player.start) return
|
||||
if (!player.url.includes('start=')) {
|
||||
el.currentTime = player.start
|
||||
setTimeout(() => { if (el.currentTime > player.end) el.pause() }, (player.end - player.start) * 1000 + 2000)
|
||||
}
|
||||
const duration = Math.max(player.end - player.start, 1)
|
||||
setTimeout(() => { if (el.currentTime >= player.end) el.pause() }, duration * 1000 + 2000)
|
||||
}
|
||||
|
||||
async function loadFiles() {
|
||||
try {
|
||||
const result = await getVideos()
|
||||
files.value = result.data || result.files || []
|
||||
if (files.value.length > 0 && !selectedFileUuid.value) {
|
||||
// Don't auto-select; let user choose "所有檔案" by default
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
localStorage.removeItem('searchState')
|
||||
loadFiles()
|
||||
|
||||
const q = route.query.q as string
|
||||
if (q) {
|
||||
@@ -186,9 +257,13 @@ interface SearchHit {
|
||||
|
||||
const searchQuery = ref('')
|
||||
const searchMode = ref('vector')
|
||||
const results = ref<SearchHit[]>([])
|
||||
const searchType = ref('chunk')
|
||||
const results = ref<any[]>([])
|
||||
const traceResults = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const searched = ref(false)
|
||||
const files = ref<any[]>([])
|
||||
const selectedFileUuid = ref('')
|
||||
|
||||
const modeDescription = computed(() => {
|
||||
const modes: Record<string, string> = {
|
||||
@@ -202,26 +277,54 @@ const modeDescription = computed(() => {
|
||||
|
||||
const performSearch = async () => {
|
||||
if (!searchQuery.value.trim()) return
|
||||
|
||||
|
||||
loading.value = true
|
||||
searched.value = true
|
||||
|
||||
|
||||
if (files.value.length === 0) {
|
||||
try {
|
||||
const result = await getVideos()
|
||||
files.value = result.data || result.files || []
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await searchVideos(searchQuery.value, 20, searchMode.value)
|
||||
results.value = result.hits
|
||||
if (searchType.value === 'chunk') {
|
||||
const result = await searchVideos(searchQuery.value, 20, searchMode.value, selectedFileUuid.value || undefined)
|
||||
results.value = result.hits
|
||||
} else {
|
||||
// Trace search — API returns traces with overlapping chunk matches
|
||||
const config = getCurrentConfig()
|
||||
const params = new URLSearchParams({ query: searchQuery.value, limit: '50' })
|
||||
if (selectedFileUuid.value) params.set('uuid', selectedFileUuid.value)
|
||||
const resp = await fetch(`${config.api_base_url}/api/v1/search/traces?${params}`, {
|
||||
headers: config.api_key ? { 'X-API-Key': config.api_key } : {}
|
||||
})
|
||||
const data = await resp.json()
|
||||
traceResults.value = data.traces || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Search failed:', error)
|
||||
alert('搜尋失敗: ' + error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const goToTrace = (trace: any) => {
|
||||
router.push(`/traces/${trace.file_uuid || selectedFileUuid.value}/${trace.trace_id}`)
|
||||
}
|
||||
|
||||
const getTraceThumbnail = (trace: any): string => {
|
||||
const config = getCurrentConfig()
|
||||
const fuid = trace.file_uuid || selectedFileUuid.value
|
||||
return `${config.api_base_url}/api/v1/file/${fuid}/thumbnail?frame=${trace.first_frame}`
|
||||
}
|
||||
|
||||
const goToDetail = (uuid: string, chunkId: string) => {
|
||||
localStorage.setItem('searchState', JSON.stringify({ query: searchQuery.value, results: results.value }))
|
||||
router.push({
|
||||
name: 'chunk-detail',
|
||||
params: { uuid, chunkId }
|
||||
params: { file_uuid: uuid, chunk_id: chunkId }
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user