Raise maxWorkspaceSearchResults to 500 and sort results even if the max number has been reached

This commit is contained in:
Fangrui Song 2017-12-23 22:49:45 -08:00
parent b52ec9070c
commit cdcf75ac84
3 changed files with 40 additions and 27 deletions

View File

@ -24,7 +24,7 @@ struct Config {
bool logSkippedPathsForIndex = false;
// Maximum workspace search results.
int maxWorkspaceSearchResults = 200;
int maxWorkspaceSearchResults = 500;
// Force a certain number of indexer threads. If less than 1 a default value
// should be used.

View File

@ -104,7 +104,26 @@ struct NamespaceHelper {
std::string name = namespaces[i].get_spelling();
// Empty name indicates unnamed namespace, anonymous struct, anonymous
// union, ...
qualifier += name.empty() ? "(anon)" : name;
if (name.size())
qualifier += name;
else
switch (namespaces[i].get_kind()) {
case CXCursor_ClassDecl:
qualifier += "(anon class)";
break;
case CXCursor_EnumDecl:
qualifier += "(anon enum)";
break;
case CXCursor_StructDecl:
qualifier += "(anon struct)";
break;
case CXCursor_UnionDecl:
qualifier += "(anon union)";
break;
default:
qualifier += "(anon)";
break;
}
qualifier += "::";
container_cursor_to_qualified_name[namespaces[i]] = qualifier;
}

View File

@ -160,13 +160,10 @@ int FuzzyEvaluate(const std::string& pattern,
pfirst = pstart = false;
}
// Enumerate the end position of the match in str.
// Enumerate the end position of the match in str. Each removed trailing
// character has a penulty of kGapScore.
lefts = kMinScore;
for (int i = 0; i < int(str.size()); i++)
// For function types, db->detailed_names may have trailing characters for
// parameters. We do not want to penalize them.
// If we use `short_name` instead of `detailed_name` for fuzzy matching, the
// penulty kGapScore can be used.
lefts = std::max(lefts + kGapScore, dp[i]);
return lefts;
}
@ -227,27 +224,24 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
}
// Sort results with a fuzzy matching algorithm.
if (unsorted_results.size() < config->maxWorkspaceSearchResults) {
int longest = 0;
for (int i: result_indices)
longest = std::max(longest, int(db->short_names[i].size()));
int longest = 0;
for (int i: result_indices)
longest = std::max(longest, int(db->short_names[i].size()));
std::vector<int> score(longest), // score for each position
dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i]
std::vector<std::pair<int, int>> permutation(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++) {
permutation[i] = {
FuzzyEvaluate(query, db->short_names[result_indices[i]], score,
dp),
i};
}
std::sort(permutation.begin(), permutation.end(),
std::greater<std::pair<int, int>>());
out.result.reserve(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++)
out.result.push_back(std::move(unsorted_results[permutation[i].second]));
} else
out.result = std::move(unsorted_results);
std::vector<int> score(longest), // score for each position
dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i]
std::vector<std::pair<int, int>> permutation(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++) {
permutation[i] = {
FuzzyEvaluate(query, db->short_names[result_indices[i]], score,
dp),
i};
}
std::sort(permutation.begin(), permutation.end(),
std::greater<std::pair<int, int>>());
out.result.reserve(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++)
out.result.push_back(std::move(unsorted_results[permutation[i].second]));
LOG_S(INFO) << "[querydb] Found " << out.result.size()
<< " results for query " << query;