4

I have installed a Sphinx system using the Read the Doc theme from scratch, with no additional configuration. Search box works well but the search results just show the pages that contain the word that I am searching for, but they don't show a snippet of the actual word in the context of the search.

This is working well in the Readthedoc site, this is for example the result of searching the word "number". The search page shows the pages that contain the "number" word and also a short snippet of the actual text with the "number" word highlighted in yellow

https://docs.readthedocs.io/en/stable/search.html?q=number

Example where the context is shown

When I do a search in my system, these extra paragraphs with the highlighted text do not appear:

Context not showing, just a link to the pages

Should I add a specific configuration parameter to my conf.py file?

Any help is more than appreciated!

mzjn
  • 48,958
  • 13
  • 128
  • 248
  • I can reproduce this with Chrome, but not with Firefox, when accessing the documentation from the file system (on Windows 10). – mzjn May 01 '21 at 15:01
  • I can reproduce it with Firefox and Safari as well (Mac OS Big Sur 11.3.2), the snippets are not shown. Just in case it helps, I'm accessing the files from the file system in my local computer (there is no local HTTP server running), but it also happens when I upload the HTMLs to a web server – Daron Burleson May 01 '21 at 16:49
  • 1
    My bad... I have just noticed that it works well if there is a HTTP server providing the files instead of opening them from right the filesystem. – Daron Burleson May 01 '21 at 16:55
  • 2
    I think we can close this issue, I have just raised a but in the Sphinx-doc Github tracker: https://github.com/sphinx-doc/sphinx/issues/9156 – Daron Burleson May 01 '21 at 19:35

1 Answers1

0

(chatgpt answer, and it works !) When viewing the search page from a local directory, browser security restrictions might prevent certain features like XHR (XMLHttpRequest) from working properly, which could lead to missing search result snippets. To solve this:

  1. Host Locally: Set up a local web server to host your Sphinx documentation. This will allow the search functionality to work as intended without browser security restrictions.

  2. Use Python: If you have Python installed, you can use the built-in HTTP server to host your documentation. Navigate to your documentation folder in the terminal and run:

 python -m http.server

This will start a simple HTTP server, and you can access your documentation at http://localhost:8000.

By hosting your documentation on a local server, you should be able to bypass the browser's security restrictions related to local files and ensure that the search functionality, including snippet display, works properly.