mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
30 lines
611 B
Lua
30 lines
611 B
Lua
local sorters = require "telescope.sorters"
|
|
|
|
local my_sorters = {}
|
|
|
|
my_sorters.get_frecency_sorter = function(opts)
|
|
opts = opts or {}
|
|
opts.ngram_len = 2
|
|
|
|
local fuzzy_sorter = sorters.get_generic_fuzzy_sorter(opts)
|
|
|
|
local frecency = sorters:new()
|
|
frecency.scoring_function = function(_, prompt, _, entry)
|
|
local base_score = fuzzy_sorter:score(prompt, entry)
|
|
|
|
if base_score == -1 then
|
|
return -1
|
|
end
|
|
|
|
if base_score == 0 then
|
|
return entry.index
|
|
else
|
|
return math.min(math.pow(entry.index, 0.25), 2) * base_score
|
|
end
|
|
end
|
|
|
|
return frecency
|
|
end
|
|
|
|
return my_sorters
|