|
|
@@ -1,9 +1,10 @@ |
|
|
|
#[allow(unused_imports)] |
|
|
|
use std::str::FromStr; |
|
|
|
use std::collections::{HashMap, HashSet}; |
|
|
|
use chrono::{DateTime, Utc, NaiveDateTime, TimeZone}; |
|
|
|
use elasticlunr::{Index, Language}; |
|
|
|
use lazy_static::lazy_static; |
|
|
|
|
|
|
|
#[cfg(feature = "tantivy-indexing")] |
|
|
|
use chrono::{DateTime, Utc, NaiveDateTime, TimeZone}; |
|
|
|
#[allow(unused_imports)] |
|
|
|
use errors::{bail, Result, Error}; |
|
|
|
use library::{Library, Section}; |
|
|
@@ -105,7 +106,7 @@ fn parse_language(lang: &str) -> Option<tantivy::tokenizer::Language> { |
|
|
|
}), |
|
|
|
|
|
|
|
// apparently not a code, so this is best available option |
|
|
|
_ => serde_json::from_str::<tantivy::tokenizer::Language>(lang).ok() |
|
|
|
_ => serde_json::from_str::<tantivy::tokenizer::Language>(&format!("{{\"language\":\"{}\"}}", lang)).ok() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -176,6 +177,7 @@ pub fn build_tantivy_index<P: AsRef<std::path::Path>>( |
|
|
|
let empty_taxonomies: HashMap<String, Vec<String>> = Default::default(); |
|
|
|
|
|
|
|
for section in library.sections_values() { |
|
|
|
//eprintln!("section: {:?}, section.pages: {:?}", section, section.pages); |
|
|
|
|
|
|
|
// reason for macro: Section/Page are different types but have same attributes |
|
|
|
macro_rules! extract_content { |
|
|
@@ -187,6 +189,8 @@ pub fn build_tantivy_index<P: AsRef<std::path::Path>>( |
|
|
|
|
|
|
|
let cleaned_body: String = AMMONIA.clean(&$page.content).to_string(); |
|
|
|
|
|
|
|
//eprintln!("indexing {}", $page.permalink.as_str()); |
|
|
|
|
|
|
|
Some(IndexContent { |
|
|
|
title: $page.meta.title.as_ref().map(|x| x.as_str()).unwrap_or(""), |
|
|
|
description: $page.meta.description.as_ref().map(|x| x.as_str()).unwrap_or(""), |
|
|
@@ -198,6 +202,7 @@ pub fn build_tantivy_index<P: AsRef<std::path::Path>>( |
|
|
|
taxonomies: &empty_taxonomies, |
|
|
|
}) |
|
|
|
} else { |
|
|
|
//eprintln!("not indexing {}", $page.permalink.as_str()); |
|
|
|
None |
|
|
|
} |
|
|
|
}} |
|
|
|