This commit is contained in:
Alex Wied
2026-06-09 20:09:16 -04:00
parent b53a3ad1e0
commit f1abcb56ea
3 changed files with 51 additions and 98 deletions
+30 -27
View File
@@ -19,12 +19,10 @@ use ldp::reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use ldp::traverse::Traverse;
use ldp::{RdfSource, RdfSourceUpdateResponse, ResourceRequestBuilder, SerializationOptions};
use oxigraph::io::RdfFormat;
use oxigraph::model::vocab::rdf;
use oxigraph::model::vocab::{rdf, rdfs};
use oxigraph::model::{BaseDirection, Dataset, NamedNode, Quad, Term, TermRef};
use tracing::{debug, error};
const ANNOTATED_IRI_TYPE: u64 = 0;
#[derive(Debug, Clone)]
pub(crate) enum Message {
None,
@@ -106,25 +104,26 @@ impl Publisher {
.build()
.expect("Failed to build search index");
index.remove_all_of_type(ANNOTATED_IRI_TYPE);
ontology.for_each_annotated_iri(|iri, label, comment| {
let mut document = doc!(
Schema::type_field() => ANNOTATED_IRI_TYPE,
Schema::iri_field() => iri,
);
if let Some(id) = ontology.catalog_id(&rdf::PROPERTY.into_owned()) { index.remove_all_of_type(id); }
if let Some(id) = ontology.catalog_id(&rdfs::CLASS.into_owned()) { index.remove_all_of_type(id); }
for (iri, info) in ontology.iri_info() {
if let Some(type_) = ontology.catalog_id(&info.type_) {
let mut document = doc!(
Schema::type_field() => type_,
Schema::iri_field() => iri.as_str(),
);
if let Some(label) = label {
document.add_text(Schema::field("label"), label.to_lowercase());
if let Some(label) = &info.label {
document.add_text(Schema::field("label"), label.to_lowercase());
}
if let Some(comment) = &info.comment {
document.add_text(Schema::field("comment"), comment.to_lowercase());
}
index.add(document).expect("Unable to add annotated IRI to search index");
}
if let Some(comment) = comment {
document.add_text(Schema::field("comment"), comment.to_lowercase());
}
index
.add(document)
.expect("Unable to add annotated IRI to search index");
});
}
index.commit().expect("Unable to commit ontology to index");
let mut abbreviated_datatypes = ontology
@@ -181,11 +180,8 @@ impl Publisher {
.chain(Task::done(Message::CommitIndex));
}
Message::IndexRdfSource(rdf_source) => {
let catalog_id = rdf_source
.classes()
.filter_map(|class| self.ontology.catalog_id(&class.into_owned()))
.next();
if let Some(catalog_id) = catalog_id {
for catalog_id in rdf_source.classes()
.filter_map(|class| self.ontology.catalog_id(&class.into_owned())) {
let mut document = SearchDocument::new();
document.add_u64(Schema::type_field(), catalog_id);
document.add_text(Schema::iri_field(), rdf_source.origin());
@@ -322,9 +318,15 @@ impl Publisher {
}
Message::QueryUpdated(new_query) => {
if let Some(search_state) = &mut self.search_state {
let type_ = match search_state.action {
SearchResultClickAction::Predicate(_) => self.ontology.catalog_id(&rdf::PROPERTY.into_owned()),
SearchResultClickAction::Object(_) => self.ontology.catalog_id(&rdfs::CLASS.into_owned()),
SearchResultClickAction::URLInput => None,
};
search_state.results = self
.index
.query(0, new_query.as_str(), Schema::all_fields())
.query(type_, new_query.as_str(), Schema::all_fields())
.expect("Error encountered while querying index")
.iter()
.map(NamedNode::new_unchecked)
@@ -676,7 +678,8 @@ impl Publisher {
let header_text = self
.ontology
.info(result.as_ref())
.map(|info| info.type_.to_string())
.and_then(|info| self.ontology.info(info.type_.as_ref()))
.and_then(|info| info.label.clone())
.unwrap_or("Unknown".to_string());
button(text(header_text))