Skip to content

Commit

Permalink
tweak to heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Dec 10, 2024
1 parent c55259b commit cc5fa9e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/textual/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def score(search: _Search) -> float:
"""
# This is a heuristic, and can be tweaked for better results
# 2 points for a first letter, 1 for other letters
# Boost first letter matches
score: float = sum(
(2.0 if offset in first_letters else 1.0) for offset in search.offsets
)
# Divide by the number of groups
# 1 group no change, 2 groups score is halved etc.
score /= search.groups
# A single group gets a boost, as the user may be typing out an entire word
if search.groups == 1:
score *= 1.5
return score

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

0 comments on commit cc5fa9e

Please sign in to comment.