Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,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
# -------------------------------
Expand Down
40 changes: 40 additions & 0 deletions Doc/tools/static/search_scorer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var Scorer = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use const or let instead of var?

score: function (result) {
let [docname, title, anchor, descr, score, filename] = result;

// boost the score of built-in functions and types
const builtinPages = [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following #156682, builtins have been split out. Update to include?

Also alphabetise these.

"library/stdtypes",
"library/functions",
"library/exceptions",
"library/constants",
];
if (builtinPages.includes(docname)) {
score += 7;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why a value of 7?

}

return score;
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment clarifying these are the defaults, as per the docs.

@adqm adqm Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be a while getting back to this. I did used to have a comment in there saying exactly this but removed it after an earlier code review comment (in 7e21628). Should I put it back?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I just added that comment back (along with a reference to the Sphinx docs).

// 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
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rearranged documentation search results to emphasize built-in types and
functions. Patch by Adam Hartz.
Loading