Coder Social home page Coder Social logo

Comments (21)

cderv avatar cderv commented on June 20, 2024 3

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 !

from bookdown-demo.

ShKlinkenberg avatar ShKlinkenberg commented on June 20, 2024 1

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024 1

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

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024

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.

from bookdown-demo.

Rmadillo avatar Rmadillo commented on June 20, 2024

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

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024

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

from bookdown-demo.

ShKlinkenberg avatar ShKlinkenberg commented on June 20, 2024

@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

from bookdown-demo.

cphthomas avatar cphthomas commented on June 20, 2024

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)

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024

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

from bookdown-demo.

cphthomas avatar cphthomas commented on June 20, 2024

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

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024

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

from bookdown-demo.

cphthomas avatar cphthomas commented on June 20, 2024

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

from bookdown-demo.

wlandau avatar wlandau commented on June 20, 2024

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.

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024

@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.

from bookdown-demo.

wlandau avatar wlandau commented on June 20, 2024

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

from bookdown-demo.

ShKlinkenberg avatar ShKlinkenberg commented on June 20, 2024

from bookdown-demo.

wlandau avatar wlandau commented on June 20, 2024

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.

from bookdown-demo.

yihui avatar yihui commented on June 20, 2024

Now it should be fixed via

remotes::install_github('rstudio/bookdown')

Thanks!

from bookdown-demo.

Shuliyey avatar Shuliyey commented on June 20, 2024

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

from bookdown-demo.

Shuliyey avatar Shuliyey commented on June 20, 2024

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

from bookdown-demo.

Shuliyey avatar Shuliyey commented on June 20, 2024

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

from bookdown-demo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.