This commit is contained in:
Alex Wied
2026-06-09 10:36:13 -04:00
parent 6906fb973a
commit d0dc1b277d
4 changed files with 34 additions and 54 deletions
+6 -30
View File
@@ -7,7 +7,7 @@ use tantivy::directory::{ManagedDirectory, MmapDirectory};
use tantivy::query::{BooleanQuery, Occur, QueryParser, TermQuery};
use tantivy::schema::{Field, IndexRecordOption, Value};
use tantivy::tokenizer::{NgramTokenizer, TokenizerManager};
use tantivy::{Index, IndexReader, IndexWriter, ReloadPolicy, TantivyDocument, Term, doc};
use tantivy::{Index, IndexReader, IndexWriter, ReloadPolicy, TantivyDocument, Term};
#[derive(Default)]
pub struct SearchIndexBuilder {
@@ -62,40 +62,16 @@ impl SearchIndex {
SearchIndexBuilder::default()
}
pub fn remove_all_annotated_iris(&mut self) {
self.writer
.delete_term(Term::from_field_u64(Schema::type_field(), 0u64));
self.writer.commit().unwrap();
}
pub fn add_annotated_iri(
&self,
iri: &str,
label: Option<&str>,
comment: Option<&str>,
) -> crate::Result<()> {
let mut document = doc!(
Schema::type_field() => 0u64,
Schema::iri_field() => iri,
);
if let Some(label) = label {
document.add_text(Schema::label_field(), label.to_lowercase());
}
if let Some(comment) = comment {
document.add_text(Schema::comment_field(), comment);
}
self.writer.add_document(document)?;
Ok(())
}
pub fn add<'a>(&self, document: TantivyDocument) -> crate::Result<()> {
self.writer.add_document(document)?;
Ok(())
}
pub fn remove_all_of_type(&mut self, type_: u64) {
self.writer
.delete_term(Term::from_field_u64(Schema::type_field(), type_));
}
pub fn commit(&mut self) -> crate::Result<()> {
self.writer.commit()?;
Ok(())