mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
switch to substring matcher (WIP)
This commit is contained in:
parent
6ca37f320f
commit
992b72de02
@ -71,8 +71,9 @@ local frecency = function(opts)
|
|||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
previewer = conf.file_previewer(opts),
|
-- previewer = conf.file_previewer(opts),
|
||||||
sorter = sorters.get_frecency_sorter(opts),
|
sorter = sorters.get_substr_matcher(opts),
|
||||||
|
-- sorter = conf.file_sorter(opts)
|
||||||
}):find()
|
}):find()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -2,16 +2,31 @@ local sorters = require "telescope.sorters"
|
|||||||
|
|
||||||
local my_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 = 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()
|
-- TODO: split the prompt into components
|
||||||
frecency.highlighter = fuzzy_sorter.highlighter
|
base_score = entry.name:find(prompt, 1, true) and 1 or -1
|
||||||
frecency.scoring_function = function(_, prompt, _, entry)
|
|
||||||
local base_score = fuzzy_sorter:score(prompt, entry)
|
|
||||||
|
|
||||||
if base_score == -1 then
|
if base_score == -1 then
|
||||||
return -1
|
return -1
|
||||||
@ -20,11 +35,11 @@ my_sorters.get_frecency_sorter = function(opts)
|
|||||||
if base_score == 0 then
|
if base_score == 0 then
|
||||||
return entry.index
|
return entry.index
|
||||||
else
|
else
|
||||||
return math.min(math.pow(entry.index, 0.25), 2) * base_score
|
return entry.index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return frecency
|
return substr
|
||||||
end
|
end
|
||||||
|
|
||||||
return my_sorters
|
return my_sorters
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user