2026-06-08 19:33:49 -04:00
|
|
|
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(|| {
|
2026-06-17 20:50:26 -04:00
|
|
|
let stored_ngram32 = TextOptions::default().set_indexing_options(
|
2026-06-08 19:33:49 -04:00
|
|
|
TextFieldIndexing::default()
|
|
|
|
|
.set_index_option(IndexRecordOption::WithFreqsAndPositions)
|
|
|
|
|
.set_tokenizer("ngram_32"),
|
2026-06-17 20:50:26 -04:00
|
|
|
).set_stored();
|
2026-06-08 19:33:49 -04:00
|
|
|
|
2026-06-17 20:50:26 -04:00
|
|
|
let stored_en_stem = TextOptions::default().set_indexing_options(
|
2026-06-08 19:33:49 -04:00
|
|
|
TextFieldIndexing::default()
|
|
|
|
|
.set_index_option(IndexRecordOption::WithFreqsAndPositions)
|
|
|
|
|
.set_tokenizer("en_stem"),
|
2026-06-17 20:50:26 -04:00
|
|
|
).set_stored();
|
2026-06-08 19:33:49 -04:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2026-06-17 20:50:26 -04:00
|
|
|
schema_builder.add_text_field("label", stored_ngram32.clone());
|
|
|
|
|
schema_builder.add_text_field("comment", stored_en_stem.clone());
|
2026-06-08 19:33:49 -04:00
|
|
|
|
2026-06-23 21:55:52 -04:00
|
|
|
/*schema_builder.add_text_field("nomen", stored_ngram32.clone());
|
2026-06-17 20:50:26 -04:00
|
|
|
schema_builder.add_text_field("givenName", stored_ngram32.clone());
|
2026-06-23 21:55:52 -04:00
|
|
|
schema_builder.add_text_field("surname", stored_ngram32);*/
|
2026-06-17 20:50:26 -04:00
|
|
|
|
|
|
|
|
/*schema_builder.add_text_field("title", en_stem.clone());
|
2026-06-08 19:33:49 -04:00
|
|
|
schema_builder.add_text_field("description", en_stem.clone());
|
2026-06-17 20:50:26 -04:00
|
|
|
schema_builder.add_text_field("content", en_stem);*/
|
2026-06-08 19:33:49 -04:00
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 10:36:13 -04:00
|
|
|
pub fn field(name: &str) -> Field {
|
|
|
|
|
Schema::schema()
|
|
|
|
|
.get_field(name)
|
|
|
|
|
.expect("Field not found in schema")
|
2026-06-08 19:33:49 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-09 10:36:13 -04:00
|
|
|
pub fn all_fields() -> Vec<Field> {
|
2026-06-09 17:20:46 -04:00
|
|
|
Self::schema().fields().map(|(field, _)| field).collect()
|
2026-06-08 19:33:49 -04:00
|
|
|
}
|
|
|
|
|
}
|