diff options
Diffstat (limited to 'clang-tools-extra/clangd/index/dex/Dex.cpp')
-rw-r--r-- | clang-tools-extra/clangd/index/dex/Dex.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp index 2c0c3d73877..3b236f8918a 100644 --- a/clang-tools-extra/clangd/index/dex/Dex.cpp +++ b/clang-tools-extra/clangd/index/dex/Dex.cpp @@ -56,7 +56,8 @@ std::vector<Token> generateSearchTokens(const Symbol &Sym) { std::vector<std::unique_ptr<Iterator>> createFileProximityIterators( llvm::ArrayRef<std::string> ProximityPaths, llvm::ArrayRef<std::string> URISchemes, - const llvm::DenseMap<Token, PostingList> &InvertedIndex) { + const llvm::DenseMap<Token, PostingList> &InvertedIndex, + const Corpus &Corpus) { std::vector<std::unique_ptr<Iterator>> BoostingIterators; // Deduplicate parent URIs extracted from the ProximityPaths. llvm::StringSet<> ParentURIs; @@ -91,8 +92,8 @@ std::vector<std::unique_ptr<Iterator>> createFileProximityIterators( if (It != InvertedIndex.end()) { // FIXME(kbobyrev): Append LIMIT on top of every BOOST iterator. PathProximitySignals.SymbolURI = ParentURI; - BoostingIterators.push_back(createBoost(It->second.iterator(&It->first), - PathProximitySignals.evaluate())); + BoostingIterators.push_back(Corpus.boost( + It->second.iterator(&It->first), PathProximitySignals.evaluate())); } } return BoostingIterators; @@ -101,6 +102,7 @@ std::vector<std::unique_ptr<Iterator>> createFileProximityIterators( } // namespace void Dex::buildIndex() { + this->Corpus = dex::Corpus(Symbols.size()); std::vector<std::pair<float, const Symbol *>> ScoredSymbols(Symbols.size()); for (size_t I = 0; I < Symbols.size(); ++I) { @@ -159,7 +161,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req, TrigramIterators.push_back(It->second.iterator(&It->first)); } if (!TrigramIterators.empty()) - TopLevelChildren.push_back(createAnd(move(TrigramIterators))); + TopLevelChildren.push_back(Corpus.intersect(move(TrigramIterators))); // Generate scope tokens for search query. std::vector<std::unique_ptr<Iterator>> ScopeIterators; @@ -170,22 +172,22 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req, ScopeIterators.push_back(It->second.iterator(&It->first)); } if (Req.AnyScope) - ScopeIterators.push_back(createBoost(createTrue(Symbols.size()), - ScopeIterators.empty() ? 1.0 : 0.2)); + ScopeIterators.push_back( + Corpus.boost(Corpus.all(), ScopeIterators.empty() ? 1.0 : 0.2)); // Add OR iterator for scopes if there are any Scope Iterators. if (!ScopeIterators.empty()) - TopLevelChildren.push_back(createOr(move(ScopeIterators))); + TopLevelChildren.push_back(Corpus.unionOf(move(ScopeIterators))); // Add proximity paths boosting. auto BoostingIterators = createFileProximityIterators( - Req.ProximityPaths, URISchemes, InvertedIndex); + Req.ProximityPaths, URISchemes, InvertedIndex, Corpus); // Boosting iterators do not actually filter symbols. In order to preserve // the validity of resulting query, TRUE iterator should be added along // BOOSTs. if (!BoostingIterators.empty()) { - BoostingIterators.push_back(createTrue(Symbols.size())); - TopLevelChildren.push_back(createOr(move(BoostingIterators))); + BoostingIterators.push_back(Corpus.all()); + TopLevelChildren.push_back(Corpus.unionOf(move(BoostingIterators))); } if (Req.RestrictForCodeCompletion) @@ -196,14 +198,14 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req, // Use TRUE iterator if both trigrams and scopes from the query are not // present in the symbol index. auto QueryIterator = TopLevelChildren.empty() - ? createTrue(Symbols.size()) - : createAnd(move(TopLevelChildren)); + ? Corpus.all() + : Corpus.intersect(move(TopLevelChildren)); // Retrieve more items than it was requested: some of the items with high // final score might not be retrieved otherwise. // FIXME(kbobyrev): Pre-scoring retrieval threshold should be adjusted as // using 100x of the requested number might not be good in practice, e.g. // when the requested number of items is small. - auto Root = Req.Limit ? createLimit(move(QueryIterator), *Req.Limit * 100) + auto Root = Req.Limit ? Corpus.limit(move(QueryIterator), *Req.Limit * 100) : move(QueryIterator); SPAN_ATTACH(Tracer, "query", llvm::to_string(*Root)); vlog("Dex query tree: {0}", *Root); |