Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Dec 27, 2023
1 parent 8969ef4 commit 60f6eae
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Index {
for term_frame in hpo_doc
.entities()
.iter()
.flat_map(fastobo::ast::EntityFrame::as_term)
.filter_map(fastobo::ast::EntityFrame::as_term)
{
let mut doc = tantivy::Document::default();

Expand All @@ -105,7 +105,11 @@ impl Index {
ident_to_string(term_frame.id().as_inner().as_ref()),
);

for line in term_frame.clauses().iter().map(|l| l.as_inner()) {
for line in term_frame
.clauses()
.iter()
.map(fastobo::ast::Line::as_inner)
{
match line {
fastobo::ast::TermClause::Name(name) => {
doc.add_field_value(schema.get_field("name")?, name.as_str());
Expand Down
1 change: 0 additions & 1 deletion src/server/actix_server/hpo_genes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl ResultEntry {
.map(|term| ResultHpoTerm {
term_id: term.id().to_string(),
name: term.name().to_string(),
..Default::default()
})
.collect::<Vec<_>>();
terms.sort();
Expand Down
1 change: 0 additions & 1 deletion src/server/actix_server/hpo_omims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl ResultEntry {
ResultHpoTerm {
term_id: term.id().to_string(),
name: term.name().to_string(),
..Default::default()
}
})
.collect::<Vec<_>>();
Expand Down
13 changes: 7 additions & 6 deletions src/server/actix_server/hpo_terms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ impl ResultEntry {

let definition = doc
.get_all(field_def)
.flat_map(|f| f.as_text().map(|s| s.to_string()))
.filter_map(|f| f.as_text().map(std::string::ToString::to_string))
.collect::<Vec<_>>();
let definition = definition.first().map(|s| s.clone());
let definition = definition.first().map(std::clone::Clone::clone);
let synonyms = doc
.get_all(field_synonym)
.flat_map(|f| f.as_text().map(|s| s.to_string()))
.filter_map(|f| f.as_text().map(std::string::ToString::to_string))
.collect::<Vec<_>>();
let synonyms = if synonyms.is_empty() {
None
Expand All @@ -151,7 +151,7 @@ impl ResultEntry {
};
let xrefs = doc
.get_all(field_xref)
.flat_map(|f| f.as_text().map(|s| s.to_string()))
.filter_map(|f| f.as_text().map(std::string::ToString::to_string))
.collect::<Vec<_>>();
let xrefs = if xrefs.is_empty() { None } else { Some(xrefs) };

Expand Down Expand Up @@ -199,6 +199,7 @@ struct Container {
///
/// In the case that there is an error running the server.
#[allow(clippy::unused_async)]
#[allow(clippy::too_many_lines)]
#[get("/hpo/terms")]
async fn handle(
data: Data<WebServerData>,
Expand Down Expand Up @@ -277,8 +278,8 @@ async fn handle(
query_parser.set_field_fuzzy(field_synonym, true, 1, true);
query_parser
};
let index_query = query_parser.parse_query(&name).map_err(|e| {
eprintln!("{}", e);
let index_query = query_parser.parse_query(name).map_err(|e| {
eprintln!("{e}");
CustomError::new(anyhow::anyhow!("Error parsing query: {}", e))
})?;
let top_docs = searcher
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn run(args_common: &crate::common::Args, args: &Args) -> Result<(), anyhow:

tracing::info!("Loading HPO OBO...");
let before_load_obo = std::time::Instant::now();
let hpo_doc = fastobo::from_file(&format!("{}/{}", &args.path_hpo_dir, "hp.obo"))
let hpo_doc = fastobo::from_file(format!("{}/{}", &args.path_hpo_dir, "hp.obo"))
.map_err(|e| anyhow::anyhow!("Error loading HPO OBO: {}", e))?;
tracing::info!(
"... done loading HPO OBO in {:?}",
Expand Down

0 comments on commit 60f6eae

Please sign in to comment.