@@ -2717,9 +2717,22 @@ 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+ //console.log(result.item?.type);
2730+ if ( containsTypeFromQuery ( result . item ?. type ?. inputs ) ) {
2731+ result . path_dist *= 100 ;
2732+ result . dist *= 100 ;
2733+ console . log ( result ) ;
2734+ }
2735+ }
27232736 result_list . push ( result ) ;
27242737 }
27252738
@@ -3540,6 +3553,28 @@ class DocSearch {
35403553 return false ;
35413554 }
35423555
3556+ /**
3557+ * This function checks if the given list contains any
3558+ * types mentioned in the query.
3559+ *
3560+ * @param {Array<FunctionType> } list - A list of function types.
3561+ * @param {[FunctionType] } where_clause - Trait bounds for generic items.
3562+ */
3563+ function containsTypeFromQuery ( list , where_clause ) {
3564+ if ( ! list ) return false ;
3565+ for ( const ty of parsedQuery . returned ) {
3566+ if ( checkIfInList ( list , ty , where_clause , null , 0 ) ) {
3567+ return true ;
3568+ }
3569+ }
3570+ for ( const ty of parsedQuery . elems ) {
3571+ if ( checkIfInList ( list , ty , where_clause , null , 0 ) ) {
3572+ return true ;
3573+ }
3574+ }
3575+ return false ;
3576+ }
3577+
35433578 /**
35443579 * This function checks if the object (`row`) matches the given type (`elem`) and its
35453580 * generics (if any).
0 commit comments