@@ -4273,7 +4273,11 @@ class DocSearch {
4273
4273
} ;
4274
4274
}
4275
4275
4276
- // @ts -expect-error
4276
+ /**
4277
+ * Handle searching by doc aliases
4278
+ *
4279
+ * @type {function(rustdoc.ResultsTable, string, Object=, Object=): Promise<void> }
4280
+ */
4277
4281
const handleAliases = async ( ret , query , filterCrates , currentCrate ) => {
4278
4282
const lowerQuery = query . toLowerCase ( ) ;
4279
4283
// We separate aliases and crate aliases because we want to have current crate
@@ -4328,6 +4332,16 @@ class DocSearch {
4328
4332
Promise . all ( aliases . map ( fetchDesc ) ) ,
4329
4333
] ) ;
4330
4334
4335
+ // if there are any existing results that match exactly, those go before aliases.
4336
+ let exactMatches = 0 ;
4337
+ while (
4338
+ ret . others [ exactMatches ] !== undefined &&
4339
+ ret . others [ exactMatches ] . dist === 0 &&
4340
+ ret . others [ exactMatches ] . path_dist === 0
4341
+ ) {
4342
+ exactMatches += 1 ;
4343
+ }
4344
+
4331
4345
// @ts -expect-error
4332
4346
const pushFunc = alias => {
4333
4347
alias . alias = query ;
@@ -4336,12 +4350,11 @@ class DocSearch {
4336
4350
alias . fullPath = alias . displayPath + alias . name ;
4337
4351
alias . href = res [ 1 ] ;
4338
4352
4339
- ret . others . unshift ( alias ) ;
4353
+ ret . others . splice ( exactMatches , 0 , alias ) ;
4340
4354
if ( ret . others . length > MAX_RESULTS ) {
4341
4355
ret . others . pop ( ) ;
4342
4356
}
4343
4357
} ;
4344
-
4345
4358
aliases . forEach ( ( alias , i ) => {
4346
4359
// @ts -expect-error
4347
4360
alias . desc = descs [ i ] ;
0 commit comments