for purely return-type based searches, deprioritize clone-like functions · rust-lang/rust@ebd5ce1 (original) (raw)
`@@ -2717,9 +2717,26 @@ 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
`+
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
`+
}
`
2723
2740
`result_list.push(result);
`
2724
2741
`}
`
2725
2742
``
`@@ -3540,6 +3557,35 @@ class DocSearch {
`
3540
3557
`return false;
`
3541
3558
`}
`
3542
3559
``
``
3560
`+
/**
`
``
3561
`+
- This function checks if the given list contains any
`
``
3562
`+
- (non-generic) types mentioned in the query.
`
``
3563
`+
`
``
3564
`+
- @param {Array} 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
+
3543
3589
`/**
`
3544
3590
`` * This function checks if the object (row
) matches the given type (elem
) and its
``
3545
3591
` * generics (if any).
`