@@ -4273,7 +4273,11 @@ class DocSearch {
42734273 } ;
42744274 }
42754275
4276- // @ts -expect-error
4276+ /**
4277+ * Handle searching by doc aliases
4278+ *
4279+ * @type {function(rustdoc.ResultsTable, string, Object=, Object=): Promise<void> }
4280+ */
42774281 const handleAliases = async ( ret , query , filterCrates , currentCrate ) => {
42784282 const lowerQuery = query . toLowerCase ( ) ;
42794283 // We separate aliases and crate aliases because we want to have current crate
@@ -4328,6 +4332,16 @@ class DocSearch {
43284332 Promise . all ( aliases . map ( fetchDesc ) ) ,
43294333 ] ) ;
43304334
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+
43314345 // @ts -expect-error
43324346 const pushFunc = alias => {
43334347 alias . alias = query ;
@@ -4336,12 +4350,11 @@ class DocSearch {
43364350 alias . fullPath = alias . displayPath + alias . name ;
43374351 alias . href = res [ 1 ] ;
43384352
4339- ret . others . unshift ( alias ) ;
4353+ ret . others . splice ( exactMatches , 0 , alias ) ;
43404354 if ( ret . others . length > MAX_RESULTS ) {
43414355 ret . others . pop ( ) ;
43424356 }
43434357 } ;
4344-
43454358 aliases . forEach ( ( alias , i ) => {
43464359 // @ts -expect-error
43474360 alias . desc = descs [ i ] ;
0 commit comments