Skip to content

Commit f40ba4c

Browse files
midichefanjakefala
authored andcommitted
[cmdpalette-] fix scoring of space-separated search terms
Previously only the score for the final search term was used.
1 parent c836d6c commit f40ba4c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

visidata/fuzzymatch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,17 @@ def fuzzymatch(vd, haystack:"list[dict[str, str]]", needles:"list[str]) -> list[
375375
formatted_hay = {}
376376
for k, v in h.items():
377377
if k[0] == '_': continue
378+
positions = set()
378379
for p in needles:
379380
mr = _fuzzymatch(v, p)
380381
if mr.score > 0:
381-
match[k] = mr
382-
formatted_hay[k] = _format_match(v, mr.positions)
382+
match.setdefault(k, []).append(mr)
383+
positions |= set(mr.positions)
384+
formatted_hay[k] = _format_match(v, positions)
383385

384386
if match:
385387
# square to prefer larger scores in a single haystack
386-
score = int(sum(mr.score**2 for mr in match.values()))
388+
score = int(sum([mr.score**2 for mrs in match.values() for mr in mrs]))
387389
matches.append(CombinedMatch(score=score, formatted=formatted_hay, match=h))
388390

389391
return sorted(matches, key=lambda m: -m.score)

0 commit comments

Comments
 (0)