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][I18n] Bad search_index.{{lang}}.js content if lang is not en #1740

Closed
pcoves opened this issue Jan 20, 2022 · 9 comments
Closed

[Search][I18n] Bad search_index.{{lang}}.js content if lang is not en #1740

pcoves opened this issue Jan 20, 2022 · 9 comments
Labels
documentation done in pr Already done in a PR

Comments

@pcoves
Copy link

pcoves commented Jan 20, 2022

Bug Report

Environment

Zola version: 0.15 (was already present in 0.14)

Expected Behavior

Generation of the search_index.{{lang}}.js should not post-fix pipelines array with -{{lang}}.

Current Behavior

When you set the default language to "en" and generate the search index you have something like "pipeline":["trimmer","stopWordFilter","stemmer"] close to the file's beginning.

But if you set de default language to, say, "fr" you get such a content: "pipeline":["trimmer-fr","stopWordFilter-fr","stemmer-fr"].
Not the -fr post-fixes.

Now, if you ever add the following lines to a template file:

<script src="{{ get_url(path="/elasticlunr.min.js") }}"></script>
<script src="{{ get_url(path="/search_index." ~ lang ~ ".js") }}"></script>
<script src="{{ get_url(path="/search.js") }}"></script>

With search.js containing the single following line:

const index = elasticlunr.Index.load(window.searchIndex);

You get the following error: Uncaught Error: Cannot load un-registered function: trimmer-fr.

Removing all -{{ lang }} in the search_index.{{lang}}.js solves the problem.

@pcoves
Copy link
Author

pcoves commented Jan 20, 2022

For what it's worth, changing this line from

let mut index = Index::with_language(language, &build_fields(&language_options.search));

to

let mut index = Index::with_language(Language::English, &build_fields(&language_options.search));

fixes the issue.

Not sure if it's the right approach tho.

@Keats
Copy link
Collaborator

Keats commented Jan 20, 2022

Can you try adding the French stemmer of elasticlunr to see if that solves it: https://github.com/MihaiValentin/lunr-languages ? Or https://github.com/weixsong/lunr-languages I'm not sure if the first one is meant to work with elasticlunr

@pcoves
Copy link
Author

pcoves commented Jan 20, 2022

To be fair I've no idea what you're asking me to do right now.

I'd gladly give it a try if I ever catch what you mean.

@Keats
Copy link
Collaborator

Keats commented Jan 20, 2022

Only the english version is built-in afaik, for other languages you need to add an additional JS like shown in https://github.com/weixsong/lunr-languages#in-a-web-browser

@pcoves
Copy link
Author

pcoves commented Jan 20, 2022

Okay, you mean to change the code in my zola site.
I thought you wanted me to patch an external dependency of zola itself.

I'll give it a try asap.

@pcoves
Copy link
Author

pcoves commented Jan 20, 2022

<script src="{{ get_url(path="/elasticlunr.min.js") }}"></script>
<script src="{{ get_url(path="/search_index." ~ lang ~ ".js") }}"></script>
<script src="{{ get_url(path="/lunr-languages/lunr.stemmer.support.js") }}"></script>
<script src="{{ get_url(path="/lunr-languages/lunr." ~ lang ~ ".js") }}"></script>
<script src="{{ get_url(path="/search.js") }}"></script>

It works just fine using https://github.com/weixsong/lunr-languages#in-a-web-browser.

Thanks a lot!

@pcoves pcoves closed this as completed Jan 20, 2022
@Keats Keats reopened this Jan 20, 2022
@Keats
Copy link
Collaborator

Keats commented Jan 20, 2022

Just re-opening to make sure it's added to the docs

@pcoves
Copy link
Author

pcoves commented Jan 20, 2022

I'm not really aware of licensing stuff but this repo is under MPL.

Do you have any idea if one could ship it with a zola generated website without issue?

@Keats
Copy link
Collaborator

Keats commented Jan 20, 2022

It should not be an issue

@Keats Keats added the done in pr Already done in a PR label Jan 23, 2022
Keats added a commit that referenced this issue Jan 23, 2022
mwcz pushed a commit to mwcz/zola that referenced this issue Mar 7, 2022
@Keats Keats closed this as completed in a9b4cc6 Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation done in pr Already done in a PR
Projects
None yet
Development

No branches or pull requests

2 participants