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 breaks for some search terms #127

Closed
straight-shoota opened this issue Oct 9, 2017 · 2 comments · Fixed by #433
Closed

Search breaks for some search terms #127

straight-shoota opened this issue Oct 9, 2017 · 2 comments · Fixed by #433
Labels
bug site-generator Issues concerning Gitbook and the way this book is generated

Comments

@straight-shoota
Copy link
Member

Search usually works fine but for some search terms it fails and there are no results nor error messages on the page. For example, search for char
The JavaScript console shows this error:

lunr.min.js:7 Uncaught TypeError: Cannot read property 'tf' of undefined
    at t.Index.documentVector (lunr.min.js:7)
    at t.Index.<anonymous> (lunr.min.js:7)
    at Array.map (<anonymous>)
    at t.SortedSet.map (lunr.min.js:7)
    at t.Index.search (lunr.min.js:7)
    at LunrSearchEngine.search (search-lunr.js:34)
    at Object.query (search-engine.js:31)
    at launchSearch (search.js:79)
    at handleUpdate (search.js:121)
    at HTMLInputElement.<anonymous> (search.js:142)

According to olivernn/lunr.js#243 this might be caused by lunr.js having issues with unicode codepoints like emojis. There is an emoji (🔮) in the book on both pages about char and string literals and it fails to search for any terms that appear on one of these pages. I am not 100% sure about it, but this looks like strong evidence.

This failure should be fixed in lunar.js but until then, we should try to find a workaround for Crystal Book.
I think we could just remove the emojis from the pages. It's nice to have them there but they're not essential. Perhaps we could also manually remove them from the search index.

@straight-shoota
Copy link
Member Author

It's possible to encode the emoji with &#x1F52E;, but that will be escaped in a fenced code block.
But it works in plain text and enables search.

straight-shoota added a commit to straight-shoota/crystal-book that referenced this issue Oct 9, 2017
Lunr.js can't handle emojis in the search index, this workaround encodes the emoji as html numerical character reference.
Unfortunately this woni't work inside fenced code blocks.

See crystal-lang#127 for details.
RX14 pushed a commit that referenced this issue Nov 7, 2017
Lunr.js can't handle emojis in the search index, this workaround encodes the emoji as html numerical character reference.
Unfortunately this woni't work inside fenced code blocks.

See #127 for details.
@straight-shoota straight-shoota added bug site-generator Issues concerning Gitbook and the way this book is generated labels Jan 2, 2019
@straight-shoota straight-shoota linked a pull request Nov 29, 2020 that will close this issue
10 tasks
@straight-shoota
Copy link
Member Author

Fixed by #433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug site-generator Issues concerning Gitbook and the way this book is generated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant