From bf9eac9844a62a125c50fcd1b41bbbcd53081e5d Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sun, 24 Aug 2014 16:20:40 -0400 Subject: [PATCH] Sort doc search results by their total module path length With the assumption that more commonly used items are going to be higher in the module hierarchy and have shorter names, so this is a good heuristic for more important and more relevant to the person searching the docs. --- src/librustdoc/html/static/main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 7b5d1b7be2f63..7f379cfd98cb6 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -266,6 +266,11 @@ b = (bbb.item.crate !== window.currentCrate); if (a !== b) return a - b; + // sort by total module path length (longer goes later) + a = (aaa.item.path + (aaa.item.parent || {name: ''}).name + aaa.item.name).length; + b = (bbb.item.path + (bbb.item.parent || {name: ''}).name + bbb.item.name).length; + if (a !== b) return a - b; + // sort by exact match (mismatch goes later) a = (aaa.word !== valLower); b = (bbb.word !== valLower);