@@ -42,7 +42,6 @@ const Token RestrictedForCodeCompletion =
42
42
// Returns the tokens which are given symbols's characteristics. For example,
43
43
// trigrams and scopes.
44
44
// FIXME(kbobyrev): Support more token types:
45
- // * Types
46
45
// * Namespace proximity
47
46
std::vector<Token> generateSearchTokens (const Symbol &Sym) {
48
47
std::vector<Token> Result = generateIdentifierTrigrams (Sym.Name );
@@ -54,49 +53,11 @@ std::vector<Token> generateSearchTokens(const Symbol &Sym) {
54
53
Result.emplace_back (Token::Kind::ProximityURI, ProximityURI);
55
54
if (Sym.Flags & Symbol::IndexedForCodeCompletion)
56
55
Result.emplace_back (RestrictedForCodeCompletion);
56
+ if (!Sym.Type .empty ())
57
+ Result.emplace_back (Token::Kind::Type, Sym.Type );
57
58
return Result;
58
59
}
59
60
60
- // Constructs BOOST iterators for Path Proximities.
61
- std::unique_ptr<Iterator> createFileProximityIterator (
62
- llvm::ArrayRef<std::string> ProximityPaths,
63
- const llvm::DenseMap<Token, PostingList> &InvertedIndex,
64
- const Corpus &Corpus) {
65
- std::vector<std::unique_ptr<Iterator>> BoostingIterators;
66
- // Deduplicate parent URIs extracted from the ProximityPaths.
67
- llvm::StringSet<> ParentURIs;
68
- llvm::StringMap<SourceParams> Sources;
69
- for (const auto &Path : ProximityPaths) {
70
- Sources[Path] = SourceParams ();
71
- auto PathURI = URI::create (Path);
72
- const auto PathProximityURIs = generateProximityURIs (PathURI.toString ());
73
- for (const auto &ProximityURI : PathProximityURIs)
74
- ParentURIs.insert (ProximityURI);
75
- }
76
- // Use SymbolRelevanceSignals for symbol relevance evaluation: use defaults
77
- // for all parameters except for Proximity Path distance signal.
78
- SymbolRelevanceSignals PathProximitySignals;
79
- // DistanceCalculator will find the shortest distance from ProximityPaths to
80
- // any URI extracted from the ProximityPaths.
81
- URIDistance DistanceCalculator (Sources);
82
- PathProximitySignals.FileProximityMatch = &DistanceCalculator;
83
- // Try to build BOOST iterator for each Proximity Path provided by
84
- // ProximityPaths. Boosting factor should depend on the distance to the
85
- // Proximity Path: the closer processed path is, the higher boosting factor.
86
- for (const auto &ParentURI : ParentURIs.keys ()) {
87
- Token Tok (Token::Kind::ProximityURI, ParentURI);
88
- const auto It = InvertedIndex.find (Tok);
89
- if (It != InvertedIndex.end ()) {
90
- // FIXME(kbobyrev): Append LIMIT on top of every BOOST iterator.
91
- PathProximitySignals.SymbolURI = ParentURI;
92
- BoostingIterators.push_back (Corpus.boost (
93
- It->second .iterator (&It->first ), PathProximitySignals.evaluate ()));
94
- }
95
- }
96
- BoostingIterators.push_back (Corpus.all ());
97
- return Corpus.unionOf (std::move (BoostingIterators));
98
- }
99
-
100
61
} // namespace
101
62
102
63
void Dex::buildIndex () {
@@ -141,6 +102,57 @@ std::unique_ptr<Iterator> Dex::iterator(const Token &Tok) const {
141
102
: It->second .iterator (&It->first );
142
103
}
143
104
105
+ // Constructs BOOST iterators for Path Proximities.
106
+ std::unique_ptr<Iterator> Dex::createFileProximityIterator (
107
+ llvm::ArrayRef<std::string> ProximityPaths) const {
108
+ std::vector<std::unique_ptr<Iterator>> BoostingIterators;
109
+ // Deduplicate parent URIs extracted from the ProximityPaths.
110
+ llvm::StringSet<> ParentURIs;
111
+ llvm::StringMap<SourceParams> Sources;
112
+ for (const auto &Path : ProximityPaths) {
113
+ Sources[Path] = SourceParams ();
114
+ auto PathURI = URI::create (Path);
115
+ const auto PathProximityURIs = generateProximityURIs (PathURI.toString ());
116
+ for (const auto &ProximityURI : PathProximityURIs)
117
+ ParentURIs.insert (ProximityURI);
118
+ }
119
+ // Use SymbolRelevanceSignals for symbol relevance evaluation: use defaults
120
+ // for all parameters except for Proximity Path distance signal.
121
+ SymbolRelevanceSignals PathProximitySignals;
122
+ // DistanceCalculator will find the shortest distance from ProximityPaths to
123
+ // any URI extracted from the ProximityPaths.
124
+ URIDistance DistanceCalculator (Sources);
125
+ PathProximitySignals.FileProximityMatch = &DistanceCalculator;
126
+ // Try to build BOOST iterator for each Proximity Path provided by
127
+ // ProximityPaths. Boosting factor should depend on the distance to the
128
+ // Proximity Path: the closer processed path is, the higher boosting factor.
129
+ for (const auto &ParentURI : ParentURIs.keys ()) {
130
+ // FIXME(kbobyrev): Append LIMIT on top of every BOOST iterator.
131
+ auto It = iterator (Token (Token::Kind::ProximityURI, ParentURI));
132
+ if (It->kind () != Iterator::Kind::False) {
133
+ PathProximitySignals.SymbolURI = ParentURI;
134
+ BoostingIterators.push_back (
135
+ Corpus.boost (std::move (It), PathProximitySignals.evaluate ()));
136
+ }
137
+ }
138
+ BoostingIterators.push_back (Corpus.all ());
139
+ return Corpus.unionOf (std::move (BoostingIterators));
140
+ }
141
+
142
+ // Constructs BOOST iterators for preferred types.
143
+ std::unique_ptr<Iterator>
144
+ Dex::createTypeBoostingIterator (llvm::ArrayRef<std::string> Types) const {
145
+ std::vector<std::unique_ptr<Iterator>> BoostingIterators;
146
+ SymbolRelevanceSignals PreferredTypeSignals;
147
+ PreferredTypeSignals.TypeMatchesPreferred = true ;
148
+ auto Boost = PreferredTypeSignals.evaluate ();
149
+ for (const auto &T : Types)
150
+ BoostingIterators.push_back (
151
+ Corpus.boost (iterator (Token (Token::Kind::Type, T)), Boost));
152
+ BoostingIterators.push_back (Corpus.all ());
153
+ return Corpus.unionOf (std::move (BoostingIterators));
154
+ }
155
+
144
156
// / Constructs iterators over tokens extracted from the query and exhausts it
145
157
// / while applying Callback to each symbol in the order of decreasing quality
146
158
// / of the matched symbols.
@@ -174,8 +186,9 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
174
186
Criteria.push_back (Corpus.unionOf (move (ScopeIterators)));
175
187
176
188
// Add proximity paths boosting (all symbols, some boosted).
177
- Criteria.push_back (
178
- createFileProximityIterator (Req.ProximityPaths , InvertedIndex, Corpus));
189
+ Criteria.push_back (createFileProximityIterator (Req.ProximityPaths ));
190
+ // Add boosting for preferred types.
191
+ Criteria.push_back (createTypeBoostingIterator (Req.PreferredTypes ));
179
192
180
193
if (Req.RestrictForCodeCompletion )
181
194
Criteria.push_back (iterator (RestrictedForCodeCompletion));
0 commit comments