Search in bookdown not working

Hello, RStudio Community!

I'm very much enjoying trying my hand at creating a website with bookdown, hosted on GitHub Pages as described here, but our search function is showing up but not working.

search_bookdown

This book has been served (bookdown::serve_book()) and the above snapshot is shown from the page built on our internal GitHub Enterprise server.

I have read through one issue on the bookdown-demo package that seems relevant:

but the problems/solutions don't quite seem relevant to my situation because:

  1. I am getting this same behavior on GitHub Pages and after bookdown::serve_book in the RStudio Viewer
  2. I am not using crayon to the best of my knowledge (I do not know what crayon is)
  3. I am using the most recent version of bookdown

Thank you for any help figuring this out!

> sessionInfo("bookdown")
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CloudForms

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
character(0)

other attached packages:
[1] bookdown_0.21

I would like to help but without an example I can look into or reproduce, it is difficult for me.

Did you build the book using bookdown::render_book() or using the Build Book button in the IDE ?

In the resulting folder (by default, _book), there should be a search_index.json file. Is this present locally ?
When you run bookdown::serve_book() it should build the book and create this file. The same in the book you host in your Github server.

You can open in a browser the bookdown site and also look into the browser's inspector (usually by hitting F12) to see if there is an error while loading this json file.

The search engine needs this file in order for the search to work.

This is a guess of what could be happening. If you can share more information, I am happy to help further.

Hi @cderv

Thanks for trying to walk through this with me! Understood that it is made much harder without a public example.

I used the Build Book button in the IDE (so I've been running serve_book() rather than render_book()).

I do have this search_index.json file, but it is mostly empty. I didn't realize until your comment that I hadn't looked at other people's search_index.json to get a feeling for what this file should contain. A quick github search shows some examples of search_index.json files that are very, very different from mine -- e.g. this bookdown issue

My search_index.json file, on the other hand, is just empty strings.

[[" ", " ", " "]]

Does that help narrow down where the error is occurring? That is how the search_index.json file looks both locally in RStudio and the version on GitHub.

Thanks so much for your help!

Best,
Rebecca

I ran render_book() in a fresh R session and still get the mostly-empty search_index.json file.

I am sorry to say that this is new enough to me that I am very much out of debugging ideas and would love any thoughts.

Semi-relatedly, do you have a guess for when 0.22 will be released? I am loving learning bookdown and am also excited for some aspects of the bs4_book. I thought that, at worse case, my search bug might be moot after changing to a new theme, so I am curious as to when that might be.

Thanks!

I will also say that I am running RStudio on a server, so perhaps that is interfering?

I wonder if downloading the project to my local machine, running bookdown::render_book(), and then copying the resulting search_index.json back to the RStudio server session would work. Does that sound like a reasonable thing to attempt? (I'd attempt it myself without asking that question if I didn't have to invoke the help of our IT department for some admin permissions.)

The empty json file explains why the search is not working. There is nothing to search into.
So the issue is why this file is empty when it should be field. :thinking:

It would be interesting if you could try to download locally and try to build the book to see if this is an issue with the server.

There seems to be something related to the issue you link to that strip all the content instead of only the html part (tags, ...) of the file. Leading to an empty file.

I'll try to reproduce on RStudio cloud to see if this is an issue with a server, but it could be a configuration issue as in the issue you linked to.

Regarding bs4_book(), I think we should make a release this month. If you want to use this theme, the search mechanism is different so yes it could work already. You can try if you want by installing the dev version from github (or downloading then installing).

Thanks, @cderv! I'll get started on getting a local R installation so I can try one version of this hypothesis.

Details of our server configuration would be entirely over my head so I don't think I can provide useful information from here, but I appreciate you looking into it via RStudio cloud.

How do I install the dev version from github? I tried devtools::install_github("rstudio/bookdown") but that results in version 0.21.6.

Many thanks for your patience.

You got it right and got the correct version. bs4_bookshould be available

Thanks! I didn't realize that bs4_book was already in the 0.21.6. Search still didn't work for me there and enough formatting changed for me that I think I'll stick with gitbook.

But I did manage to create an appropriate search_index.json file on local RStudio -- so the blank file does seem to be related to my RStudio server session somehow. I can definitely use this .json file as a temporary fix.

Thank you again for your help with this!

I tried to reproduce on RStudio Cloud without success. I used a demo project.
You can try to build your project to see if you can reproduce there too or if this is only something related to your environment.

If you are willing to dig further to understand, you can enter debug mode then build the book and debug step by step.

debug(bookdown:::write_search_data)
bookdown::render_book(".")
# it will stop when writing the search data.
# You can go step by step inside function to see why it does not write anything

This could help find which line in this make all the content disappear.

Some help about debugging




@cderv Thank you for trying this in the Cloud!

I had no idea how many debugging tools there were out there until Jenny Bryan's talk -- which is to say that now I am aware of them though haven't used them yet. This is a good opportunity to change that, I suppose! Thanks for linking to the resources!

Thanks so much for writing out the debug steps -- since the failure is a blank file rather than a semi-informative error message, I would not have any idea where to begin.

1 Like

Yes that is the hardest! It is not a hard red message bug ! Just something that is supposed to work and that fails silently. If you debug and find the line that removes everything, I will be happy to see if we could detect that and add a warning ! Or fix the issue would be best!