Pin RTD search query to current version - #328
Conversation
The v3 search API call in getReadTheDocsResults was missing the version parameter, so RTD defaulted to the project's default version (stable). On non-stable builds (latest, a release branch, a PR build) search results linked to /en/stable/ pages instead of the version being read. Capture versions.current.slug from the readthedocs-addons-data-ready event and append &version=<slug> to the query. Fixes sunpy#327.
|
Thanks for the PR. I can't see the modified request on the RTD preview. I don't know if this is because it's a PR or if something is bugged? |
|
You were right... RTD expects the version in the search expression as The fix is pushed now. |
There was a problem hiding this comment.
Pull request overview
This PR aims to keep Read the Docs “enhanced search” results pointing at the currently viewed documentation version (e.g., latest or a release branch) instead of defaulting links to stable.
Changes:
- Adds a listener for the
readthedocs-addons-data-readyevent to capture the current RTD project/version slug. - Adjusts the RTD v3 search query construction to incorporate the captured version when building the project search filter.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fixes #327.
Read the Docs v3 search defaults each project to its default version, usually
stable. This caused searches from non-stable documentation builds to return links for/en/stable/.This change reads the current project and version from the Read the Docs Addons data and pins only that project inside the search query using
project:<slug>/<version>. Other projects remain on their own default versions.External PR builds are not indexed, so they retain the existing unpinned search behavior. The Addons data is handled both when already available and when delivered later by the
readthedocs-addons-data-readyevent.This also affects projects using the SunPy theme, including Astropy through the Astropy unified theme. See astropy/astropy#19866.