From bfb997d35fcecb14bc152eea90a3064618596d98 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Thu, 9 Feb 2017 23:54:21 +0100 Subject: [PATCH] logic: Fixed SearchMatch sorting not updated after rescoring * also ignore template section in SearchMatch sorting --- .../component/controller/GraphController.cpp | 6 +++- src/lib/data/PersistentStorage.cpp | 36 ++++++++++--------- src/lib/data/PersistentStorage.h | 6 ++-- src/lib/data/search/SearchMatch.cpp | 25 ++++++++++++- src/lib/data/search/SearchMatch.h | 2 ++ 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 82d023f2..fe057169 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -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; diff --git a/src/lib/data/PersistentStorage.cpp b/src/lib/data/PersistentStorage.cpp index 3974e368..a0f318ef 100644 --- a/src/lib/data/PersistentStorage.cpp +++ b/src/lib/data/PersistentStorage.cpp @@ -512,16 +512,14 @@ std::vector PersistentStorage::getAutocompletionMatches(const std:: size_t maxBestScoredResultsLength = 100; // create SearchMatches + std::vector matches; + utility::append(matches, getAutocompletionSymbolMatches(query, maxResultsCount)); + utility::append(matches, getAutocompletionFileMatches(query, 20)); + utility::append(matches, getAutocompletionCommandMatches(query)); + std::set matchesSet; - utility::append(matchesSet, getAutocompletionSymbolMatches(query, maxResultsCount)); - utility::append(matchesSet, getAutocompletionFileMatches(query, 20)); - utility::append(matchesSet, getAutocompletionCommandMatches(query)); - - std::vector 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 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 PersistentStorage::getAutocompletionMatches(const std:: return matches; } -std::set PersistentStorage::getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const +std::vector PersistentStorage::getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const { // search in indices std::vector results = m_symbolIndex.search(query, maxResultsCount, maxResultsCount); @@ -569,7 +571,7 @@ std::set PersistentStorage::getAutocompletionSymbolMatches(const st } // create SearchMatches - std::set matches; + std::vector matches; for (const SearchResult& result : results) { SearchMatch match; @@ -614,18 +616,18 @@ std::set PersistentStorage::getAutocompletionSymbolMatches(const st match.typeName = "non-indexed " + match.typeName; } - matches.insert(match); + matches.push_back(match); } return matches; } -std::set PersistentStorage::getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const +std::vector PersistentStorage::getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const { std::vector results = m_fileIndex.search(query, maxResultsCount); // create SearchMatches - std::set matches; + std::vector matches; for (const SearchResult& result : results) { SearchMatch match; @@ -646,19 +648,19 @@ std::set PersistentStorage::getAutocompletionFileMatches(const std: match.searchType = SearchMatch::SEARCH_TOKEN; - matches.insert(match); + matches.push_back(match); } return matches; } -std::set PersistentStorage::getAutocompletionCommandMatches(const std::string& query) const +std::vector PersistentStorage::getAutocompletionCommandMatches(const std::string& query) const { // search in indices std::vector results = m_commandIndex.search(query, 0); // create SearchMatches - std::set matches; + std::vector matches; for (const SearchResult& result : results) { SearchMatch match; @@ -671,7 +673,7 @@ std::set PersistentStorage::getAutocompletionCommandMatches(const s match.searchType = SearchMatch::SEARCH_COMMAND; match.typeName = "command"; - matches.insert(match); + matches.push_back(match); } return matches; diff --git a/src/lib/data/PersistentStorage.h b/src/lib/data/PersistentStorage.h index c3c3caba..13040d4b 100644 --- a/src/lib/data/PersistentStorage.h +++ b/src/lib/data/PersistentStorage.h @@ -87,9 +87,9 @@ public: virtual std::shared_ptr getFullTextSearchLocations( const std::string& searchTerm, bool caseSensitive) const; virtual std::vector getAutocompletionMatches(const std::string& query) const; - std::set getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const; - std::set getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const; - std::set getAutocompletionCommandMatches(const std::string& query) const; + std::vector getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const; + std::vector getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const; + std::vector getAutocompletionCommandMatches(const std::string& query) const; virtual std::vector getSearchMatchesForTokenIds(const std::vector& elementIds) const; virtual std::shared_ptr getGraphForAll() const; diff --git a/src/lib/data/search/SearchMatch.cpp b/src/lib/data/search/SearchMatch.cpp index 374abe7f..8bded0b4 100644 --- a/src/lib/data/search/SearchMatch.cpp +++ b/src/lib/data/search/SearchMatch.cpp @@ -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; diff --git a/src/lib/data/search/SearchMatch.h b/src/lib/data/search/SearchMatch.h index 532de8d3..587d1672 100644 --- a/src/lib/data/search/SearchMatch.h +++ b/src/lib/data/search/SearchMatch.h @@ -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;