Skip to content

Commit

Permalink
heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Dec 11, 2024
1 parent a1bb056 commit cc0615b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/textual/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ def score(search: _Search) -> float:
score: float = sum(
(2.0 if offset in first_letters else 1.0) for offset in search.offsets
)
# A single group gets a boost, as the user may be typing out an entire word
if search.groups == 1:
score *= 1.5
# Boost to favor less groups
offset_count = len(search.offsets)
normalized_groups = (offset_count - (search.groups - 1)) / offset_count
score *= 1 + (normalized_groups**2)
return score

stack: list[_Search] = [_Search()]
Expand Down

0 comments on commit cc0615b

Please sign in to comment.