Skip to content

Commit 42e4ff2

Browse files
committed
Implement source diversity in search results
- Ensure top result from each source type (ArNS, docs, glossary) appears first - Apply priority hierarchy for remaining results: ArNS > docs > glossary - Prevent duplicate URLs across different source types - Increase result limit from 5 to 8 to accommodate diverse sources - Improve discovery across all available content types while maintaining relevance
1 parent 470a5c5 commit 42e4ff2

1 file changed

Lines changed: 45 additions & 9 deletions

File tree

src/components/SearchBar.vue

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,56 @@ const filteredSuggestions = computed(() => {
219219
const glossary = glossarySuggestionsComp.value;
220220
const docs = docsSuggestionsComp.value;
221221
222-
// Merge docs and glossary, preferring docs over glossary when scores are similar
223-
const mergedDocsGlossary = [...docs, ...glossary]
222+
// Ensure source diversity: pick top result from each source type first
223+
const diverseResults = [];
224+
const usedUrls = new Set();
225+
226+
// Add top ArNS result if available
227+
if (arns.length > 0) {
228+
diverseResults.push(arns[0]);
229+
usedUrls.add(arns[0].text);
230+
}
231+
232+
// Add top docs result if available
233+
if (docs.length > 0) {
234+
diverseResults.push(docs[0]);
235+
usedUrls.add(docs[0].fullUrl);
236+
}
237+
238+
// Add top glossary result if available
239+
if (glossary.length > 0) {
240+
diverseResults.push(glossary[0]);
241+
usedUrls.add(glossary[0].text);
242+
}
243+
244+
// Merge remaining results with priority hierarchy
245+
const allRemaining = [...arns.slice(1), ...docs.slice(1), ...glossary.slice(1)]
246+
.filter(item => {
247+
const urlKey = item.type === 'arns' ? item.text :
248+
item.type === 'docs' ? item.fullUrl : item.text;
249+
return !usedUrls.has(urlKey);
250+
})
224251
.sort((a, b) => {
225-
// If scores are very close (within 10 points), prefer docs
226-
if (Math.abs(a.score - b.score) <= 10) {
227-
return a.type === 'docs' ? -1 : 1;
252+
// Priority hierarchy: ArNS > docs > glossary
253+
const priority = { arns: 3, docs: 2, glossary: 1 };
254+
const priorityDiff = priority[b.type] - priority[a.type];
255+
256+
if (priorityDiff !== 0) return priorityDiff;
257+
258+
// Within same type, prefer docs over glossary when scores are similar
259+
if (a.type === 'docs' && b.type === 'glossary' && Math.abs(a.score - b.score) <= 10) {
260+
return -1;
261+
}
262+
if (b.type === 'docs' && a.type === 'glossary' && Math.abs(a.score - b.score) <= 10) {
263+
return 1;
228264
}
265+
229266
// Otherwise sort by score descending
230267
return b.score - a.score;
231-
})
232-
.slice(0, 5); // Limit to top 5 results
268+
});
233269
234-
// Priority order: ArNS first, then docs/glossary with docs preference
235-
return [...arns, ...mergedDocsGlossary];
270+
// Combine diverse results with remaining results, limit to top 8
271+
return [...diverseResults, ...allRemaining].slice(0, 8);
236272
});
237273
238274
const suggestions = computed(() => {

0 commit comments

Comments
 (0)