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 doesn't work #12

Closed
Rmadillo opened this issue Nov 3, 2016 · 21 comments
Closed

Search function doesn't work #12

Rmadillo opened this issue Nov 3, 2016 · 21 comments

Comments

@Rmadillo
Copy link

Rmadillo commented Nov 3, 2016

Compiling this example doesn't allow search to work.

Saved and extracted zip file.
Opened project in R Studio 1.0.44 (with R 3.3.1).
Opened index.Rmd.
Clicked Build Book.
Site and pdf are created just fine, but search doesn't work. Other menu bar buttons do work.

Adding search: yes to _output.yml doesn't let it work.

Played with other bookdown books, search does work. Copied those _output.yml files' content over, search still doesn't work. Not sure where to look next to allow search to work.

@yihui
Copy link
Member

yihui commented Nov 3, 2016

You don't need search: yes because searching is enabled by default.

What do you mean by "doesn't work"? No search button? Typed in the search box but nothing happened? A screenshot will be helpful. Are you viewing the HTML output in RStudio Viewer or an external browser? Searching won't work for the latter case unless you serve the HTML output with a web server.

@Rmadillo
Copy link
Author

Rmadillo commented Nov 3, 2016

Oh, OK, got it. Viewing in external browser--so it won't work locally. Sorry!

@Rmadillo Rmadillo closed this as completed Nov 3, 2016
@yihui
Copy link
Member

yihui commented Nov 4, 2016

You can serve the book locally and search button will function, e.g. use the addin "Preview Book": https://bookdown.org/yihui/bookdown/rstudio-ide.html

@ShKlinkenberg
Copy link

@yihui it does seem that the search option is showing some buggy behavior. I'm hosting a book on: https://shklinkenberg.github.io/Interactive_Teaching_Techniques/index.html#

I got search working by first building the book and then saving the _output.yml file by making a minor change (adding a white space). Then without rebuilding and committing and pushing this to github, it worked.

But if I rebuild, then clicking the search icon does not make the search field appear. I'm not testing local, only on github.io

@cphthomas
Copy link

Hi @yihui, I am also experiencing some problems with the search option. I have a page https://jura.tepedu.dk
When i type f or click the search icon I am not getting the search box anymore it used to work. any ideas :O)

@yihui
Copy link
Member

yihui commented Jul 17, 2019

@cphthomas Please make sure you are using the latest version of bookdown to compile the book.

@cphthomas
Copy link

Hi @yihui, thanks for your quick reply :O) I'm building the book on rstudio.cloud using:
Package: bookdown
Type: Package
Title: Authoring Books and Technical Documents with R Markdown
Version: 0.9

@yihui
Copy link
Member

yihui commented Jul 17, 2019

@cphthomas 0.9 is not the latest: https://cran.rstudio.com/web/packages/bookdown/

@cphthomas
Copy link

Hi @yihui, thanks a lot, and thank you for a wonderful package :O)

@wlandau
Copy link

wlandau commented Jul 11, 2020

I am encountering this issue with version 0.20 when I render https://github.com/yihui/bookdown-minimal locally. Can anyone else reproduce this? Related: ropensci-books/drake#165.

@yihui
Copy link
Member

yihui commented Jul 12, 2020

@wlandau It's not reproducible to me. Please see #12 (comment). The search button won't work if you open index.html. You have to view the book via a server.

@wlandau
Copy link

wlandau commented Jul 12, 2020

Thanks Yihui, all my search bars work locally when I run a server.

@wlandau
Copy link

wlandau commented Jul 13, 2020

In both my case and that of @ShKlinkenberg, I think this is caused by an invalid search_index.json. Plugging https://github.com/ShKlinkenberg/Interactive_Teaching_Techniques/blob/master/docs/search_index.json and https://github.com/ropensci-books/drake/blob/f5c580623cfe8d36478aa41662c25dcc1f63d134/search_index.json into https://jsonlint.com/ expose lints. When I manually switch to a valid search_index.json in ropensci-books/drake@6654d20, the search bar starts working.

In my case, I think the problem is that search_index.json cannot handle special characters from crayon, so I need to set options(crayon.enabled = FALSE) in all the chapters. In @ShKlinkenberg's case, there is a mysterious special character just before the ## Student Questions header in interaction-through-homework.html. In interaction-through-homework.Rmd, there is a dot before the ## in the header title (i.e. �## Student Questions). Removing it and rerunning bookdown::render_book() fixes the search bar.

So I think somewhere in the stack, the text in search_index.json should be converted to an encoding that can be parsed.

@yihui
Copy link
Member

yihui commented Jul 24, 2020

Now it should be fixed via

remotes::install_github('rstudio/bookdown')

Thanks!

@ShKlinkenberg
Copy link

ShKlinkenberg commented Aug 11, 2020 via email

@yihui
Copy link
Member

yihui commented Aug 11, 2020

@ShKlinkenberg Good to know! I'll make a CRAN release in a couple of weeks. Thanks for confirming!

@Shuliyey
Copy link

Shuliyey commented Oct 28, 2020

does search bar support all languages, i did some test, searching Chinese Characters, doesn't seem to work

@Shuliyey
Copy link

Shuliyey commented Oct 28, 2020

i did some research i found this thread rstudio/bookdown#387 conclusion seem to be doesn't work with CJK characters, and it's related to gitbook implementation

also found this https://github.com/rstudio/bookdown/blob/ee96e467b021045a858f3fb198df27965146f287/inst/resources/gitbook/js/plugin-search.js#L8-L29

    function loadIndex(data) {
        // [Yihui] In bookdown, I use a character matrix to store the chapter
        // content, and the index is dynamically built on the client side.
        // Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search
        // We can certainly do that via R packages V8 and jsonlite, but let's
        // see how slow it really is before improving it. On the other hand,
        // lunr cannot handle non-English text very well, e.g. the default
        // tokenizer cannot deal with Chinese text, so we may want to replace
        // lunr with a dumb simple text matching approach.
        index = lunr(function () {
          this.ref('url');
          this.field('title', { boost: 10 });
          this.field('body');
        });
        data.map(function(item) {
          index.add({
            url: item[0],
            title: item[1],
            body: item[2]
          });
        });
    }

seems to be a functionality related to Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search

@Shuliyey
Copy link

Shuliyey commented Oct 28, 2020

interesting so it seems to be the lunr.js doesn't support CJK - olivernn/lunr.js#173

there's this repo that support multi language but i don't see Chinese https://github.com/MihaiValentin/lunr-languages

there's this https://github.com/Wiredcraft/lunr-chinese, this one might work for chinese


another possible solution is https://github.com/krisk/fuse (fuse.js) this works well with all languages

image
image

https://fusejs.io/demo.html

when i find some time I will submit a PR

@cderv
Copy link
Collaborator

cderv commented Oct 28, 2020

IMO fuse.js is definitely something we should consider. This was mentioned in rstudio/bookdown#975
If it supports all language, this is another good point.

Before doing anything PR related, you should open an issue so that we can discuss this type of change.

Thanks for sharing this and the suggestion BTW !

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

No branches or pull requests

7 participants