From f1499a583f7730c9133a56c0419a3a0fff7bb3a5 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 9 Aug 2021 11:24:37 -0700 Subject: initial fatcat_refs search index support --- fatcat-cli/src/commands.rs | 14 ++++++++++++++ fatcat-cli/src/lib.rs | 2 ++ fatcat-cli/src/main.rs | 5 +++++ fatcat-cli/src/search.rs | 15 +++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/fatcat-cli/src/commands.rs b/fatcat-cli/src/commands.rs index 8ef6bb0..5b456d7 100644 --- a/fatcat-cli/src/commands.rs +++ b/fatcat-cli/src/commands.rs @@ -295,6 +295,9 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) SearchEntityType::Scholar => { writeln!(tw, "key\ttype\tstage\tyear\tcontainer_name\ttitle")?; } + SearchEntityType::Reference => { + writeln!(tw, "source\tkey\tprovenance\tstatus\ttarget")?; + } } for hit in results { let hit = hit?; @@ -348,6 +351,17 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) hit["biblio"]["title"].as_str().unwrap_or("-"), )?; } + SearchEntityType::Reference => { + writeln!( + tw, + "{}\t{}\t{}\t{}\t{}", + hit["source_release_ident"].as_str().unwrap_or("-"), + hit["ref_key"].as_str().unwrap_or("-"), + hit["match_provenance"].as_str().unwrap_or("-"), + hit["match_status"].as_str().unwrap_or("-"), + hit["target_release_ident"].as_str().unwrap_or("-"), + )?; + } } } tw.flush()?; diff --git a/fatcat-cli/src/lib.rs b/fatcat-cli/src/lib.rs index 6fd7b61..e8b112f 100644 --- a/fatcat-cli/src/lib.rs +++ b/fatcat-cli/src/lib.rs @@ -58,6 +58,7 @@ pub enum SearchEntityType { Container, File, Scholar, + Reference, } impl FromStr for SearchEntityType { @@ -69,6 +70,7 @@ impl FromStr for SearchEntityType { "container" | "containers" => Ok(SearchEntityType::Container), "file" | "files" => Ok(SearchEntityType::File), "scholar" | "fulltext" => Ok(SearchEntityType::Scholar), + "ref" | "refs" | "references" => Ok(SearchEntityType::Reference), _ => Err(anyhow!("invalid entity type : {}", s)), } } diff --git a/fatcat-cli/src/main.rs b/fatcat-cli/src/main.rs index bdab729..9e995d2 100644 --- a/fatcat-cli/src/main.rs +++ b/fatcat-cli/src/main.rs @@ -665,6 +665,11 @@ fn run(opt: Opt) -> Result<()> { "entity schema output not supported for scholar index" )); } + (false, true, SearchEntityType::Reference) => { + return Err(anyhow!( + "entity schema output not supported for references index" + )); + } } } } diff --git a/fatcat-cli/src/search.rs b/fatcat-cli/src/search.rs index 7d03f6f..0dea37f 100644 --- a/fatcat-cli/src/search.rs +++ b/fatcat-cli/src/search.rs @@ -80,6 +80,7 @@ pub fn crude_search( SearchEntityType::Container => "fatcat_container", SearchEntityType::File => "fatcat_file", SearchEntityType::Scholar => "scholar_fulltext", + SearchEntityType::Reference => "fatcat_ref", }; let http_client = reqwest::blocking::Client::builder() .timeout(Duration::from_secs(10)) @@ -218,6 +219,20 @@ pub fn crude_search( "sort": [ sort_mode ], "track_total_hits": true, }), + SearchEntityType::Reference => json!({ + "query": { + "query_string": { + "query": query, + "default_operator": "AND", + "analyze_wildcard": true, + "allow_leading_wildcard": false, + "lenient": true, + }, + }, + "size": size, + "sort": [ sort_mode ], + "track_total_hits": true, + }), }.to_string(); let mut request = http_client -- cgit v1.2.3