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

Search function broken in 2.0.0 #6244

Closed
jobec opened this issue Apr 2, 2019 · 8 comments
Closed

Search function broken in 2.0.0 #6244

jobec opened this issue Apr 2, 2019 · 8 comments

Comments

@jobec
Copy link
Contributor

jobec commented Apr 2, 2019

Describe the bug
When searching in the built HTML file, no results are diplayed and only "Searching..." is showing.

The browser console shows:

jquery.js:2 jQuery.Deferred exception: Search.loadIndex is not a function TypeError: Search.loadIndex is not a function
    at HTMLDocument.<anonymous> (http://localhost:63342/documentation/_build/search.html?q=redis&check_keywords=yes&area=default:250:32)
    at j (http://localhost:63342/documentation/_build/_static/jquery.js:2:29999)
    at k (http://localhost:63342/documentation/_build/_static/jquery.js:2:30313) undefined

Looks like a regression from #467

To Reproduce
Steps to reproduce the behavior:

sphinx-build -b html -W -n -E -a -j auto ./docs ./_build

Expected behavior
Search is working

Your project
Even an empty index.rst does it.

Screenshots

Environment info

  • OS: Win
  • Python version: 3.6.6
  • Sphinx version: 2.0.0
  • Sphinx extensions: /
  • Extra tools: Latest chrome or firefox
@tk0miya
Copy link
Member

tk0miya commented Apr 2, 2019

@jobec what theme have you used? I'd like to reproduce the error.
Thanks,

@tk0miya tk0miya added this to the 2.0.1 milestone Apr 2, 2019
@jobec
Copy link
Contributor Author

jobec commented Apr 2, 2019

sphinx_rtd_theme

@jobec
Copy link
Contributor Author

jobec commented Apr 2, 2019

Going to the default theme seems to make the error go away.

@tk0miya
Copy link
Member

tk0miya commented Apr 2, 2019

Thank you for info.
https://github.com/rtfd/sphinx_rtd_theme/blob/ddfdd35e6977f21fb1771734732756b0cf1d6bba/sphinx_rtd_theme/search.html#L13-L21

Absolutely this is a bug of Sphinx. I'll take a look #6091 later.

@tk0miya
Copy link
Member

tk0miya commented Apr 6, 2019

Fixed by #6257.
Thank you for reporting!

@tk0miya tk0miya closed this as completed Apr 6, 2019
@ViktorHaag
Copy link
Contributor

ViktorHaag commented Apr 11, 2019

Thanks for your work on this @tk0miya, but I'd like to suggest that we re-open this issue. I have noticed that search function is still broken for me, even with the 2.0.1 release. I am using a theme that's based on the older haiku theme and modified for local needs.

I am noticing that the behaviour of the basic searchtools.js is inconsistent; in some case (opening my build as local files in Chrome) the search seems to work with various search terms within my built documentation. However, in some cases, the search does not work with some search terms in some other browsers (Firefox opening the build as local files; also, Safari; seemingly all browsers trying to search when opening the build documents after deployment to a webserver).

Looking in Firefox's browser console, I'm consistently seeing this error arise from searchtools.js:

TypeError: docContent is undefined searchtools.js:66:7
    htmlToText file:///Users/vhaag/src/devsite/valence-api-docs/pub/html/_static/searchtools.js:66
    makeSearchSummary file:///Users/vhaag/src/devsite/valence-api-docs/pub/html/_static/searchtools.js:483
    complete file:///Users/vhaag/src/devsite/valence-api-docs/pub/html/_static/searchtools.js:277
    jQuery 4
    
    i
    
    fireWith
    
    A
    
    c

I have also noticed that the search results I see in Chrome when it works with the local files don't show any more context than the bold single line entries in the search (i.e. they don't show any context from the 'source' files that are copied over in the build). This leads me to wonder whether there's an issue in picking through the "source files" looking for context?

I have done some simple debugging on my end by starting with the 1.8.5 searchtools.js (which works, even when used with Sphinx v2) and slowly adding stuff from the Sphinx v2 version of searchtools, and I believe that I have determined that the problem with search lies in the use of the htmlToText function that was added in Sphinx v2. If I use all of the Sphinx v2 searchtool.js, except the call to that function, and go back to the way that searchtools.js in 1.8.5 functioned, namely adjusting these lines near the bottom, everything seems to work:

...
  makeSearchSummary : function(text, keywords, hlwords) {
    //
    // Sphinx v2 improvement of using Search.htmlToText(text) breaks our docs,
    // reverting to just not calling it seems to retain the old behaviour
    //
    // makeSearchSummary : function(htmlText, keywords, hlwords) {
    //   var text = Search.htmlToText(htmlText);
    var textLower = text.toLowerCase();
...

@ViktorHaag
Copy link
Contributor

My skills with javascript and front-end stuff aren't so strong; I hope I've given enough information that we can re-open this issue as not really fixed, and have further investigation? I believe that it's not as simple as that the search index isn't successfully loading...

@tk0miya
Copy link
Member

tk0miya commented May 21, 2019

@ViktorHaag Sorry for missing your comment. I filed #6387 as a new issue. Please watch it please.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants