telescope-frecency.nvim/lua/frecency/fuzzy_sorter.lua
JINNOUCHI Yasushi 42b6421061
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 64c022904871143ab12c7d6ba29c89fbabdbe15e.

* 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`
2024-04-28 17:58:45 +09:00

27 lines
725 B
Lua

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