improve substr matcher

This commit is contained in:
Senghan Bright
2021-01-17 12:59:20 +01:00
parent 0e606ebfca
commit dc37ed8dd0
3 changed files with 10 additions and 17 deletions

View File

@@ -36,20 +36,17 @@ my_sorters.get_substr_matcher = function(opts)
substr.scoring_function = function(_, prompt, _, entry)
local display = entry.name:lower()
local search_terms = util.split(prompt, " ")
local matched
local search_terms = util.split(prompt, "%s")
local matched = 0
local total_search_terms = 0
for _, word in pairs(search_terms) do
matched = display:find(word, 1, true) and 1 or -1
if matched == -1 then goto continue end
total_search_terms = total_search_terms + 1
if display:find(word, 1, true) then
matched = matched + 1
end
end
::continue::
if matched == -1 then
return -1
else
return entry.index
end
return matched == total_search_terms and entry.index or -1
end
return substr

View File

@@ -34,7 +34,7 @@ end
util.split = function(str, delimiter)
local result = {}
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
for match in str:gmatch("[^" .. delimiter .. "]+") do
table.insert(result, match)
end
return result