fix(tui): add weight to fuzzy search to maintain title priority (#10106)
This commit is contained in:
parent
1b244bf850
commit
510f595e25
1 changed files with 13 additions and 5 deletions
|
|
@ -72,15 +72,23 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||||
let input: InputRenderable
|
let input: InputRenderable
|
||||||
|
|
||||||
const filtered = createMemo(() => {
|
const filtered = createMemo(() => {
|
||||||
if (props.skipFilter) {
|
if (props.skipFilter) return props.options.filter((x) => x.disabled !== true)
|
||||||
return props.options.filter((x) => x.disabled !== true)
|
|
||||||
}
|
|
||||||
const needle = store.filter.toLowerCase()
|
const needle = store.filter.toLowerCase()
|
||||||
const result = pipe(
|
const options = pipe(
|
||||||
props.options,
|
props.options,
|
||||||
filter((x) => x.disabled !== true),
|
filter((x) => x.disabled !== true),
|
||||||
(x) => (!needle ? x : fuzzysort.go(needle, x, { keys: ["title", "category"] }).map((x) => x.obj)),
|
|
||||||
)
|
)
|
||||||
|
if (!needle) return options
|
||||||
|
|
||||||
|
// prioritize title matches (weight: 2) over category matches (weight: 1).
|
||||||
|
// users typically search by the item name, and not its category.
|
||||||
|
const result = fuzzysort
|
||||||
|
.go(needle, options, {
|
||||||
|
keys: ["title", "category"],
|
||||||
|
scoreFn: (r) => r[0].score * 2 + r[1].score,
|
||||||
|
})
|
||||||
|
.map((x) => x.obj)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue