data: increased autocomplete performance by caching and limiting results to 100
This commit is contained in:
@@ -15,7 +15,7 @@ std::vector<SearchMatch> SearchIndex::getMatches(
|
||||
|
||||
for (SearchResultsIterator it = searchResults.begin(); it != searchResults.end(); it++)
|
||||
{
|
||||
SearchMatch match = it->node->fuzzyMatchData(query, it->parent);
|
||||
SearchMatch match = it->node->fuzzyMatchData(query, it->parent->getParent());
|
||||
result.push_back(match);
|
||||
}
|
||||
|
||||
@@ -171,6 +171,11 @@ SearchResults SearchIndex::runFuzzySearch(const std::string& query) const
|
||||
return m_root.runFuzzySearch(query);
|
||||
}
|
||||
|
||||
SearchResults SearchIndex::runFuzzySearchCached(const std::string& query, const SearchResults& searchResults) const
|
||||
{
|
||||
return m_root.runFuzzySearchCached(query, searchResults);
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> SearchIndex::runFuzzySearchAndGetMatches(const std::string& query) const
|
||||
{
|
||||
return getMatches(runFuzzySearch(query), query);
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
NameHierarchy getNameHierarchyForTokenId(Id tokenId) const;
|
||||
|
||||
SearchResults runFuzzySearch(const std::string& query) const;
|
||||
SearchResults runFuzzySearchCached(const std::string& query, const SearchResults& searchResults) const;
|
||||
std::vector<SearchMatch> runFuzzySearchAndGetMatches(const std::string& query) const;
|
||||
|
||||
static const std::string DELIMITER;
|
||||
|
||||
@@ -162,12 +162,32 @@ SearchResults SearchNode::runFuzzySearch(const std::string& query) const
|
||||
FuzzyMap m = n->fuzzyMatchRecursive(query, 0, 0, 0);
|
||||
for (const std::pair<size_t, const SearchNode*>& p : m)
|
||||
{
|
||||
addResultsRecursive(&result, p.first, p.second);
|
||||
addResultsRecursive(&result, p.first, p.second, n.get());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SearchResults SearchNode::runFuzzySearchCached(const std::string& query, const SearchResults& searchResults) const
|
||||
{
|
||||
SearchResults result;
|
||||
|
||||
std::set<const SearchNode*> nodes;
|
||||
for (const SearchResult& r : searchResults)
|
||||
{
|
||||
nodes.insert(r.parent);
|
||||
}
|
||||
|
||||
for (const SearchNode* n : nodes)
|
||||
{
|
||||
FuzzyMap m = n->fuzzyMatchRecursive(query, 0, 0, 0);
|
||||
for (const std::pair<size_t, const SearchNode*>& p : m)
|
||||
{
|
||||
addResultsRecursive(&result, p.first, p.second, n);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Currently all matches are added to the ordered set and get compared by their fullName for alphabetical
|
||||
// order. This could be improved by limiting the number of items to e.g. 100.
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -177,26 +197,20 @@ SearchResults SearchNode::runFuzzySearchOnSelf(const std::string& query) const
|
||||
FuzzyMap m = fuzzyMatchRecursive(query, 0, 0, 0);
|
||||
for (const std::pair<size_t, const SearchNode*>& p : m)
|
||||
{
|
||||
addResultsRecursive(&result, p.first, p.second);
|
||||
addResultsRecursive(&result, p.first, p.second, this);
|
||||
}
|
||||
|
||||
// TODO: Currently all matches are added to the ordered set and get compared by their fullName for alphabetical
|
||||
// order. This could be improved by limiting the number of items to e.g. 100.
|
||||
return result;
|
||||
}
|
||||
|
||||
void SearchNode::addResults(SearchResults* results, size_t weight, const SearchNode* node) const
|
||||
{
|
||||
results->insert(SearchResult(weight, node, this));
|
||||
}
|
||||
|
||||
void SearchNode::addResultsRecursive(SearchResults* results, size_t weight, const SearchNode* node) const
|
||||
{
|
||||
addResults(results, weight, node);
|
||||
void SearchNode::addResultsRecursive(
|
||||
SearchResults* results, size_t weight, const SearchNode* node, const SearchNode* parent
|
||||
) const {
|
||||
results->insert(SearchResult(weight, node, parent));
|
||||
|
||||
for (std::shared_ptr<SearchNode> n: node->m_nodes)
|
||||
{
|
||||
addResultsRecursive(results, weight, n.get());
|
||||
addResultsRecursive(results, weight, n.get(), parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ public:
|
||||
const std::set<std::shared_ptr<SearchNode>>& getChildren() const;
|
||||
|
||||
SearchResults runFuzzySearch(const std::string& query) const;
|
||||
SearchResults runFuzzySearchCached(const std::string& query, const SearchResults& searchResults) const;
|
||||
SearchResults runFuzzySearchOnSelf(const std::string& query) const;
|
||||
|
||||
void addResults(SearchResults* results, size_t weight, const SearchNode* node) const;
|
||||
void addResultsRecursive(SearchResults* results, size_t weight, const SearchNode* node) const;
|
||||
void addResultsRecursive(SearchResults* results, size_t weight, const SearchNode* node, const SearchNode* parent) const;
|
||||
|
||||
private:
|
||||
typedef std::multimap<size_t, const SearchNode*> FuzzyMap;
|
||||
|
||||
Reference in New Issue
Block a user