Fix fuzzy matching option check and matched position
This commit is contained in:
@@ -128,17 +128,12 @@ matcher.match = function(input, word, option)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if #matches == 0 then
|
if #matches == 0 then
|
||||||
matches = {
|
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
|
||||||
index = 1,
|
return 1, matches
|
||||||
input_match_start = 1,
|
end
|
||||||
input_match_end = 1,
|
end
|
||||||
word_match_start = 1,
|
return 0, {}
|
||||||
word_match_end = 1,
|
|
||||||
strict_ratio = 0,
|
|
||||||
fuzzy = false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
matcher.debug(word, matches)
|
matcher.debug(word, matches)
|
||||||
@@ -190,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) then
|
||||||
return score, matches
|
return score, matches
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -203,10 +198,9 @@ end
|
|||||||
|
|
||||||
--- fuzzy
|
--- fuzzy
|
||||||
matcher.fuzzy = function(input, word, matches)
|
matcher.fuzzy = function(input, word, matches)
|
||||||
local last_match = matches[#matches]
|
local input_index = matches[1] and (matches[1].input_match_end + 1) or 1
|
||||||
|
|
||||||
-- Lately specified middle of text.
|
-- Lately specified middle of text.
|
||||||
local input_index = last_match.input_match_end + 1
|
|
||||||
for i = 1, #matches - 1 do
|
for i = 1, #matches - 1 do
|
||||||
local curr_match = matches[i]
|
local curr_match = matches[i]
|
||||||
local next_match = matches[i + 1]
|
local next_match = matches[i + 1]
|
||||||
@@ -227,7 +221,7 @@ matcher.fuzzy = function(input, word, matches)
|
|||||||
local last_input_index = input_index
|
local last_input_index = input_index
|
||||||
local matched = false
|
local matched = false
|
||||||
local word_offset = 0
|
local word_offset = 0
|
||||||
local word_index = last_match.word_match_end + 1
|
local word_index = matches[1] and (matches[1].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
|
||||||
|
|||||||
@@ -37,12 +37,23 @@ describe('matcher', function()
|
|||||||
assert.is.truthy(matcher.match('Unit', 'net.UnixListener', { disallow_partial_fuzzy_matching = true }) == 0)
|
assert.is.truthy(matcher.match('Unit', 'net.UnixListener', { disallow_partial_fuzzy_matching = true }) == 0)
|
||||||
assert.is.truthy(matcher.match('Unit', 'net.UnixListener', { disallow_partial_fuzzy_matching = false }) >= 1)
|
assert.is.truthy(matcher.match('Unit', 'net.UnixListener', { disallow_partial_fuzzy_matching = false }) >= 1)
|
||||||
|
|
||||||
assert.is.truthy(matcher.match('tail', 'HCDetails', {
|
local score, matches
|
||||||
|
score, matches = matcher.match('tail', 'HCDetails', {
|
||||||
disallow_fuzzy_matching = false,
|
disallow_fuzzy_matching = false,
|
||||||
disallow_partial_matching = false,
|
disallow_partial_matching = false,
|
||||||
disallow_prefix_unmatching = false,
|
disallow_prefix_unmatching = false,
|
||||||
disallow_partial_fuzzy_matching = false,
|
disallow_partial_fuzzy_matching = false,
|
||||||
}) >= 1)
|
})
|
||||||
|
assert.is.truthy(score >= 1)
|
||||||
|
assert.equals(matches[1].word_match_start, 5)
|
||||||
|
|
||||||
|
score, matches = matcher.match('tail', 'HCDetails', {
|
||||||
|
disallow_fuzzy_matching = false,
|
||||||
|
disallow_partial_matching = false,
|
||||||
|
disallow_prefix_unmatching = false,
|
||||||
|
disallow_partial_fuzzy_matching = true,
|
||||||
|
})
|
||||||
|
assert.is.truthy(score == 0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('disallow_fuzzy_matching', function()
|
it('disallow_fuzzy_matching', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user