logic: Fixed SearchMatch sorting not updated after rescoring

* also ignore template section in SearchMatch sorting
This commit is contained in:
Eberhard Graether
2017-02-09 23:54:21 +01:00
parent b423b41836
commit bfb997d35f
5 changed files with 53 additions and 22 deletions
@@ -1346,7 +1346,11 @@ void GraphController::layoutToGrid(DummyNode* node) const
if (lastAccessNode)
{
lastAccessNode->size.y = lastAccessNode->size.y + incY;
expandToggleNode->position.x = expandToggleNode->position.x + incX;
if (expandToggleNode)
{
expandToggleNode->position.x = expandToggleNode->position.x + incX;
}
node->size.x = width;
node->size.y = height;
+19 -17
View File
@@ -512,16 +512,14 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
size_t maxBestScoredResultsLength = 100;
// create SearchMatches
std::vector<SearchMatch> matches;
utility::append(matches, getAutocompletionSymbolMatches(query, maxResultsCount));
utility::append(matches, getAutocompletionFileMatches(query, 20));
utility::append(matches, getAutocompletionCommandMatches(query));
std::set<SearchMatch> matchesSet;
utility::append(matchesSet, getAutocompletionSymbolMatches(query, maxResultsCount));
utility::append(matchesSet, getAutocompletionFileMatches(query, 20));
utility::append(matchesSet, getAutocompletionCommandMatches(query));
std::vector<SearchMatch> matches = utility::toVector(matchesSet);
for (auto it = matches.begin(); it != matches.end(); it++)
for (SearchMatch& match : matches)
{
SearchMatch& match = *it;
// rescore match
if (!match.subtext.empty() && match.indices.size())
{
@@ -531,8 +529,12 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
match.score = newResult.score;
match.indices = newResult.indices;
}
matchesSet.insert(match);
}
matches = utility::toVector(matchesSet);
if (matches.size() > maxResultsCount)
{
matches.resize(maxResultsCount);
@@ -541,7 +543,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
return matches;
}
std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const
std::vector<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const
{
// search in indices
std::vector<SearchResult> results = m_symbolIndex.search(query, maxResultsCount, maxResultsCount);
@@ -569,7 +571,7 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const st
}
// create SearchMatches
std::set<SearchMatch> matches;
std::vector<SearchMatch> matches;
for (const SearchResult& result : results)
{
SearchMatch match;
@@ -614,18 +616,18 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const st
match.typeName = "non-indexed " + match.typeName;
}
matches.insert(match);
matches.push_back(match);
}
return matches;
}
std::set<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const
std::vector<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const
{
std::vector<SearchResult> results = m_fileIndex.search(query, maxResultsCount);
// create SearchMatches
std::set<SearchMatch> matches;
std::vector<SearchMatch> matches;
for (const SearchResult& result : results)
{
SearchMatch match;
@@ -646,19 +648,19 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const std:
match.searchType = SearchMatch::SEARCH_TOKEN;
matches.insert(match);
matches.push_back(match);
}
return matches;
}
std::set<SearchMatch> PersistentStorage::getAutocompletionCommandMatches(const std::string& query) const
std::vector<SearchMatch> PersistentStorage::getAutocompletionCommandMatches(const std::string& query) const
{
// search in indices
std::vector<SearchResult> results = m_commandIndex.search(query, 0);
// create SearchMatches
std::set<SearchMatch> matches;
std::vector<SearchMatch> matches;
for (const SearchResult& result : results)
{
SearchMatch match;
@@ -671,7 +673,7 @@ std::set<SearchMatch> PersistentStorage::getAutocompletionCommandMatches(const s
match.searchType = SearchMatch::SEARCH_COMMAND;
match.typeName = "command";
matches.insert(match);
matches.push_back(match);
}
return matches;
+3 -3
View File
@@ -87,9 +87,9 @@ public:
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
const std::string& searchTerm, bool caseSensitive) const;
virtual std::vector<SearchMatch> getAutocompletionMatches(const std::string& query) const;
std::set<SearchMatch> getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const;
std::set<SearchMatch> getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const;
std::set<SearchMatch> getAutocompletionCommandMatches(const std::string& query) const;
std::vector<SearchMatch> getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const;
std::vector<SearchMatch> getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const;
std::vector<SearchMatch> getAutocompletionCommandMatches(const std::string& query) const;
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& elementIds) const;
virtual std::shared_ptr<Graph> getGraphForAll() const;
+24 -1
View File
@@ -125,8 +125,19 @@ bool SearchMatch::operator<(const SearchMatch& other) const
otherStr = &other.name;
}
size_t size = getTextSizeForSorting(str);
size_t otherSize = other.getTextSizeForSorting(otherStr);
// text size
if (str->size() < otherStr->size())
if (size < otherSize)
{
return true;
}
else if (size > otherSize)
{
return false;
}
else if (str->size() < otherStr->size())
{
return true;
}
@@ -159,6 +170,18 @@ bool SearchMatch::operator<(const SearchMatch& other) const
return false;
}
size_t SearchMatch::getTextSizeForSorting(const std::string* str) const
{
// check if templated symbol and only use size up to template stuff
size_t pos = str->find('<');
if (pos != std::string::npos)
{
return pos;
}
return str->size();
}
bool SearchMatch::isValid() const
{
return searchType != SEARCH_NONE;
+2
View File
@@ -43,6 +43,8 @@ struct SearchMatch
bool operator<(const SearchMatch& other) const;
size_t getTextSizeForSorting(const std::string* str) const;
bool isValid() const;
void print(std::ostream& ostream) const;