Skip to content

Issue with search across subprojects #12162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OriolAbril opened this issue May 8, 2025 · 4 comments
Closed

Issue with search across subprojects #12162

OriolAbril opened this issue May 8, 2025 · 4 comments

Comments

@OriolAbril
Copy link
Contributor

Details

I am not sure when it started to happen, but we have a main project with multiple subprojects and results from subprojects have stopped appearing when searching on the main project.

Expected Result

Several months back whenever searching we would get search results across subprojects as expected from the docs and search entries got indicators (from "docs" project) or (from "examples" project).

Actual Result

Currently search is only local to pymcio project which has a landing page and a blogpost so it generally finds nothing and there are no longer any (from "xyz" project) indicators because nothing from any subproject is found even when there should be matches.

I am not sure what is happening nor at what level the issue might be, something general, theme specific, maybe we are breaking things when customizing the theme further. I leave some extra details below and sorry if I am not reporting to the right place.


Extra details

As users are generally not very aware of the subproject they are in and expected search to be "global" we aliased the search of the subprojects to that of the main project. But back when we did that it wasn't an issue, it still worked.

Right now I am attempting to have two search bars on the search page (see example https://pymcio--225.org.readthedocs.build/projects/bart/en/225/search.html) which so far seems to redirect the searches to the right place, but the search from the parent project is local instead of global across subprojects (as it is a redirect from the PR preview to the published parent project search).

We weren't so far but we will be templating the search.html page and extending one of its blocks to add the extra search bar. We were templating the components/search-filed.html and will continue to do so. We are using the pydata-sphinx-theme which itself also templates the search.html and as fas as I can tell has been doing so from before we started using, so global search worked initially with that setup. Link to custom theme project (only a handful of changes on top of pydata-sphinx-one): https://github.com/pymc-devs/pymc-sphinx-theme

@OriolAbril
Copy link
Contributor Author

I missed this issue before when searching for "search" related things which is probably relevant if the theme is circumventing the search addon (which is active on the dashboard for all projects): pydata/pydata-sphinx-theme#1933

@stsewd
Copy link
Member

stsewd commented May 15, 2025

Hi, currently, you have to manually check the "include subprojects" box in

Image

We have plans to make it more configurable, so for example that check to always be checked. We have an open issue at readthedocs/addons#22.

@stsewd stsewd closed this as completed May 15, 2025
@OriolAbril
Copy link
Contributor Author

For full context, when I posted the issue there was a single search bar, the theme one which I was unable to get to work with the readthedocs search (and still am, it is the lower bar now; I also commented on the theme issue related to this). As other themes do integrate with readthedocs I copied a search bar from these themes as the top bar and used the javascript from https://docs.readthedocs.com/platform/stable/addons.html#integrate-with-search-as-you-type:

// TODO: Change me if needed
const selector = "input[type='search']";

document.addEventListener("DOMContentLoaded", function(event) {
    // Trigger Read the Docs' search addon instead of the default search
    document.querySelector(selector).addEventListener("click", (e) => {
        const event = new CustomEvent("readthedocs-search-show");
        document.dispatchEvent(event);
    });
});

I was able to adapt it to the top bar but not to the lower one no matter which selectors I tried, hence the theme incompatibility I mention as the theme also has search related javascript which probably interferes (I have no idea about javascript).

Having the include subprojects check on by default will be nice, but the issue was about the flyout appearing at all which does never appear when using the pydata-sphinx-them even if using this javascript above with what to my non-javscript self looks like the right selector (same as default one "input[type='search']") given their search template:

https://github.com/pydata/pydata-sphinx-theme/blob/3e74810e3ad3778c179f3f836409540e0a3bf0f1/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-field.html#L6

@stsewd
Copy link
Member

stsewd commented May 15, 2025

if using this javascript above with what to my non-javscript self looks like the right selector (same as default one "input[type='search']") given their search template:

looks like you are including the script before the DOM loads, the script needs to run after the DOM is loaded for it to find the node. You can achieve this in several ways, an easy one would be to add the defer attribute to your script tag.

https://github.com/pymc-devs/pymc-sphinx-theme/blob/f8b7d7537ef1fb46dc81899ee255a851ac439cdb/src/pymc_sphinx_theme/layout.html#L5

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

No branches or pull requests

2 participants