@@ -149,17 +149,14 @@ private bool ActuallyLoading()
149
149
// _always_ show up first.
150
150
private int ScoreTopLevelItem ( string query , IListItem topLevelOrAppItem )
151
151
{
152
- if ( string . IsNullOrWhiteSpace ( query ) )
153
- {
154
- return 1 ;
155
- }
156
-
157
152
var title = topLevelOrAppItem . Title ;
158
- if ( string . IsNullOrEmpty ( title ) )
153
+ if ( string . IsNullOrWhiteSpace ( title ) )
159
154
{
160
155
return 0 ;
161
156
}
162
157
158
+ var isWhiteSpace = string . IsNullOrWhiteSpace ( query ) ;
159
+
163
160
var isFallback = false ;
164
161
var isAliasSubstringMatch = false ;
165
162
var isAliasMatch = false ;
@@ -179,17 +176,45 @@ private int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem)
179
176
extensionDisplayName = topLevel . ExtensionHost ? . Extension ? . PackageDisplayName ?? string . Empty ;
180
177
}
181
178
182
- var nameMatch = StringMatcher . FuzzySearch ( query , title ) ;
183
- var descriptionMatch = StringMatcher . FuzzySearch ( query , topLevelOrAppItem . Subtitle ) ;
184
- var extensionTitleMatch = StringMatcher . FuzzySearch ( query , extensionDisplayName ) ;
179
+ // StringMatcher.FuzzySearch will absolutely BEEF IT if you give it a
180
+ // whitespace-only query.
181
+ //
182
+ // in that scenario, we'll just use a simple string contains for the
183
+ // query. Maybe someone is really looking for things with a space in
184
+ // them, I don't know.
185
+
186
+ // Title:
187
+ // * whitespace query: 1 point
188
+ // * otherwise full weight match
189
+ var nameMatch = isWhiteSpace ?
190
+ ( title . Contains ( query ) ? 1 : 0 ) :
191
+ StringMatcher . FuzzySearch ( query , title ) . Score ;
192
+
193
+ // Subtitle:
194
+ // * whitespace query: 1/2 point
195
+ // * otherwise ~half weight match. Minus a bit, because subtitles tend to be longer
196
+ var descriptionMatch = isWhiteSpace ?
197
+ ( topLevelOrAppItem . Subtitle . Contains ( query ) ? .5 : 0 ) :
198
+ ( StringMatcher . FuzzySearch ( query , topLevelOrAppItem . Subtitle ) . Score - 4 ) / 2.0 ;
199
+
200
+ // Extension title: despite not being visible, give the extension name itself some weight
201
+ // * whitespace query: 0 points
202
+ // * otherwise more weight than a subtitle, but not much
203
+ var extensionTitleMatch = isWhiteSpace ? 0 : StringMatcher . FuzzySearch ( query , extensionDisplayName ) . Score / 1.5 ;
204
+
185
205
var scores = new [ ]
186
206
{
187
- nameMatch . Score ,
188
- ( descriptionMatch . Score - 4 ) / 2.0 ,
207
+ nameMatch ,
208
+ descriptionMatch ,
189
209
isFallback ? 1 : 0 , // Always give fallbacks a chance...
190
210
} ;
191
211
var max = scores . Max ( ) ;
192
- max = max + ( extensionTitleMatch . Score / 1.5 ) ;
212
+
213
+ // _Add_ the extension name. This will bubble items that match both
214
+ // title and extension name up above ones that just match title.
215
+ // e.g. "git" will up-weight "GitHub searches" from the GitHub extension
216
+ // above "git" from "whatever"
217
+ max = max + extensionTitleMatch ;
193
218
194
219
// ... but downweight them
195
220
var matchSomething = ( max / ( isFallback ? 3 : 1 ) )
0 commit comments