Closed boy-vd closed 5 years ago
Thanks for your comment, hopefully this will help others in the future. You could consider turning this into a Sphinx extension if you have the time and knowhow.
I'll close this ticket, since there is nothing left to do but keep it readable for posterity.
@boy-vd do you have any thoughts on whether algolia could work on a multi-version site? E.g. we have docs.site.org/en/<version>/
and searches on one version's page should only return results from that same version.
You can use algolia on multi version sides using facetfilters. This is an example docsearch config that labels the search index entries with a version tag. I have also seen config that solve this problem like this
config = {
"index_name": "name",
"start_urls": [
{
"url": BASEURL + "(?P<version>.*?)/",
"variables": {"version": versions},
}
],
...
You enable facet filters in the docseach js script like this
<!-- at the end of the BODY -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
<script type="text/javascript"> docsearch({
apiKey: APIKEY,
indexName: INDEXNAME
inputSelector: '### REPLACE ME ####',
algoliaOptions: { 'facetFilters': ["version:$VERSION"] },
debug: false // Set debug to true if you want to inspect the dropdown
});
</script>
@boy-vd @joleroi I am exploring https://github.com/algolia/autocomplete to create a instant search with autocomplete which shows matching page names and if possible, API classes, methods, etc. that also show up in toctree if titles_only
is false
. Any suggestion how can I populate the source?
Hi sphinx. I'll be seeing ya. This side of the other.
I'm sorry if this isn't the right place to share, but since I struggled quite a bit with getting Algolia DocSearch to work I thought others might appreciate it as a useful example. I initially wrote and shared this as a reply to an issue on the official Sphinx GitHub repo: https://github.com/sphinx-doc/sphinx/issues/3812.
The following configuration works well for a Sphinx 1.8.5 environment with and ):
sphinx_rtd_theme
version 0.4.3. It's very easy to implement (basically copy-paste everything to the correct places and make sure to add your ownThe
algolia.css
file in the_static
directory contains the following:And the
algolia.js
file in the same_static
directory contains this:The above setup makes use of the public crawler that Algolia hosts for free on their servers: https://community.algolia.com/docsearch/dropdown.html. Implementing it based on a crawler that you build yourself shouldn't be much different: https://community.algolia.com/docsearch/run-your-own.html.