Since the sorting function accounts for an `index` field, there's not much
reason to also be applying changes to the levenshtein distance. Instead,
we can just not treat `lev` as a filter if there's already a non-sentinel
value for `index`.
This change gives slightly more weight to the index and path part, as
search criteria, than it used to. This changes some of the test cases,
but not in any obviously-"worse" way, and, in particular, substring matches
are a bigger deal than levenshtein distances (we're assuming that a typo
is less likely than someone just not typing the entire name).
Based on
https://github.com/rust-lang/rust/pull/103710#issuecomment-1296894296
This renames the ID, which is only used in search results, to
`#search-tabs`. Also changes the `.count` to a span, so it doesn't need its
display mode to be overridden.
Resolves all of issue #93240
Reproduces a similar change as #99086, but with improvements
In particular, this PR inlcludes:
* redesigning the crate-search selector so the background color matches its surroundings
* decrease the font of the dropdown menu to a reaonable size
* add a hover effect
* make the color of the arrow theme-dependent, using a surrounding div, with :after pseudo-element
that can then be transformed using CSS filters to approximate the desired color
* fix the text "in" to match the title font
* remove the "for xyz" in the "Results for xyz in [All crates]" title when
searching for search term "xyz"; you can already see what you're searching for
as it's typed in the search bar!
* in line with #99086, handle super-long crate names appropriately without a long <select>
element escaping the screen area; the improvement is that we also keep the title
within a single line now; uses some flex layout shenanigans...
* the margins / paddings are adjusted so the selected label of the <select> fits within
the rest of that title nicely; also some inconsistency in the way that Firefox renders
a <select> with "appearance: none" (roughly 4px more padding left and right of the text
than e.g. Chrome) is worked around, and it now produces a result that looks (essentially)
identical to Chrome
* the color of the help menu and settings menu border in light theme is made to match with
the color of the corresponding buttons, like they do (match) in the ayu theme
* the casing of "All crates" changes to "all crates"
* the new tests from #99086 are temporarily disabled, until they can be adapted later
This reduces the size of the function signature index, because
it's common to have many functions that operate on the same types.
$ wc -c search-index-old.js search-index-new.js
5224374 search-index-old.js
3932314 search-index-new.js
By my math, this reduces the uncompressed size of the search index by 32%.
On compressed signatures, the wins are less drastic, a mere 8%:
$ wc -c search-index-old.js.gz search-index-new.js.gz
404532 search-index-old.js.gz
371635 search-index-new.js.gz
Now that the "All Crates" dropdown is only rendered on the search results page,
there is no need to load crates.js on most pages. Load it only on crate pages.
Also, add the `defer` attribute so it does not block page rendering.
For sidebar-items.js, move the script tag to `<head>`. Since it already has the
defer attribute it won't block loading. The defer attribute does preserve
ordering between scripts, so instead of the callback on load, it can set a
global variable on load, which is slightly simpler. Also, since it is required
to finish rendering the page, beginning its load earlier is better.
Remove generation and handling of sidebar-vars. Everything there can be computed
with information available in JS via other means.
Remove the "other" wrapper in the sidebar. It was unnecessary.
Remove excess script fields
Previously, search.js relied on the DOM and the `window` object. It can now be
loaded in the absence of the DOM, for instance by Node. The same is true of
search-index.js.
This allows removing a lot of code from src/tools/rustdoc-js/tester.js that
tried to parse search.js and extract specific functions that were needed for
testing.
Fixes reexports in search
Fixes#96681.
At some point we stopped reexporting items in search so this PR fixes it.
It also adds a regression test.
r? ```@notriddle```
* If it's just `-> a`, use "In Function Return Types"
* If it's just `a b`, use "In Function Parameters"
* Otherwise, still use "In Function Signatures"