https://github.com/python/cpython/commit/64e3db71131c9a76fd502476cec1fa59a9e974dd commit: 64e3db71131c9a76fd502476cec1fa59a9e974dd branch: main author: adam j hartz <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-11-02T16:52:42Z summary:
gh-138277: Elevate Built-in Types and Functions in Documentation Search (#138278) 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 3514a20f317124b..d6f34576715045f 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -608,6 +608,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]
