Skip to content

Commit

Permalink
Implement "fallback" searching strategy and remove dedicated Chinese …
Browse files Browse the repository at this point in the history
…search support.
  • Loading branch information
Sunshine40 committed Jun 4, 2024
1 parent 30f9e71 commit a2ee372
Show file tree
Hide file tree
Showing 12 changed files with 1,126 additions and 252 deletions.
40 changes: 0 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ default = ["watch", "serve", "search"]
watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore", "dep:pathdiff", "dep:walkdir"]
serve = ["dep:futures-util", "dep:tokio", "dep:warp"]
search = ["dep:elasticlunr-rs", "dep:ammonia"]
search-non-english = ["search", "elasticlunr-rs/languages"]
search-non-english = ["search", "elasticlunr-rs/ar", "elasticlunr-rs/da", "elasticlunr-rs/de", "elasticlunr-rs/du",
"elasticlunr-rs/es", "elasticlunr-rs/fi", "elasticlunr-rs/fr", "elasticlunr-rs/hu", "elasticlunr-rs/it",
"elasticlunr-rs/ja", "elasticlunr-rs/ko", "elasticlunr-rs/no", "elasticlunr-rs/pt", "elasticlunr-rs/ro",
"elasticlunr-rs/ru", "elasticlunr-rs/sv", "elasticlunr-rs/tr"]

[[bin]]
doc = false
Expand Down
3 changes: 2 additions & 1 deletion guide/src/format/configuration/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ This is general information about your book.
key in the configuration file.
- **language:** The main language of the book, which is used as a language attribute `<html lang="en">` for example.
This is also used to derive the direction of text (RTL, LTR) within the book.
When `search-non-english` feature is enabled, this may change the behavior of the search functionality provided by the HTML renderer.
When it is specified to a non-English language, an alternative indexing / searching strategy would be applied to the search functionality provided by the HTML renderer.
When `search-non-english` feature is enabled, additional language-specific search support may kick in.
- **text-direction**: The direction of text in the book: Left-to-right (LTR) or Right-to-left (RTL). Possible values: `ltr`, `rtl`.
When not specified, the text direction is derived from the book's `language` attribute.

Expand Down
3 changes: 2 additions & 1 deletion guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ copy-js = true # include Javascript code for search
- **enable:** Enables the search feature. Defaults to `true`.
- **limit-results:** The maximum number of search results. Defaults to `30`.
- **teaser-word-count:** The number of words used for a search result teaser.
Defaults to `30`.
When `book.language` is set to a non-English language, this limit might
be exceeded in case too many keywords are matched. Defaults to `30`.
- **use-boolean-and:** Define the logical link between multiple search words. If
true, all search words must appear in each result. Defaults to `false`.
- **boost-title:** Boost factor for the search result score if a search word
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ impl Renderer for HtmlHandlebars {
{
let search = html_config.search.clone().unwrap_or_default();
if search.enable {
let language = book_config
.language
.as_deref()
.and_then(|lang| lang.parse().ok());
let language = match book_config.language.as_deref() {
None => Err("en".to_string()),
Some(language) => language.parse(),
};
#[allow(unused_variables)]
let extra_language_subtag =
super::search::create_files(&search, language, destination, book)?;
Expand Down
Loading

0 comments on commit a2ee372

Please sign in to comment.