Skip to content

Commit 5c3ec85

Browse files
committed
Avoid double sorting of fuzzy-search results
1 parent bbe899b commit 5c3ec85

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

composables/useSearch.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import Fuse from 'fuse.js'
33

44
const regexSearchShape = /^\/(?<regex>.+)\/(?<flags>[a-z]*)$/s
55

6-
const sortByScore = <T extends { score?: number }>(list: T[]) => {
7-
return list.sort((a, b) => {
8-
return (a.score ?? 1) - (b.score ?? 1)
9-
})
10-
}
11-
126
const fuzzy = <T>(list: Ref<T[]>, keys: string[]) => {
137
return new Fuse(list.value, { includeScore: true, keys })
148
}
@@ -42,9 +36,8 @@ export const useSearch = <T extends Record<string, any>>(list: Ref<T[]>, { keys,
4236
// 3. If the search query is not a regex, attempt to fuzzy-find entries in the list.
4337
try {
4438
const fuzzyResults = filterer.value.search(searchQueryDebounced.value)
45-
const sortedFuzzyResults = sortByScore(fuzzyResults)
4639

47-
return sortedFuzzyResults.map((result) => result.item)
40+
return fuzzyResults.map((result) => result.item)
4841
} catch (error) {
4942
console.error(error)
5043
}

0 commit comments

Comments
 (0)