add sorter (not working yet)

This commit is contained in:
Senghan Bright
2021-01-14 12:24:11 +01:00
parent d1eab0a69c
commit bcec7dd4b8
2 changed files with 31 additions and 2 deletions

View 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