opendp / opendp

The core library of differential privacy algorithms powering the OpenDP Project.
https://opendp.org
MIT License
284 stars 46 forks source link

Show context snippet for search results #1517

Open mccalluc opened 3 weeks ago

mccalluc commented 3 weeks ago

When I search on docs.opendp.org, all I see is the document title. Sphinx should able to show us snippets, giving us our search term in context. For example: https://www.sphinx-doc.org/en/master/search.html?q=context

There are a couple layers to the problem: The JS-based search only has an index of the documents. For snippets, it actually needs to load the document and parse its contents, but if we're just using file:/// that's not possible: The page does not have permission to read arbitrary files from the file system -- For good reason! see https://github.com/sphinx-doc/sphinx/issues/9156

But we don't see snippets on docs.opendp.org either. If we look in the debugger, we see lots of errors:

Uncaught (in promise) TypeError: docContent is null

coming from the second line here:

    const docContent = htmlElement.querySelector('[role="main"]');
    if (docContent !== undefined) return docContent.textContent;

htmlElement.documentElement.innerHTML looks like it is the full html, but docContent gets set to null. Looking at the source html, we are missing the role="main" attribute.

Looking at the docs:

In order for the built-in JavaScript search to show a page preview on the results page, the document or body content should be wrapped in an HTML element containing the role="main" attribute.

I'll investigate...

mccalluc commented 3 weeks ago

Ah: It was a bug in pydata-sphinx-theme. Updating should fix.

mccalluc commented 3 weeks ago

Except that there hasn't been a release since that fix. Options:

I'd suggest waiting. It has been a while, but other people are also want this fix, and in the past year they've generally made a release every month or so.

Shoeboxam commented 3 weeks ago

Agree with waiting, no point complicating this.