diff options
| author | Michael Howell <michael@notriddle.com> | 2023-12-26 16:15:51 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-12-26 18:46:17 -0700 |
| commit | 0ea58e2346b905a7847d890db6e8e5154a390e2e (patch) | |
| tree | 69de366b7173faf9070a04f7ba90c6d48d1d1f8b /tests/rustdoc-js/path-maxeditdistance.js | |
| parent | a75fed74b62f95d1659ff70bea7895ed5c85bdba (diff) | |
| download | rust-0ea58e2346b905a7847d890db6e8e5154a390e2e.tar.gz rust-0ea58e2346b905a7847d890db6e8e5154a390e2e.zip | |
rustdoc-search: count path edits with separate edit limit
Since the two are counted separately elsewhere, they should get
their own limits, too. The biggest problem with combining them
is that paths are loosely checked by not requiring every component
to match, which means that if they are short and matched loosely,
they can easily find "drunk typist" matches that make no sense,
like this old result:
std::collections::btree_map::itermut matching slice::itermut
maxEditDistance = ("slice::itermut".length) / 3 = 14 / 3 = 4
editDistance("std", "slice") = 4
editDistance("itermut", "itermut") = 0
4 + 0 <= 4 PASS
Of course, `slice::itermut` should not match stuff from btreemap.
`slice` should not match `std`.
The new result counts them separately:
maxPathEditDistance = "slice".length / 3 = 5 / 3 = 1
maxEditDistance = "itermut".length / 3 = 7 / 3 = 2
editDistance("std", "slice") = 4
4 <= 1 FAIL
Effectively, this makes path queries less "typo-resistant".
It's not zero, but it means `vec` won't match the `v1` prelude.
Queries without parent paths are unchanged.
Diffstat (limited to 'tests/rustdoc-js/path-maxeditdistance.js')
| -rw-r--r-- | tests/rustdoc-js/path-maxeditdistance.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/rustdoc-js/path-maxeditdistance.js b/tests/rustdoc-js/path-maxeditdistance.js new file mode 100644 index 00000000000..73b24a6dddf --- /dev/null +++ b/tests/rustdoc-js/path-maxeditdistance.js @@ -0,0 +1,35 @@ +// exact-check + +const EXPECTED = [ + { + 'query': 'xxxxxxxxxxx::hocuspocusprestidigitation', + // do not match abracadabra::hocuspocusprestidigitation + 'others': [], + }, + { + // exact match + 'query': 'abracadabra::hocuspocusprestidigitation', + 'others': [ + { 'path': 'abracadabra', 'name': 'HocusPocusPrestidigitation' }, + ], + }, + { + // swap br/rb; that's edit distance 2, where maxPathEditDistance = 3 (11 / 3) + 'query': 'arbacadarba::hocuspocusprestidigitation', + 'others': [ + { 'path': 'abracadabra', 'name': 'HocusPocusPrestidigitation' }, + ], + }, + { + // truncate 5 chars, where maxEditDistance = 7 (21 / 3) + 'query': 'abracadarba::hocusprestidigitation', + 'others': [ + { 'path': 'abracadabra', 'name': 'HocusPocusPrestidigitation' }, + ], + }, + { + // truncate 9 chars, where maxEditDistance = 5 (17 / 3) + 'query': 'abracadarba::hprestidigitation', + 'others': [], + }, +]; |
