From 09567e18a23396700d4aaf8ea736d53db1e85f92 Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Thu, 19 Dec 2024 01:21:08 -0800 Subject: [PATCH] [cmdpalette] fix scoring of space-separated search terms Previously only the score for the final search term was used. --- visidata/fuzzymatch.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/visidata/fuzzymatch.py b/visidata/fuzzymatch.py index 116933bb5..a8a634ee7 100644 --- a/visidata/fuzzymatch.py +++ b/visidata/fuzzymatch.py @@ -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)