-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fuzzy matching sorter experimentally (#166)
* feat: add fuzzy matching sorter experimentally * feat: add an option to select matcher logic * feat: separate logic to match: fuzzy, fuzzy_full * Revert "feat: separate logic to match: fuzzy, fuzzy_full" This reverts commit 64c0229. * feat: use fzy sorter and combine recency scores * feat: enable to change logic to calculate scores * feat: change the view for scores by config.matcher * docs: add note in README * docs: add note for `scoring_function`
- Loading branch information
Showing
5 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local config = require "frecency.config" | ||
local sorters = require "telescope.sorters" | ||
|
||
---@param opts any options for get_fzy_sorter() | ||
return function(opts) | ||
local fzy_sorter = sorters.get_fzy_sorter(opts) | ||
|
||
return sorters.Sorter:new { | ||
---@param prompt string | ||
---@param entry FrecencyEntry | ||
---@return number | ||
scoring_function = function(_, prompt, _, entry) | ||
if #prompt == 0 then | ||
return 1 | ||
end | ||
local fzy_score = fzy_sorter:scoring_function(prompt, entry.ordinal) | ||
if fzy_score <= 0 then | ||
return -1 | ||
end | ||
entry.fuzzy_score = config.scoring_function(entry.score, fzy_score) | ||
return entry.fuzzy_score | ||
end, | ||
|
||
highlighter = fzy_sorter.highlighter, | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters