@@ -2717,9 +2717,22 @@ class DocSearch {
2717
2717
const normalizedUserQuery = parsedQuery . userQuery . toLowerCase ( ) ;
2718
2718
const isMixedCase = normalizedUserQuery !== userQuery ;
2719
2719
const result_list = [ ] ;
2720
+ const isReturnTypeQuery = parsedQuery . elems . length === 0 ||
2721
+ typeInfo == "returned" ;
2720
2722
for ( const result of results . values ( ) ) {
2721
2723
result . item = this . searchIndex [ result . id ] ;
2722
2724
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
+ }
2723
2736
result_list . push ( result ) ;
2724
2737
}
2725
2738
@@ -3540,6 +3553,28 @@ class DocSearch {
3540
3553
return false ;
3541
3554
}
3542
3555
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
+
3543
3578
/**
3544
3579
* This function checks if the object (`row`) matches the given type (`elem`) and its
3545
3580
* generics (if any).
0 commit comments