Sort then slice

This commit is contained in:
Simon Cambier
2023-03-11 13:32:26 +01:00
parent eb1576c972
commit 58db940b68
2 changed files with 3 additions and 4 deletions

View File

@@ -130,9 +130,7 @@
async function updateResults() { async function updateResults() {
query = new Query(searchQuery) query = new Query(searchQuery)
resultNotes = (await searchEngine.getSuggestions(query)).sort( resultNotes = await searchEngine.getSuggestions(query)
(a, b) => b.score - a.score
)
selectedIndex = 0 selectedIndex = 0
await scrollIntoView() await scrollIntoView()
} }

View File

@@ -247,7 +247,8 @@ export class Omnisearch {
} }
} }
results = results.slice(0, 50) // Sort results and keep the 50 best
results = results.sort((a, b) => b.score - a.score).slice(0, 50)
const documents = await Promise.all( const documents = await Promise.all(
results.map(async result => await cacheManager.getDocument(result.id)) results.map(async result => await cacheManager.getDocument(result.id))