@@ -2717,9 +2717,26 @@ class DocSearch {
27172717 const normalizedUserQuery = parsedQuery . userQuery . toLowerCase ( ) ;
27182718 const isMixedCase = normalizedUserQuery !== userQuery ;
27192719 const result_list = [ ] ;
2720+ const isReturnTypeQuery = parsedQuery . elems . length === 0 ||
2721+ typeInfo === "returned" ;
27202722 for ( const result of results . values ( ) ) {
27212723 result . item = this . searchIndex [ result . id ] ;
27222724 result . word = this . searchIndex [ result . id ] . word ;
2725+ if ( isReturnTypeQuery ) {
2726+ // we are doing a return-type based search,
2727+ // deprioritize "clone-like" results,
2728+ // ie. functions that also take the queried type as an argument.
2729+ const hasType = result . item && result . item . type ;
2730+ if ( ! hasType ) {
2731+ continue ;
2732+ }
2733+ const inputs = result . item . type . inputs ;
2734+ const where_clause = result . item . type . where_clause ;
2735+ if ( containsTypeFromQuery ( inputs , where_clause ) ) {
2736+ result . path_dist *= 100 ;
2737+ result . dist *= 100 ;
2738+ }
2739+ }
27232740 result_list . push ( result ) ;
27242741 }
27252742
@@ -3540,6 +3557,35 @@ class DocSearch {
35403557 return false ;
35413558 }
35423559
3560+ /**
3561+ * This function checks if the given list contains any
3562+ * (non-generic) types mentioned in the query.
3563+ *
3564+ * @param {Array<FunctionType> } list - A list of function types.
3565+ * @param {[FunctionType] } where_clause - Trait bounds for generic items.
3566+ */
3567+ function containsTypeFromQuery ( list , where_clause ) {
3568+ if ( ! list ) return false ;
3569+ for ( const ty of parsedQuery . returned ) {
3570+ // negative type ids are generics
3571+ if ( ty . id < 0 ) {
3572+ continue ;
3573+ }
3574+ if ( checkIfInList ( list , ty , where_clause , null , 0 ) ) {
3575+ return true ;
3576+ }
3577+ }
3578+ for ( const ty of parsedQuery . elems ) {
3579+ if ( ty . id < 0 ) {
3580+ continue ;
3581+ }
3582+ if ( checkIfInList ( list , ty , where_clause , null , 0 ) ) {
3583+ return true ;
3584+ }
3585+ }
3586+ return false ;
3587+ }
3588+
35433589 /**
35443590 * This function checks if the object (`row`) matches the given type (`elem`) and its
35453591 * generics (if any).
0 commit comments