Skip to content

If !search_config.copy_js, then perform useless search indexing, and search is disabled #2403

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

Open
SichangHe opened this issue Jun 21, 2024 · 0 comments
Labels
C-bug Category: A bug, incorrect or unintended behavior

Comments

@SichangHe
Copy link

Problem

let index = write_to_json(index, search_config, doc_urls)?;
debug!("Writing search index ✓");
if index.len() > 10_000_000 {
warn!("searchindex.json is very large ({} bytes)", index.len());
}
if search_config.copy_js {
utils::fs::write_file(destination, "searchindex.json", index.as_bytes())?;
utils::fs::write_file(
destination,
"searchindex.js",
format!("Object.assign(window.search, {});", index).as_bytes(),
)?;

Here, if !search_config.copy_js, then index is not used, so the above expensive computation is wasted.

More importantly, since the search index is not written, the search feature does not work.
That is, search is only enabled if search_config.enable && search_config.copy_js, instead of the intended behavior of just depending on search_config.enable.

Steps

N/A

Possible Solution(s)

The name copy_js seems to suggest the use of a CDN if set to false, however, looking at

{{#if search_js}}
, the links to a CDN seems to be missing. If so, then the solution would be:

  1. Add the CDN links of the search JS to the index.hbs file and enable them when search_config.enable && !search_config.copy_js.
  2. Correct create_files to write the index JSON file when !search_config.copy_js.

However, if !search_config.copy_js disabling the search entirely is the intended behavior (which would be weird), then maybe we should just get rid of it and fully rely on search_config.enable.

Notes

Additionally, the search index is unnecessarily duplicated in both searchindex.json and searchindex.js, which are sequentially tentatively queried by searcher.js.

Version

Please see the permalink above pointing to the latest master as of this writing.
@SichangHe SichangHe added the C-bug Category: A bug, incorrect or unintended behavior label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: A bug, incorrect or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant