Skip to content

Commit 77ba201

Browse files
authored
Add custom sort function to improve search matching (#574)
1 parent 6edfc9b commit 77ba201

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/services/nodeSearchService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ export class NodeSearchService {
121121
includeScore: true,
122122
threshold: 0.3,
123123
shouldSort: true,
124-
useExtendedSearch: true
124+
useExtendedSearch: true,
125+
// Sort by score first, then by length of the display name, then by index
126+
// https://github.com/Comfy-Org/ComfyUI_frontend/issues/562#issuecomment-2299738393
127+
sortFn: (a, b) =>
128+
Math.abs(a.score - b.score) > 0.01
129+
? a.score - b.score
130+
: a.item[1]['v']['length'] - b.item[1]['v']['length'] || a.idx - b.idx
125131
})
126132

127133
const filterSearchOptions = {

0 commit comments

Comments
 (0)