Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmdpalette] fix scoring of space-separated search terms #2646

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading