RankedMatch: Do not compare word boundary match count on single word matches

As the computation of word boundary matches is separate from the
actual subsequence matching, we sometimes have candidate that match
as a single word while still having multiple word boundary matches.

For example, with query "expresins", candidate "expressionism's"
will match as single word ("expressins" is a subsequence of
"expressionism"), and will have two word boundaries match (it does
match the last "s", which is considered as a separate word).

This should not be taken into account when compared against
candidate "expresions", which should be considered a better
match.

Fixes #1925
This commit is contained in:
Maxime Coste 2018-03-15 23:20:03 +11:00
parent 1ede2b89bb
commit 08df409a53

View File

@ -180,7 +180,9 @@ bool RankedMatch::operator<(const RankedMatch& other) const
if (diff != Flags::None) if (diff != Flags::None)
return (int)(m_flags & diff) > (int)(other.m_flags & diff); return (int)(m_flags & diff) > (int)(other.m_flags & diff);
if (not (m_flags & Flags::Prefix) and // If we are SingleWord, FirstCharMatch will do the job, and we dont want to take
// other words boundaries into account.
if (not (m_flags & (Flags::Prefix | Flags::SingleWord)) and
m_word_boundary_match_count != other.m_word_boundary_match_count) m_word_boundary_match_count != other.m_word_boundary_match_count)
return m_word_boundary_match_count > other.m_word_boundary_match_count; return m_word_boundary_match_count > other.m_word_boundary_match_count;
@ -241,6 +243,7 @@ UnitTest test_ranked_match{[] {
kak_assert(RankedMatch{"class", "cla"} < RankedMatch{"class::attr", "cla"}); kak_assert(RankedMatch{"class", "cla"} < RankedMatch{"class::attr", "cla"});
kak_assert(RankedMatch{"meta/", "meta"} < RankedMatch{"meta-a/", "meta"}); kak_assert(RankedMatch{"meta/", "meta"} < RankedMatch{"meta-a/", "meta"});
kak_assert(RankedMatch{"find(1p)", "find"} < RankedMatch{"findfs(8)", "find"}); kak_assert(RankedMatch{"find(1p)", "find"} < RankedMatch{"findfs(8)", "find"});
kak_assert(RankedMatch{"expresions", "expresins"} < RankedMatch{"expressionism's", "expresins"});
}}; }};
UnitTest test_used_letters{[]() UnitTest test_used_letters{[]()