https://github.com/python/cpython/commit/86687641750515fc72aad80bb3b72272115b5a33
commit: 86687641750515fc72aad80bb3b72272115b5a33
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-11-02T16:59:44Z
summary:

[3.15] gh-138277: Elevate Built-in Types and Functions in Documentation Search 
(GH-138278) (#161196)

(cherry picked from commit 64e3db71131c9a76fd502476cec1fa59a9e974dd)

Co-authored-by: adam j hartz <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Doc/tools/static/search_scorer.js
A Misc/NEWS.d/next/Documentation/2025-08-31-02-28-21.gh-issue-138277.kkORph.rst
M Doc/conf.py

diff --git a/Doc/conf.py b/Doc/conf.py
index 1bfb303085b0403..367cba6ea31c221 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -610,6 +610,11 @@
     r'https://unix.org/version2/whatsnew/lp64_wp.html',
 ]
 
+# Options to adjust search results sorting
+# ----------------------------------------
+
+html_search_scorer = "tools/static/search_scorer.js"
+
 
 # Options for sphinx.ext.extlinks
 # -------------------------------
diff --git a/Doc/tools/static/search_scorer.js 
b/Doc/tools/static/search_scorer.js
new file mode 100644
index 000000000000000..82a781a526ed8d3
--- /dev/null
+++ b/Doc/tools/static/search_scorer.js
@@ -0,0 +1,40 @@
+var Scorer = {
+  score: function (result) {
+    let [docname, title, anchor, descr, score, filename, kind] = result;
+
+    // boost the score of built-in functions and types
+    const builtinPages = [
+      "builtins/constants",
+      "builtins/exceptions",
+      "builtins/functions",
+      "builtins/stdtypes",
+    ];
+    if (kind === "object" && builtinPages.includes(docname)) {
+      score += 7;
+    }
+
+    return score;
+  },
+
+  // all values below this line are the Sphinx defaults
+  // (see 
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_search_scorer)
+
+  // Additive scores depending on the priority of the object
+  // Priority is set by object domains
+  // (see https://www.sphinx-doc.org/en/master/extdev/domainapi.html)
+  objPrio: {
+    0: 15,
+    1: 5,
+    2: -5,
+  },
+  objPrioDefault: 0,
+
+  objNameMatch: 11, // score if object's name exactly matches search query
+  objPartialMatch: 6, // score if object's name contains search query
+
+  title: 15, // score if title exactly matches search query
+  partialTitle: 7, // score if title contains search query
+
+  term: 5, // score if a term exactly matches search query
+  partialTerm: 2, // score if a term contains search query
+};
diff --git 
a/Misc/NEWS.d/next/Documentation/2025-08-31-02-28-21.gh-issue-138277.kkORph.rst 
b/Misc/NEWS.d/next/Documentation/2025-08-31-02-28-21.gh-issue-138277.kkORph.rst
new file mode 100644
index 000000000000000..198d1de3121c5b2
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Documentation/2025-08-31-02-28-21.gh-issue-138277.kkORph.rst
@@ -0,0 +1,2 @@
+Rearranged documentation search results to emphasize built-in types and
+functions.  Patch by Adam Hartz.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to