Scoring Functions
Scoring functions are the core of the fuzzy matching logic in
FuzzyFinder.
They are responsible for calculating the score
for each candidate item in
curses_fzf.FuzzyFinder.all_items based on the
query the user has entered.
You can use the built-in scoring functions or implement your own and pass them
to FuzzyFinder’s score()
function parameter.
All scoring functions take the same parameters as
ScoringResult’s constructor,
query and
candidate.
The scoring functions create and populate a ScoringResult
internally and return it after score calculation.
A higher score indicates a better match, while a
score of 0 means the
candidate was not matched by the
query, which will filter it out of the resulting
curses_fzf.FuzzyFinder.filtered list.
Learn more about ScoringResult if you plan to implement
your own scoring functions.
Built-in Scoring Functions
- curses_fzf.scoring_fzf(query: str, candidate: str) ScoringResult[source]
A fzf-like fuzzy scoring.
This is the default scoring function used by
FuzzyFinderif no other scoring function is provided.The
querycharacters are matched as a subsequence against thecandidate(characters must appear in order). There are bonuses for consecutive matches, matches on boundaries and matches early in the candidate.
- curses_fzf.scoring_full_words(query: str, candidate: str) ScoringResult[source]
The
queryand thecandidatestring both get lowercased and split on whitespaces (seequery_words_with_index&candidate_words_with_index).Each query word is supposed to find a unique match among the words of the candidate. The closer a match is to a full word the higher the score.
An additional bonus is given, if the match is at the beginning of a word. The query words may appear in the candidate in any order, however if the original order is found a small bonus will be granted.