Fix #1443
This commit is contained in:
@@ -78,7 +78,7 @@ end
|
|||||||
---Match entry
|
---Match entry
|
||||||
---@param input string
|
---@param input string
|
||||||
---@param word string
|
---@param word string
|
||||||
---@param option { synonyms: string[], disallow_fuzzy_matching: boolean, disallow_partial_fuzzy_matching: boolean, disallow_partial_matching: boolean, disallow_prefix_unmatching: boolean }
|
---@param option { synonyms: string[], disallow_fullfuzzy_matching: boolean, disallow_fuzzy_matching: boolean, disallow_partial_fuzzy_matching: boolean, disallow_partial_matching: boolean, disallow_prefix_unmatching: boolean }
|
||||||
---@return integer
|
---@return integer
|
||||||
matcher.match = function(input, word, option)
|
matcher.match = function(input, word, option)
|
||||||
option = option or {}
|
option = option or {}
|
||||||
@@ -129,7 +129,7 @@ matcher.match = function(input, word, option)
|
|||||||
|
|
||||||
if #matches == 0 then
|
if #matches == 0 then
|
||||||
if not option.disallow_fuzzy_matching and not option.disallow_prefix_unmatching and not option.disallow_partial_fuzzy_matching then
|
if not option.disallow_fuzzy_matching and not option.disallow_prefix_unmatching and not option.disallow_partial_fuzzy_matching then
|
||||||
if matcher.fuzzy(input, word, matches) then
|
if matcher.fuzzy(input, word, matches, option) then
|
||||||
return 1, matches
|
return 1, matches
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -185,7 +185,7 @@ matcher.match = function(input, word, option)
|
|||||||
if matches[#matches].input_match_end < #input then
|
if matches[#matches].input_match_end < #input then
|
||||||
if not option.disallow_fuzzy_matching then
|
if not option.disallow_fuzzy_matching then
|
||||||
if not option.disallow_partial_fuzzy_matching or prefix then
|
if not option.disallow_partial_fuzzy_matching or prefix then
|
||||||
if matcher.fuzzy(input, word, matches) then
|
if matcher.fuzzy(input, word, matches, option) then
|
||||||
return score, matches
|
return score, matches
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -197,7 +197,7 @@ matcher.match = function(input, word, option)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- fuzzy
|
--- fuzzy
|
||||||
matcher.fuzzy = function(input, word, matches)
|
matcher.fuzzy = function(input, word, matches, option)
|
||||||
local input_index = matches[#matches] and (matches[#matches].input_match_end + 1) or 1
|
local input_index = matches[#matches] and (matches[#matches].input_match_end + 1) or 1
|
||||||
|
|
||||||
-- Lately specified middle of text.
|
-- Lately specified middle of text.
|
||||||
@@ -218,10 +218,9 @@ matcher.fuzzy = function(input, word, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Remaining text fuzzy match.
|
-- Remaining text fuzzy match.
|
||||||
local last_input_index = input_index
|
|
||||||
local matched = false
|
local matched = false
|
||||||
local word_offset = 0
|
local word_offset = 0
|
||||||
local word_index = matches[1] and (matches[1].word_match_end + 1) or 1
|
local word_index = matches[#matches] and (matches[#matches].word_match_end + 1) or 1
|
||||||
local input_match_start = -1
|
local input_match_start = -1
|
||||||
local input_match_end = -1
|
local input_match_end = -1
|
||||||
local word_match_start = -1
|
local word_match_start = -1
|
||||||
@@ -238,12 +237,26 @@ matcher.fuzzy = function(input, word, matches)
|
|||||||
input_index = input_index + 1
|
input_index = input_index + 1
|
||||||
strict_count = strict_count + (c1 == c2 and 1 or 0)
|
strict_count = strict_count + (c1 == c2 and 1 or 0)
|
||||||
match_count = match_count + 1
|
match_count = match_count + 1
|
||||||
elseif matched then
|
else
|
||||||
input_index = last_input_index
|
if option.disallow_fullfuzzy_matching then
|
||||||
input_match_end = input_index - 1
|
break
|
||||||
|
else
|
||||||
|
if matched then
|
||||||
|
table.insert(matches, {
|
||||||
|
input_match_start = input_match_start,
|
||||||
|
input_match_end = input_index - 1,
|
||||||
|
word_match_start = word_match_start,
|
||||||
|
word_match_end = word_index + word_offset - 1,
|
||||||
|
strict_ratio = strict_count / match_count,
|
||||||
|
fuzzy = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
matched = false
|
||||||
end
|
end
|
||||||
word_offset = word_offset + 1
|
word_offset = word_offset + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if input_index > #input then
|
if input_index > #input then
|
||||||
table.insert(matches, {
|
table.insert(matches, {
|
||||||
input_match_start = input_match_start,
|
input_match_start = input_match_start,
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ describe('matcher', function()
|
|||||||
assert.is.truthy(matcher.match('fmodify', 'fnamemodify', { disallow_fuzzy_matching = false }) >= 1)
|
assert.is.truthy(matcher.match('fmodify', 'fnamemodify', { disallow_fuzzy_matching = false }) >= 1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('disallow_fullfuzzy_matching', function()
|
||||||
|
assert.is.truthy(matcher.match('svd', 'saved_splitright', { disallow_fullfuzzy_matching = true }) == 0)
|
||||||
|
assert.is.truthy(matcher.match('svd', 'saved_splitright', { disallow_fullfuzzy_matching = false }) >= 1)
|
||||||
|
end)
|
||||||
|
|
||||||
it('disallow_partial_matching', function()
|
it('disallow_partial_matching', function()
|
||||||
assert.is.truthy(matcher.match('fb', 'foo_bar', { disallow_partial_matching = true }) == 0)
|
assert.is.truthy(matcher.match('fb', 'foo_bar', { disallow_partial_matching = true }) == 0)
|
||||||
assert.is.truthy(matcher.match('fb', 'foo_bar', { disallow_partial_matching = false }) >= 1)
|
assert.is.truthy(matcher.match('fb', 'foo_bar', { disallow_partial_matching = false }) >= 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user