switch to substring matcher (WIP)

This commit is contained in:
Senghan Bright 2021-01-14 20:56:56 +01:00
parent 6ca37f320f
commit 992b72de02
2 changed files with 27 additions and 11 deletions

View File

@ -71,8 +71,9 @@ local frecency = function(opts)
}
end,
},
previewer = conf.file_previewer(opts),
sorter = sorters.get_frecency_sorter(opts),
-- previewer = conf.file_previewer(opts),
sorter = sorters.get_substr_matcher(opts),
-- sorter = conf.file_sorter(opts)
}):find()
end

View File

@ -2,16 +2,31 @@ local sorters = require "telescope.sorters"
local my_sorters = {}
my_sorters.get_frecency_sorter = function(opts)
local substr_highlighter = function(_, prompt, display)
local highlights = {}
display = display:lower()
local hl_start, hl_end
hl_start, hl_end = display:find(prompt, 1, true)
if hl_start then
table.insert(highlights, {start = hl_start, finish = hl_end})
end
return highlights
end
my_sorters.get_substr_matcher = function(opts)
opts = opts or {}
opts.ngram_len = 2
local fuzzy_sorter = sorters.get_generic_fuzzy_sorter(opts)
local substr = sorters:new()
substr.highlighter = substr_highlighter
substr.scoring_function = function(_, prompt, _, entry)
-- local base_score = frecency:score(prompt, entry)
local base_score
local frecency = sorters:new()
frecency.highlighter = fuzzy_sorter.highlighter
frecency.scoring_function = function(_, prompt, _, entry)
local base_score = fuzzy_sorter:score(prompt, entry)
-- TODO: split the prompt into components
base_score = entry.name:find(prompt, 1, true) and 1 or -1
if base_score == -1 then
return -1
@ -20,11 +35,11 @@ my_sorters.get_frecency_sorter = function(opts)
if base_score == 0 then
return entry.index
else
return math.min(math.pow(entry.index, 0.25), 2) * base_score
return entry.index
end
end
return frecency
return substr
end
return my_sorters