Skip to content

Commit

Permalink
testing changes to search algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
AltriusRS committed Aug 26, 2023
1 parent a5df5b0 commit 6d02b42
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
45 changes: 41 additions & 4 deletions components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ useAsyncData(async () => {
})
const results = ref([])
const episodeResults = ref([])
const visible = ref(false)
const thumbs = ref({})
async function search (d) {
const term = d.target.value
if (term.length > 1) {
Expand All @@ -57,16 +59,28 @@ async function search (d) {
ofst: 0
})
})).json()
if (res.data.length === 0) {
if (res.data.topics.length === 0) {
results.value = [{
error: 'No Results Found'
}]
} else {
for (let i = 0; i < res.data.length; i++) {
thumbs.value[res.data[i].id] = sb.storage.from('thumbs').getPublicUrl(res.data[i].id + '.jpeg').data.publicUrl
for (let i = 0; i < res.data.topics.length; i++) {
thumbs.value[res.data.topics[i].id] = sb.storage.from('thumbs').getPublicUrl(res.data.topics[i].id + '.jpeg').data.publicUrl
}
results.value = res.data
results.value = res.data.topics
}
if (res.data.episodes.length === 0) {
episodeResults.value = [{
error: 'No Results Found'
}]
} else {
for (let i = 0; i < res.data.topics.length; i++) {
thumbs.value[res.data.episodes[i].id] = sb.storage.from('thumbs').getPublicUrl(res.data.episodes[i].id + '.jpeg').data.publicUrl
}
episodeResults.value = res.data.episodes
}
visible.value = results.value.length > 0
Expand Down Expand Up @@ -147,6 +161,7 @@ function logout () {
opacity: visible ? '0.95' : '0'
}"
>
<h2>Topics Matching Search</h2>
<template v-for="(result, index) in results" :key="index">
<div v-if="!result.error" :class="style.searchResult" @click="openVideo(result.id)">
<img :src="thumbs[result.id]">
Expand All @@ -166,6 +181,28 @@ function logout () {
<h2>No Results Found</h2>
</div>
</template>
}">
<hr>
<h2>Episodes containing search</h2>
<template v-for="(result, index) in episodeResults" :key="index">
<div v-if="!result.error" :class="style.searchResult" @click="openVideo(result.id)">
<img :src="thumbs[result.id]">
<span>
<h2>{{ result.title }}</h2>
<ul>
<li v-for="idx in (result.matched_topics.length > 2 ? 2 : result.matched_topics.length)" :key="idx">
{{ result.matched_topics[idx - 1].title }}
</li>
<li v-if="result.matched_topics.length > 2">
as well as {{ (result.matched_topics.length - 2).toLocaleString() }} other topics
</li>
</ul>
</span>
</div>
<div v-else :class="style.searchResultError">
<h2>No Results Found</h2>
</div>
</template>
</div>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions server/api/v1/search.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ export default defineEventHandler(async (event) => {
}
} else {
const s = (await sb.rpc('search', q)).data
searchCache.set(q.phrase, s)
const se = (await sb.rpc('search_episodes', q)).data
searchCache.set(q.phrase, {
topics: s,
episodes: se
})
return {
data: s,
data: {
topics: s,
episodes: se
},
time: new Date().getTime() - t.getTime()
}
}
Expand Down

0 comments on commit 6d02b42

Please sign in to comment.