From c13cac79a0410a893a54b91c9d9cd5720973700b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 10 Apr 2018 13:09:59 +0200 Subject: [PATCH] logic: Score children with same score as parent lower in search results --- src/lib/data/storage/PersistentStorage.cpp | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index 30b5525e..243bc7fb 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -602,7 +602,8 @@ std::vector PersistentStorage::getAutocompletionMatches(const std:: utility::append(matches, getAutocompletionCommandMatches(query, acceptedNodeTypes)); - std::set matchesSet; + // Rescore search matches to check if better score is achieved with higher indices + std::map matchesMap; for (SearchMatch& match : matches) { // rescore match @@ -615,12 +616,37 @@ std::vector PersistentStorage::getAutocompletionMatches(const std:: match.indices = newResult.indices; } + matchesMap.emplace(match.name, match); + } + + // Score child symbol matches with same score as parent lower + SearchMatch lastMatch; + std::set matchesSet; + for (const auto& p : matchesMap) + { + SearchMatch match = p.second; + if (!lastMatch.name.size() || !utility::isPrefix(lastMatch.name, match.name)) + { + lastMatch = match; + } + else if (lastMatch.score == match.score) + { + if (utility::isPrefix(nameDelimiterTypeToString(match.delimiter), match.name.substr(lastMatch.name.size()))) + { + match.score -= 10; + } + else + { + lastMatch = match; + } + } + matchesSet.insert(match); } // for (auto a : matchesSet) // { - // std::cout << a.score << " " << a.name << std::endl; + // std::wcout << a.score << " " << a.name << std::endl; // } return utility::toVector(matchesSet);