Skip to content

Commit fbdc9d4

Browse files
authored
Improve node search matching algorithm (#597)
1 parent 3e457f8 commit fbdc9d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/services/nodeSearchService.ts

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

127134
const filterSearchOptions = {

0 commit comments

Comments
 (0)