mozilla/rust — pull request #13514 by lifthrasiir (2014-04-14 19:00:12+00:00)
Title: rustdoc: Better sorting criteria for searching.

This essentially rewrites the sorting algorithm, which relied on the implementation-defined handling of non-consistent sorting function (cf. ECMA-262 5th edition, [section 15.4.4.11](http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.11)) and was also a bit inefficient.

The new criteria expands the prior criteria while adding these ones:

- The current crate is always preferred over other crates. (Closes #13178)
- An item with a description is preferred over one without it, if item names match. This is a heuristic assuming that the documented item is more likely to be relevant.
- An item with no literal occurrence of search query is handled correctly.

****

Example with the query `repr`:

* std::repr *(exact match, module first)*
* std::raw::Repr *(struct/trait first)*
* std::repr::Repr
* std::raw::Repr::repr *(type method later)*
* std::repr::write_repr *(no desc)*
* std::repr::Repr::write_repr *(no desc)*
* std::repr::repr_to_str *(no desc)*
* std::repr::ReprVisitor *(no desc)*
* std::repr::ReprVisitor *(no desc)*
* std::repr::ReprVisitor::write_unboxed_vec_repr *(no desc)*
* rustc::middle::trans::adt::Repr *(exact match not in the current crate)*
* rustc::util::ppaux::Repr
* rustc::util::ppaux::Repr::repr
* ...

Example with the query `fm`:

* std::fmt *(prefix match, module first)*
* std::fmt::Show::fmt *(type method first)*
* std::io::process::ProcessExit::fmt *(normal method later, but has desc, thus prefered over others)*
* std::ascii::Ascii::fmt *(no desc)*
* std::cell::Cell::fmt *(no desc)*
* std::cmp::Ordering::fmt *(no desc)*
* ...
* std::fmt::RadixFmt *(later occurence of the query in the name)*
* std::rt::unwind::begin_unwind_fmt
* ...