[docs] [issue15871] Online docs: make index search always available.

Ezio Melotti report at bugs.python.org
Sat Sep 8 14:51:30 CEST 2012


Ezio Melotti added the comment:

If I search for "random", at the top of the result lists I want to see at least the "random" module and the "random.random" function.

Currently the "random" module is the 4th result, and "random.random" is buried down in the list (17th place) among all the other random.* functions.

The results are generated by the query() function in searchtools.js, and AFAIU it generates 3 lists, importantResults, objectResults, unimportantResults, that get then sorted independently in alphabetic order by the object fullname, and concatenated.

I experimented a bit and one way to get exact matches to the top is to add before the switch at line 370 something like 
if (fullname == object) {
    importantResults.push(result);
    continue;
}

This will include "random", but not "random.random".
Other possible variations are 
  if ((fullname == object) || (fullname.split('.').pop() == object)) {
or
  if ((fullname == object) || $.inArray(object, fullname.split('.')) > -1)

Here fullname is e.g. "random.random", "$.inArray(object, fullname.split('.')) > -1" is the jquery equivalent of Python's "object in fullname.split('.')".

Another way to address the problem is to change the sorting algorithm to move near the top results like "random" and "random.random".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15871>
_______________________________________


More information about the docs mailing list