From 0ea58e2346b905a7847d890db6e8e5154a390e2e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 26 Dec 2023 16:15:51 -0700 Subject: 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. --- tests/rustdoc-js/module-substring.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'tests/rustdoc-js/module-substring.js') diff --git a/tests/rustdoc-js/module-substring.js b/tests/rustdoc-js/module-substring.js index 7a10397ebc6..74c421d7f0b 100644 --- a/tests/rustdoc-js/module-substring.js +++ b/tests/rustdoc-js/module-substring.js @@ -1,7 +1,15 @@ -const EXPECTED = { - 'query': 'ig::pc', - 'others': [ - { 'path': 'module_substring::Sig', 'name': 'pc' }, - { 'path': 'module_substring::Si', 'name': 'pc' }, - ], -}; +const EXPECTED = [ + { + 'query': 'ig::pc', + 'others': [ + { 'path': 'module_substring::Sig', 'name': 'pc' }, + ], + }, + { + 'query': 'si::pc', + 'others': [ + { 'path': 'module_substring::Si', 'name': 'pc' }, + { 'path': 'module_substring::Sig', 'name': 'pc' }, + ], + }, +]; -- cgit 1.4.1-3-g733a5