Skip to content
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

Support third-party serarch like Algolia, minisearch, and lyrajs #795

Open
choldgraf opened this issue Jul 11, 2022 · 5 comments
Open

Support third-party serarch like Algolia, minisearch, and lyrajs #795

choldgraf opened this issue Jul 11, 2022 · 5 comments
Labels
kind: enhancement New feature or request

Comments

@choldgraf
Copy link
Collaborator

choldgraf commented Jul 11, 2022

Context

Sphinx's default search UI is nice, but feels a bit out of date. It takes you to a dedicated page for search results, has non-fuzzy matching, and doesn't have a "results as you type" interface.

There are many other search libraries out there, and most of them could be adapted to the structure of this theme with the same UX around activating them (e.g. ctrl+k). This is an issue to track these options and their functionality in case we wish to implement support for them.

Algolia

Algolia has a really nice AI-powered search API that you can hook into via your own documentation site. Many documentation engines are starting to support Algolia as an option if their authors sign up for an Algolia account. This pops up an Algolia search overlay with much more rapid feedback.

For example, see the Docasaurus docs:

chrome_WVfEMbiNLI

Algolia is pretty flexible, and should work just fine with Sphinx. To support it, I think you just need to make sure that the styling works as-expected and make it possible for the "search click" to hook into the Algolia JavaScript.

Minisearch

Minisearch is a lightweight search engine. I think we'd have to build our own UI around it?

Lyrajs

Lyrajs seems to have a bit more UI built into it.

Implementation

It think this could be implemented relatively easily by making it possible to define a different function in our search button hook:

{#- Only on pages not `search.html`. This is because we only want the in-page search on this page -#}
{%- if pagename !="search" -%}
{#- This will be hidden by default until click -#}
<div class="search-button__overlay" onclick="toggleSearchField()"></div>
<div class="{{ containerClass }}">
{% include "../components/search-field.html" %}
</div>
{% endif %}

In the case of lyrajs or minisearch, we'd also need to add code that would build up a little in-memory search database via text. It shouldn't need to be too big since it is all text though.

References

@choldgraf choldgraf added the kind: enhancement New feature or request label Jul 11, 2022
@12rambau
Copy link
Collaborator

related to #202

@choldgraf choldgraf changed the title Support Algolia search Support third-party serarch like Algolia, minisearch, and lyrajs Dec 16, 2022
@agriyakhetarpal
Copy link

Hi, we have been looking into adding Algolia DocSearch to our documentation at https://docs.pybamm.org with the PyData Sphinx Theme and turns out that Algolia is providing its own Sphinx extension now which could make the process a bit easier – it is still at version 0.0.3, so it is probably not ready for production however.

@12rambau
Copy link
Collaborator

12rambau commented Jan 7, 2025

@choldgraf Is the solution provided in #2093 which create an internal search as you type mechanism would supersede this issue ? I'm not sure we should supports tons of search tools if we start using our own.

@maximlt
Copy link
Contributor

maximlt commented Jan 8, 2025

My 2 cents and, as far as I can see, #2093 improves the search UI with "results as you type" but doesn't touch the search engine. This issue mentions both and focuses quite on the engine side by listing multiple JS engine libraries. I'd certainly like to make it easier to use and customize search engines for Sphinx sites (though I don't really know to which extent it is the responsibility of a theme).

@kaycebasques
Copy link
Contributor

Hello, author of #2093 (feel free to ping me as needed)

Can confirm that #2093 does not touch the search engine. Implementation is detailed here: https://github.com/orgs/sphinx-doc/discussions/13222

It basically just intercepts the search query, uses the built-in client-side Sphinx search suite (searchtools.js) to conduct the search, and sets up a container for searchtools.js to populate the results into.

Being able to swap out the underlying search engine would be cool. Assuming that searchtools.js is one of the supported engines, I can sketch out what is and is not feasible for it to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants