Adjust ranking so that duplicates count against rank

This commit is contained in:
Michael Howell 2024-10-31 13:09:37 -07:00
parent 12dc24f460
commit 9900ea48b5
6 changed files with 52 additions and 30 deletions

View File

@ -1412,7 +1412,7 @@ class DocSearch {
* query fingerprint. If any bits are set in the query but not in the function, it can't * query fingerprint. If any bits are set in the query but not in the function, it can't
* match. * match.
* *
* - The fourth section has the number of distinct items in the set. * - The fourth section has the number of items in the set.
* This is the distance function, used for filtering and for sorting. * This is the distance function, used for filtering and for sorting.
* *
* [^1]: Distance is the relatively naive metric of counting the number of distinct items in * [^1]: Distance is the relatively naive metric of counting the number of distinct items in
@ -1420,9 +1420,8 @@ class DocSearch {
* *
* @param {FunctionType|QueryElement} type - a single type * @param {FunctionType|QueryElement} type - a single type
* @param {Uint32Array} output - write the fingerprint to this data structure: uses 128 bits * @param {Uint32Array} output - write the fingerprint to this data structure: uses 128 bits
* @param {Set<number>} fps - Set of distinct items
*/ */
buildFunctionTypeFingerprint(type, output, fps) { buildFunctionTypeFingerprint(type, output) {
let input = type.id; let input = type.id;
// All forms of `[]`/`()`/`->` get collapsed down to one thing in the bloom filter. // All forms of `[]`/`()`/`->` get collapsed down to one thing in the bloom filter.
// Differentiating between arrays and slices, if the user asks for it, is // Differentiating between arrays and slices, if the user asks for it, is
@ -1468,10 +1467,11 @@ class DocSearch {
output[0] |= (1 << (h0a % 32)) | (1 << (h1b % 32)); output[0] |= (1 << (h0a % 32)) | (1 << (h1b % 32));
output[1] |= (1 << (h1a % 32)) | (1 << (h2b % 32)); output[1] |= (1 << (h1a % 32)) | (1 << (h2b % 32));
output[2] |= (1 << (h2a % 32)) | (1 << (h0b % 32)); output[2] |= (1 << (h2a % 32)) | (1 << (h0b % 32));
fps.add(input); // output[3] is the total number of items in the type signature
output[3] += 1;
} }
for (const g of type.generics) { for (const g of type.generics) {
this.buildFunctionTypeFingerprint(g, output, fps); this.buildFunctionTypeFingerprint(g, output);
} }
const fb = { const fb = {
id: null, id: null,
@ -1482,9 +1482,8 @@ class DocSearch {
for (const [k, v] of type.bindings.entries()) { for (const [k, v] of type.bindings.entries()) {
fb.id = k; fb.id = k;
fb.generics = v; fb.generics = v;
this.buildFunctionTypeFingerprint(fb, output, fps); this.buildFunctionTypeFingerprint(fb, output);
} }
output[3] = fps.size;
} }
/** /**
@ -1734,16 +1733,15 @@ class DocSearch {
if (type !== null) { if (type !== null) {
if (type) { if (type) {
const fp = this.functionTypeFingerprint.subarray(id * 4, (id + 1) * 4); const fp = this.functionTypeFingerprint.subarray(id * 4, (id + 1) * 4);
const fps = new Set();
for (const t of type.inputs) { for (const t of type.inputs) {
this.buildFunctionTypeFingerprint(t, fp, fps); this.buildFunctionTypeFingerprint(t, fp);
} }
for (const t of type.output) { for (const t of type.output) {
this.buildFunctionTypeFingerprint(t, fp, fps); this.buildFunctionTypeFingerprint(t, fp);
} }
for (const w of type.where_clause) { for (const w of type.where_clause) {
for (const t of w) { for (const t of w) {
this.buildFunctionTypeFingerprint(t, fp, fps); this.buildFunctionTypeFingerprint(t, fp);
} }
} }
} }
@ -3885,14 +3883,13 @@ class DocSearch {
); );
}; };
const fps = new Set();
for (const elem of parsedQuery.elems) { for (const elem of parsedQuery.elems) {
convertNameToId(elem); convertNameToId(elem);
this.buildFunctionTypeFingerprint(elem, parsedQuery.typeFingerprint, fps); this.buildFunctionTypeFingerprint(elem, parsedQuery.typeFingerprint);
} }
for (const elem of parsedQuery.returned) { for (const elem of parsedQuery.returned) {
convertNameToId(elem); convertNameToId(elem);
this.buildFunctionTypeFingerprint(elem, parsedQuery.typeFingerprint, fps); this.buildFunctionTypeFingerprint(elem, parsedQuery.typeFingerprint);
} }
if (parsedQuery.foundElems === 1 && !parsedQuery.hasReturnArrow) { if (parsedQuery.foundElems === 1 && !parsedQuery.hasReturnArrow) {

View File

@ -20,11 +20,6 @@ const EXPECTED = [
'name': 'simd_min', 'name': 'simd_min',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_min' 'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_min'
}, },
{
'path': 'std::simd::prelude::Simd',
'name': 'simd_clamp',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_clamp'
},
{ {
'path': 'std::simd::prelude::Simd', 'path': 'std::simd::prelude::Simd',
'name': 'saturating_add', 'name': 'saturating_add',
@ -35,6 +30,11 @@ const EXPECTED = [
'name': 'saturating_sub', 'name': 'saturating_sub',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_sub' 'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_sub'
}, },
{
'path': 'std::simd::prelude::Simd',
'name': 'simd_clamp',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_clamp'
},
], ],
}, },
{ {
@ -50,11 +50,6 @@ const EXPECTED = [
'name': 'simd_min', 'name': 'simd_min',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_min' 'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_min'
}, },
{
'path': 'std::simd::prelude::Simd',
'name': 'simd_clamp',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_clamp'
},
{ {
'path': 'std::simd::prelude::Simd', 'path': 'std::simd::prelude::Simd',
'name': 'saturating_add', 'name': 'saturating_add',
@ -65,6 +60,11 @@ const EXPECTED = [
'name': 'saturating_sub', 'name': 'saturating_sub',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_sub' 'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_sub'
}, },
{
'path': 'std::simd::prelude::Simd',
'name': 'simd_clamp',
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_clamp'
},
], ],
}, },
]; ];

View File

@ -0,0 +1,13 @@
// should-fail
const EXPECTED = [
{
// Keep this test case identical to `transmute`, except the
// should-fail tag and the search query below:
'query': 'generic:T -> generic:T',
'others': [
{ 'path': 'std::intrinsics::simd', 'name': 'simd_as' },
{ 'path': 'std::intrinsics::simd', 'name': 'simd_cast' },
{ 'path': 'std::intrinsics', 'name': 'transmute' },
],
},
];

View File

@ -0,0 +1,12 @@
const EXPECTED = [
{
// Keep this test case identical to `transmute-fail`, except the
// should-fail tag and the search query below:
'query': 'generic:T -> generic:U',
'others': [
{ 'path': 'std::intrinsics::simd', 'name': 'simd_as' },
{ 'path': 'std::intrinsics::simd', 'name': 'simd_cast' },
{ 'path': 'std::intrinsics', 'name': 'transmute' },
],
},
];

View File

@ -23,8 +23,8 @@ const EXPECTED = [
'others': [ 'others': [
{ 'path': 'impl_trait', 'name': 'bbbbbbb' }, { 'path': 'impl_trait', 'name': 'bbbbbbb' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'ddddddd' }, { 'path': 'impl_trait::Ccccccc', 'name': 'ddddddd' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'ggggggg' }, { 'path': 'impl_trait::Ccccccc', 'name': 'ggggggg' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
], ],
}, },
{ {
@ -39,14 +39,14 @@ const EXPECTED = [
{ 'path': 'impl_trait', 'name': 'Aaaaaaa' }, { 'path': 'impl_trait', 'name': 'Aaaaaaa' },
], ],
'in_args': [ 'in_args': [
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'eeeeeee' }, { 'path': 'impl_trait::Ccccccc', 'name': 'eeeeeee' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
], ],
'returned': [ 'returned': [
{ 'path': 'impl_trait', 'name': 'bbbbbbb' }, { 'path': 'impl_trait', 'name': 'bbbbbbb' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'ddddddd' }, { 'path': 'impl_trait::Ccccccc', 'name': 'ddddddd' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'ggggggg' }, { 'path': 'impl_trait::Ccccccc', 'name': 'ggggggg' },
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
], ],
}, },
]; ];

View File

@ -11,9 +11,9 @@ const EXPECTED = [
{ {
query: '-> generic:T', query: '-> generic:T',
others: [ others: [
{ path: 'foo', name: 'beta' },
{ path: 'foo', name: 'bet' }, { path: 'foo', name: 'bet' },
{ path: 'foo', name: 'alef' }, { path: 'foo', name: 'alef' },
{ path: 'foo', name: 'beta' },
], ],
}, },
{ {
@ -50,8 +50,8 @@ const EXPECTED = [
{ {
query: 'generic:T', query: 'generic:T',
in_args: [ in_args: [
{ path: 'foo', name: 'beta' },
{ path: 'foo', name: 'bet' }, { path: 'foo', name: 'bet' },
{ path: 'foo', name: 'beta' },
{ path: 'foo', name: 'alternate' }, { path: 'foo', name: 'alternate' },
{ path: 'foo', name: 'other' }, { path: 'foo', name: 'other' },
], ],
@ -59,8 +59,8 @@ const EXPECTED = [
{ {
query: 'generic:Other', query: 'generic:Other',
in_args: [ in_args: [
{ path: 'foo', name: 'beta' },
{ path: 'foo', name: 'bet' }, { path: 'foo', name: 'bet' },
{ path: 'foo', name: 'beta' },
{ path: 'foo', name: 'alternate' }, { path: 'foo', name: 'alternate' },
{ path: 'foo', name: 'other' }, { path: 'foo', name: 'other' },
], ],