feat: Do a bit better sorting for command history
To be honest, I'm not 100% sure this is fantastic, but it's definitely a step in the right direction for command history. Closes: #150
This commit is contained in:
@@ -198,7 +198,7 @@ end
|
||||
sorters.get_generic_fuzzy_sorter = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local ngram_len = 2
|
||||
local ngram_len = opts.ngram_len or 2
|
||||
|
||||
local function overlapping_ngrams(s, n)
|
||||
if TelescopeCachedNgrams[s] and TelescopeCachedNgrams[s][n] then
|
||||
@@ -283,6 +283,30 @@ sorters.get_generic_fuzzy_sorter = function(opts)
|
||||
}
|
||||
end
|
||||
|
||||
sorters.fuzzy_with_index_bias = function(opts)
|
||||
opts = opts or {}
|
||||
opts.ngram_len = 2
|
||||
|
||||
-- TODO: Probably could use a better sorter here.
|
||||
local fuzzy_sorter = sorters.get_generic_fuzzy_sorter(opts)
|
||||
|
||||
return Sorter:new {
|
||||
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
|
||||
}
|
||||
end
|
||||
|
||||
-- Bad & Dumb Sorter
|
||||
sorters.get_levenshtein_sorter = function()
|
||||
return Sorter:new {
|
||||
|
||||
Reference in New Issue
Block a user