mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 13:48:04 +00:00
Simplify ComputeGuessScore
This commit is contained in:
parent
25094bc70d
commit
90329e5453
@ -152,6 +152,7 @@ TEST_SUITE("fuzzy_match") {
|
|||||||
Ranks("ab", {"ab", "aoo_boo", "acb"});
|
Ranks("ab", {"ab", "aoo_boo", "acb"});
|
||||||
Ranks("CC", {"CamelCase", "camelCase", "camelcase"});
|
Ranks("CC", {"CamelCase", "camelCase", "camelcase"});
|
||||||
Ranks("cC", {"camelCase", "CamelCase", "camelcase"});
|
Ranks("cC", {"camelCase", "CamelCase", "camelcase"});
|
||||||
|
Ranks("c c", {"camel case", "camelCase", "CamelCase", "camelcase", "camel ace"});
|
||||||
Ranks("Da.Te", {"Data.Text", "Data.Text.Lazy", "Data.Aeson.Encoding.text"});
|
Ranks("Da.Te", {"Data.Text", "Data.Text.Lazy", "Data.Aeson.Encoding.text"});
|
||||||
// prefix
|
// prefix
|
||||||
Ranks("is", {"isIEEE", "inSuf"});
|
Ranks("is", {"isIEEE", "inSuf"});
|
||||||
|
@ -496,37 +496,15 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
|
|||||||
// Computes a score based on how well |a| and |b| match. This is used for
|
// Computes a score based on how well |a| and |b| match. This is used for
|
||||||
// argument guessing.
|
// argument guessing.
|
||||||
int ComputeGuessScore(const std::string& a, const std::string& b) {
|
int ComputeGuessScore(const std::string& a, const std::string& b) {
|
||||||
const int kMatchPrefixWeight = 100;
|
// Increase score based on common prefix and suffix. Prefixes are prioritized.
|
||||||
const int kMismatchDirectoryWeight = 100;
|
size_t i = std::mismatch(a.begin(), a.end(), b.begin()).first - a.begin();
|
||||||
const int kMatchPostfixWeight = 1;
|
size_t j = std::mismatch(a.rbegin(), a.rend(), b.rbegin()).first - a.rbegin();
|
||||||
|
int score = 10 * i + j;
|
||||||
int score = 0;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
// Increase score based on matching prefix.
|
|
||||||
for (i = 0; i < a.size() && i < b.size(); ++i) {
|
|
||||||
if (a[i] != b[i])
|
|
||||||
break;
|
|
||||||
score += kMatchPrefixWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reduce score based on mismatched directory distance.
|
// Reduce score based on mismatched directory distance.
|
||||||
for (size_t j = i; j < a.size(); ++j) {
|
if (i + j < std::min(a.size(), b.size()))
|
||||||
if (a[j] == '/')
|
score -= 100 * (std::count(a.begin() + i, a.end() - j, '/') +
|
||||||
score -= kMismatchDirectoryWeight;
|
std::count(b.begin() + i, b.end() - j, '/'));
|
||||||
}
|
|
||||||
for (size_t j = i; j < b.size(); ++j) {
|
|
||||||
if (b[j] == '/')
|
|
||||||
score -= kMismatchDirectoryWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increase score based on common ending. Don't increase as much as matching
|
|
||||||
// prefix or directory distance.
|
|
||||||
for (size_t offset = 1; offset <= a.size() && offset <= b.size(); ++offset) {
|
|
||||||
if (a[a.size() - offset] != b[b.size() - offset])
|
|
||||||
break;
|
|
||||||
score += kMatchPostfixWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user