Skip to content

gh-138277: Elevate Built-in Types and Functions in Documentation Search - #138278

Merged
StanFromIreland merged 15 commits into
python:mainfrom
adqm:search_scoring
Nov 2, 2026
Merged

StanFromIreland merged 15 commits into
python:mainfrom
adqm:search_scoring

Conversation

@adqm

@adqm adqm commented Aug 31, 2025 •

Copy link
Copy Markdown
Contributor

This patch adds a custom search scorer for the Python docs, in the hopes of making the search results more useful. For now, this just increases the score of built-in functions and types so that they show up closer to the top of the relevant search results, though it also opens the door to other improvements. I also have a couple of other ideas that might further improve the ordering, but I figured it'd be best to start small.

With this change:

  • When searching "str", the built-in str type goes from being the 44th result to the 1st.
  • When searching "set", the built-in set type goes from being the 14th result to the 1st.
  • When searching "int", the built-in int type now shows up above tkinter and pprint.

I don't think this needs a news item, but I can add one if y'all think it's necessary.


📚 Documentation preview 📚: https://cpython-previews--138278.org.readthedocs.build/

@skirpichev

This comment was marked as resolved.

@skirpichev skirpichev left a comment

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 played with this a bit and I generally like new search output 👍

Comment thread Doc/search_scorer.js Resolved
Comment thread Doc/search_scorer.js Resolved
adqm added 3 commits August 31, 2025 02:25
...to try to keep most search results roughly where they currently are.
@adqm

adqm commented Aug 31, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look, @skirpichev! I just pushed a few changes, adding some comments and tweaking the scoring a little bit (to adjust one value that I inadvertently changed from the sphinx defaults that was affecting the ordering more than I intended).

Looking around a bit more, though, I am wondering if it might be better to do this with a Sphinx object domain, though, setting the builtin things to be important. But I'm not sure if there's an easy way to do that without hard-coding all of the built-in objects somewhere. @AA-Turner might know better. Then again, some of the other changes I had been thinking of probably do require a score function anyway...

@StanFromIreland StanFromIreland left a comment •

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.

The file does not belong in the root Doc dir, please move it to Doc/tools/static.

@skirpichev skirpichev left a comment

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.

Look good for me, modulo Stan's comment.

I am wondering if it might be better to do this with a Sphinx object domain, though, setting the builtin things to be important

Probably, the right way might be a mixture of both.

Comment thread Doc/search_scorer.js Resolved
@adqm

adqm commented Aug 31, 2025

Copy link
Copy Markdown
Contributor Author

Thanks! I went ahead and moved the file into tools/static and removed that comment.

@AA-Turner AA-Turner self-assigned this Aug 31, 2025
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 28, 2026
Comment thread Doc/tools/static/search_scorer.js Outdated
let [docname, title, anchor, descr, score, filename] = result;

// boost the score of built-in functions and types
const builtinPages = ["library/stdtypes", "library/functions"];

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.

Let's add library/exceptions and library/constants.

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.

Thanks for taking a look, and good call! I just added those and pushed.

@read-the-docs-community

read-the-docs-community Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Sep 9, 2026
Comment thread Doc/tools/static/search_scorer.js Resolved
Comment thread Doc/conf.py Resolved
@adqm

adqm commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure what was causing the CI failure before, but merging from main seems to have fixed it. If you want any other changes here, just let me know!

Comment thread Doc/tools/static/search_scorer.js Resolved
Comment thread Doc/tools/static/search_scorer.js Resolved
Comment thread Doc/tools/static/search_scorer.js Resolved
@adqm

adqm commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Not sure why the readthedocs build is failing (it looks like it somehow couldn't find that most recent commit?). Is there a way to force it to try again?

@StanFromIreland StanFromIreland left a comment

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 have a little suggestion to avoid elevating non-object results: adqm#2

@adqm

adqm commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for being slow here; I'll check out the results of your patch this weekend and get back to you!

@adqm

adqm commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

that change looks good to me, @StanFromIreland ! i just merged it in.

@hugovk hugovk left a comment

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.

Thank you!

@hugovk hugovk added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 2, 2026
@StanFromIreland
StanFromIreland merged commit 64e3db7 into python:main Nov 2, 2026
38 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @adqm for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@StanFromIreland

Copy link
Copy Markdown
Member

Merged, thanks!

@bedevere-app

bedevere-app Bot commented Nov 2, 2026

Copy link
Copy Markdown

GH-161196 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 2, 2026
@bedevere-app

bedevere-app Bot commented Nov 2, 2026

Copy link
Copy Markdown

GH-161197 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 2, 2026
StanFromIreland added a commit that referenced this pull request Nov 2, 2026
…on Search (GH-138278) (#161196)

(cherry picked from commit 64e3db7)

Co-authored-by: adam j hartz <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
StanFromIreland added a commit that referenced this pull request Nov 2, 2026
…on Search (GH-138278) (#161197)

(cherry picked from commit 64e3db7)

Co-authored-by: adam j hartz <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants