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)