Skip to content

Commit

Permalink
[cmdpalette] fix scoring of space-separated search terms
Browse files Browse the repository at this point in the history
Previously only the score for the final search term was used.
  • Loading branch information
midichef committed Dec 20, 2024
1 parent efbe84e commit 09567e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions visidata/fuzzymatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,17 @@ def fuzzymatch(vd, haystack:"list[dict[str, str]]", needles:"list[str]) -> list[
formatted_hay = {}
for k, v in h.items():
if k[0] == '_': continue
positions = set()
for p in needles:
mr = _fuzzymatch(v, p)
if mr.score > 0:
match[k] = mr
formatted_hay[k] = _format_match(v, mr.positions)
match.setdefault(k, []).append(mr)
positions |= set(mr.positions)
formatted_hay[k] = _format_match(v, positions)

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

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

0 comments on commit 09567e1

Please sign in to comment.