mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2026-02-04 23:02:06 +00:00
add sorter (not working yet)
This commit is contained in:
29
lua/telescope/_extensions/frecency/sorter.lua
Normal file
29
lua/telescope/_extensions/frecency/sorter.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
Reference in New Issue
Block a user