Skip to content

Commit 9900ea4

Browse files
committed
Adjust ranking so that duplicates count against rank
1 parent 12dc24f commit 9900ea4

6 files changed

Lines changed: 52 additions & 30 deletions

File tree

‎src/librustdoc/html/static/js/search.js‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,17 +1412,16 @@ class DocSearch {
14121412
* query fingerprint. If any bits are set in the query but not in the function, it can't
14131413
* match.
14141414
*
1415-
* - The fourth section has the number of distinct items in the set.
1415+
* - The fourth section has the number of items in the set.
14161416
* This is the distance function, used for filtering and for sorting.
14171417
*
14181418
* [^1]: Distance is the relatively naive metric of counting the number of distinct items in
14191419
* the function that are not present in the query.
14201420
*
14211421
* @param {FunctionType|QueryElement} type - a single type
14221422
* @param {Uint32Array} output - write the fingerprint to this data structure: uses 128 bits
1423-
* @param {Set<number>} fps - Set of distinct items
14241423
*/
1425-
buildFunctionTypeFingerprint(type,output,fps){
1424+
buildFunctionTypeFingerprint(type,output){
14261425
letinput=type.id;
14271426
// All forms of `[]`/`()`/`->` get collapsed down to one thing in the bloom filter.
14281427
// Differentiating between arrays and slices, if the user asks for it, is
@@ -1468,10 +1467,11 @@ class DocSearch {
14681467
output[0]|=(1<<(h0a%32))|(1<<(h1b%32));
14691468
output[1]|=(1<<(h1a%32))|(1<<(h2b%32));
14701469
output[2]|=(1<<(h2a%32))|(1<<(h0b%32));
1471-
fps.add(input);
1470+
// output[3] is the total number of items in the type signature
1471+
output[3]+=1;
14721472
}
14731473
for(constgoftype.generics){
1474-
this.buildFunctionTypeFingerprint(g,output,fps);
1474+
this.buildFunctionTypeFingerprint(g,output);
14751475
}
14761476
constfb={
14771477
id: null,
@@ -1482,9 +1482,8 @@ class DocSearch {
14821482
for(const[k,v]oftype.bindings.entries()){
14831483
fb.id=k;
14841484
fb.generics=v;
1485-
this.buildFunctionTypeFingerprint(fb,output,fps);
1485+
this.buildFunctionTypeFingerprint(fb,output);
14861486
}
1487-
output[3]=fps.size;
14881487
}
14891488

14901489
/**
@@ -1734,16 +1733,15 @@ class DocSearch {
17341733
if(type!==null){
17351734
if(type){
17361735
constfp=this.functionTypeFingerprint.subarray(id*4,(id+1)*4);
1737-
constfps=newSet();
17381736
for(consttoftype.inputs){
1739-
this.buildFunctionTypeFingerprint(t,fp,fps);
1737+
this.buildFunctionTypeFingerprint(t,fp);
17401738
}
17411739
for(consttoftype.output){
1742-
this.buildFunctionTypeFingerprint(t,fp,fps);
1740+
this.buildFunctionTypeFingerprint(t,fp);
17431741
}
17441742
for(constwoftype.where_clause){
17451743
for(consttofw){
1746-
this.buildFunctionTypeFingerprint(t,fp,fps);
1744+
this.buildFunctionTypeFingerprint(t,fp);
17471745
}
17481746
}
17491747
}
@@ -3885,14 +3883,13 @@ class DocSearch {
38853883
);
38863884
};
38873885

3888-
constfps=newSet();
38893886
for(constelemofparsedQuery.elems){
38903887
convertNameToId(elem);
3891-
this.buildFunctionTypeFingerprint(elem,parsedQuery.typeFingerprint,fps);
3888+
this.buildFunctionTypeFingerprint(elem,parsedQuery.typeFingerprint);
38923889
}
38933890
for(constelemofparsedQuery.returned){
38943891
convertNameToId(elem);
3895-
this.buildFunctionTypeFingerprint(elem,parsedQuery.typeFingerprint,fps);
3892+
this.buildFunctionTypeFingerprint(elem,parsedQuery.typeFingerprint);
38963893
}
38973894

38983895
if(parsedQuery.foundElems===1&&!parsedQuery.hasReturnArrow){

‎tests/rustdoc-js-std/simd-type-signatures.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ const EXPECTED = [
2020
'name': 'simd_min',
2121
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_min'
2222
},
23-
{
24-
'path': 'std::simd::prelude::Simd',
25-
'name': 'simd_clamp',
26-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_clamp'
27-
},
2823
{
2924
'path': 'std::simd::prelude::Simd',
3025
'name': 'saturating_add',
@@ -35,6 +30,11 @@ const EXPECTED = [
3530
'name': 'saturating_sub',
3631
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_sub'
3732
},
33+
{
34+
'path': 'std::simd::prelude::Simd',
35+
'name': 'simd_clamp',
36+
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_clamp'
37+
},
3838
],
3939
},
4040
{
@@ -50,11 +50,6 @@ const EXPECTED = [
5050
'name': 'simd_min',
5151
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_min'
5252
},
53-
{
54-
'path': 'std::simd::prelude::Simd',
55-
'name': 'simd_clamp',
56-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_clamp'
57-
},
5853
{
5954
'path': 'std::simd::prelude::Simd',
6055
'name': 'saturating_add',
@@ -65,6 +60,11 @@ const EXPECTED = [
6560
'name': 'saturating_sub',
6661
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_sub'
6762
},
63+
{
64+
'path': 'std::simd::prelude::Simd',
65+
'name': 'simd_clamp',
66+
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_clamp'
67+
},
6868
],
6969
},
7070
];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// should-fail
2+
constEXPECTED=[
3+
{
4+
// Keep this test case identical to `transmute`, except the
5+
// should-fail tag and the search query below:
6+
'query': 'generic:T -> generic:T',
7+
'others': [
8+
{'path': 'std::intrinsics::simd','name': 'simd_as'},
9+
{'path': 'std::intrinsics::simd','name': 'simd_cast'},
10+
{'path': 'std::intrinsics','name': 'transmute'},
11+
],
12+
},
13+
];

‎tests/rustdoc-js-std/transmute.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
constEXPECTED=[
2+
{
3+
// Keep this test case identical to `transmute-fail`, except the
4+
// should-fail tag and the search query below:
5+
'query': 'generic:T -> generic:U',
6+
'others': [
7+
{'path': 'std::intrinsics::simd','name': 'simd_as'},
8+
{'path': 'std::intrinsics::simd','name': 'simd_cast'},
9+
{'path': 'std::intrinsics','name': 'transmute'},
10+
],
11+
},
12+
];

‎tests/rustdoc-js/impl-trait.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const EXPECTED = [
2323
'others': [
2424
{'path': 'impl_trait','name': 'bbbbbbb'},
2525
{'path': 'impl_trait::Ccccccc','name': 'ddddddd'},
26-
{'path': 'impl_trait::Ccccccc','name': 'fffffff'},
2726
{'path': 'impl_trait::Ccccccc','name': 'ggggggg'},
27+
{'path': 'impl_trait::Ccccccc','name': 'fffffff'},
2828
],
2929
},
3030
{
@@ -39,14 +39,14 @@ const EXPECTED = [
3939
{'path': 'impl_trait','name': 'Aaaaaaa'},
4040
],
4141
'in_args': [
42-
{'path': 'impl_trait::Ccccccc','name': 'fffffff'},
4342
{'path': 'impl_trait::Ccccccc','name': 'eeeeeee'},
43+
{'path': 'impl_trait::Ccccccc','name': 'fffffff'},
4444
],
4545
'returned': [
4646
{'path': 'impl_trait','name': 'bbbbbbb'},
4747
{'path': 'impl_trait::Ccccccc','name': 'ddddddd'},
48-
{'path': 'impl_trait::Ccccccc','name': 'fffffff'},
4948
{'path': 'impl_trait::Ccccccc','name': 'ggggggg'},
49+
{'path': 'impl_trait::Ccccccc','name': 'fffffff'},
5050
],
5151
},
5252
];

‎tests/rustdoc-js/type-parameters.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const EXPECTED = [
1111
{
1212
query: '-> generic:T',
1313
others: [
14-
{path: 'foo',name: 'beta'},
1514
{path: 'foo',name: 'bet'},
1615
{path: 'foo',name: 'alef'},
16+
{path: 'foo',name: 'beta'},
1717
],
1818
},
1919
{
@@ -50,17 +50,17 @@ const EXPECTED = [
5050
{
5151
query: 'generic:T',
5252
in_args: [
53-
{path: 'foo',name: 'beta'},
5453
{path: 'foo',name: 'bet'},
54+
{path: 'foo',name: 'beta'},
5555
{path: 'foo',name: 'alternate'},
5656
{path: 'foo',name: 'other'},
5757
],
5858
},
5959
{
6060
query: 'generic:Other',
6161
in_args: [
62-
{path: 'foo',name: 'beta'},
6362
{path: 'foo',name: 'bet'},
63+
{path: 'foo',name: 'beta'},
6464
{path: 'foo',name: 'alternate'},
6565
{path: 'foo',name: 'other'},
6666
],

0 commit comments

Comments
 (0)