From 4f4c1e78186ad9bcd77f3536ef30dd5a130ec2d7 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 10 Feb 2021 11:12:49 -0800 Subject: search: container and file indexes --- fatcat-cli/src/commands.rs | 32 +++++++++++++++++++++++++++++++- fatcat-cli/src/lib.rs | 8 ++++---- fatcat-cli/src/main.rs | 20 ++++++++++++++++++++ fatcat-cli/src/search.rs | 4 ++-- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/fatcat-cli/src/commands.rs b/fatcat-cli/src/commands.rs index 3074937..95b97a0 100644 --- a/fatcat-cli/src/commands.rs +++ b/fatcat-cli/src/commands.rs @@ -283,7 +283,18 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) "release_ident\ttype\tstage\tyear\tcontainer_name\ttitle" )?; } - //"ident\tissnl\tname" + SearchEntityType::Container=> { + writeln!( + tw, + "ident\tissnl\tname" + )?; + } + SearchEntityType::File => { + writeln!( + tw, + "ident\tsha1\tsize\tmimetype" + )?; + } } for hit in results { let hit = hit?; @@ -300,6 +311,25 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) hit["title"].as_str().unwrap_or("-"), )?; } + SearchEntityType::Container => { + writeln!( + tw, + "{}\t{}\t{}", + hit["ident"].as_str().unwrap_or("-"), + hit["issnl"].as_str().unwrap_or("-"), + hit["name"].as_str().unwrap_or("-"), + )?; + } + SearchEntityType::File => { + writeln!( + tw, + "{}\t{}\t{}\t{}", + hit["ident"].as_str().unwrap_or("-"), + hit["sha1"].as_str().unwrap_or("-"), + hit["size"].as_u64().map_or("-".to_string(), |v| v.to_string()), + hit["mimetype"].as_str().unwrap_or("-"), + )?; + } } } tw.flush()?; diff --git a/fatcat-cli/src/lib.rs b/fatcat-cli/src/lib.rs index 8706774..1657d8d 100644 --- a/fatcat-cli/src/lib.rs +++ b/fatcat-cli/src/lib.rs @@ -56,8 +56,8 @@ impl FromStr for EntityType { #[derive(Debug, PartialEq, Clone, Copy)] pub enum SearchEntityType { Release, - // TODO: Container, - // TODO: Fulltext, + Container, + File, } impl FromStr for SearchEntityType { @@ -66,8 +66,8 @@ impl FromStr for SearchEntityType { fn from_str(s: &str) -> Result { match s { "release" | "releases" => Ok(SearchEntityType::Release), - //"container" | "containers" => Ok(SearchEntityType::Container), - //"fulltext" | "scholar" => Ok(SearchEntityType::Fulltext), + "container" | "containers" => Ok(SearchEntityType::Container), + "file" | "files" => Ok(SearchEntityType::File), _ => Err(anyhow!("invalid entity type : {}", s)), } } diff --git a/fatcat-cli/src/main.rs b/fatcat-cli/src/main.rs index 72cb169..b3a5db3 100644 --- a/fatcat-cli/src/main.rs +++ b/fatcat-cli/src/main.rs @@ -553,6 +553,26 @@ fn run(opt: Opt) -> Result<()> { )?; writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)? } + (false, true, SearchEntityType::Container) => { + let specifier = + Specifier::Container(hit["ident"].as_str().unwrap().to_string()); + let entity = specifier.get_from_api( + &mut api_client, + expand.clone(), + hide.clone(), + )?; + writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)? + } + (false, true, SearchEntityType::File) => { + let specifier = + Specifier::File(hit["ident"].as_str().unwrap().to_string()); + let entity = specifier.get_from_api( + &mut api_client, + expand.clone(), + hide.clone(), + )?; + writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)? + } } } } diff --git a/fatcat-cli/src/search.rs b/fatcat-cli/src/search.rs index f328ee9..88361c5 100644 --- a/fatcat-cli/src/search.rs +++ b/fatcat-cli/src/search.rs @@ -77,8 +77,8 @@ pub fn crude_search( ) -> Result { let index = match entity_type { SearchEntityType::Release => "fatcat_release", - //SearchEntityType::File => "fatcat_file", - //SearchEntityType::Container => "fatcat_container", + SearchEntityType::Container => "fatcat_container", + SearchEntityType::File => "fatcat_file", }; let http_client = reqwest::blocking::Client::builder() .timeout(Duration::from_secs(10)) -- cgit v1.2.3