Skip to content

Commit eb17041

Browse files
miss-islingtonadqmStanFromIreland
authored
[3.14] gh-138277: Elevate Built-in Types and Functions in Documentation Search (GH-138278) (#161197)
(cherry picked from commit 64e3db7) Co-authored-by: adam j hartz <hz@mit.edu> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent ab79a3d commit eb17041

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎Doc/conf.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,11 @@
608608
r'https://unix.org/version2/whatsnew/lp64_wp.html',
609609
]
610610

611+
# Options to adjust search results sorting
612+
# ----------------------------------------
613+
614+
html_search_scorer = "tools/static/search_scorer.js"
615+
611616

612617
# Options for sphinx.ext.extlinks
613618
# -------------------------------

‎Doc/tools/static/search_scorer.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var Scorer = {
2+
score: function (result) {
3+
let [docname, title, anchor, descr, score, filename, kind] = result;
4+
5+
// boost the score of built-in functions and types
6+
const builtinPages = [
7+
"builtins/constants",
8+
"builtins/exceptions",
9+
"builtins/functions",
10+
"builtins/stdtypes",
11+
];
12+
if (kind === "object" && builtinPages.includes(docname)) {
13+
score += 7;
14+
}
15+
16+
return score;
17+
},
18+
19+
// all values below this line are the Sphinx defaults
20+
// (see https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_search_scorer)
21+
22+
// Additive scores depending on the priority of the object
23+
// Priority is set by object domains
24+
// (see https://www.sphinx-doc.org/en/master/extdev/domainapi.html)
25+
objPrio: {
26+
0: 15,
27+
1: 5,
28+
2: -5,
29+
},
30+
objPrioDefault: 0,
31+
32+
objNameMatch: 11, // score if object's name exactly matches search query
33+
objPartialMatch: 6, // score if object's name contains search query
34+
35+
title: 15, // score if title exactly matches search query
36+
partialTitle: 7, // score if title contains search query
37+
38+
term: 5, // score if a term exactly matches search query
39+
partialTerm: 2, // score if a term contains search query
40+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Rearranged documentation search results to emphasize built-in types and
2+
functions. Patch by Adam Hartz.

0 commit comments

Comments
 (0)