66 lines
2.3 KiB
Rust
66 lines
2.3 KiB
Rust
use std::sync::OnceLock;
|
|
use tantivy::schema;
|
|
use tantivy::schema::{
|
|
Field, IndexRecordOption, Schema as TantivySchema, TextFieldIndexing, TextOptions,
|
|
};
|
|
|
|
static SCHEMA: OnceLock<TantivySchema> = OnceLock::new();
|
|
|
|
pub struct Schema;
|
|
|
|
impl Schema {
|
|
pub fn schema() -> &'static TantivySchema {
|
|
SCHEMA.get_or_init(|| {
|
|
let ngram_32 = TextOptions::default().set_indexing_options(
|
|
TextFieldIndexing::default()
|
|
.set_index_option(IndexRecordOption::WithFreqsAndPositions)
|
|
.set_tokenizer("ngram_32"),
|
|
);
|
|
|
|
let en_stem = TextOptions::default().set_indexing_options(
|
|
TextFieldIndexing::default()
|
|
.set_index_option(IndexRecordOption::WithFreqsAndPositions)
|
|
.set_tokenizer("en_stem"),
|
|
);
|
|
|
|
let mut schema_builder = TantivySchema::builder();
|
|
schema_builder.add_u64_field("type", schema::FAST | schema::INDEXED);
|
|
schema_builder.add_text_field("iri", schema::STORED | schema::STRING);
|
|
schema_builder.add_text_field("label", ngram_32.clone());
|
|
schema_builder.add_text_field("comment", en_stem.clone());
|
|
|
|
schema_builder.add_text_field("given name", ngram_32.clone());
|
|
schema_builder.add_text_field("surname", ngram_32);
|
|
|
|
schema_builder.add_text_field("title", en_stem.clone());
|
|
schema_builder.add_text_field("description", en_stem.clone());
|
|
schema_builder.add_text_field("content", en_stem);
|
|
|
|
schema_builder.add_u64_field("page", schema::STORED);
|
|
schema_builder.add_u64_field("book", schema::STORED);
|
|
schema_builder.add_u64_field("chapter", schema::STORED);
|
|
schema_builder.add_u64_field("verse", schema::STORED);
|
|
|
|
schema_builder.build()
|
|
})
|
|
}
|
|
|
|
pub fn type_field() -> Field {
|
|
Self::schema().get_field("type").unwrap()
|
|
}
|
|
|
|
pub fn iri_field() -> Field {
|
|
Self::schema().get_field("iri").unwrap()
|
|
}
|
|
|
|
pub fn field(name: &str) -> Field {
|
|
Schema::schema()
|
|
.get_field(name)
|
|
.expect("Field not found in schema")
|
|
}
|
|
|
|
pub fn all_fields() -> Vec<Field> {
|
|
Self::schema().fields().map(|(field, _)| field).collect()
|
|
}
|
|
}
|