diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-02-10 11:12:49 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-02-10 11:12:49 -0800 |
commit | 4f4c1e78186ad9bcd77f3536ef30dd5a130ec2d7 (patch) | |
tree | b1015ec2278426e30a969da37f9eaf746cff9378 | |
parent | 6a0e0d122b70c282f28eb0aec83780f9d3edc995 (diff) | |
download | fatcat-cli-4f4c1e78186ad9bcd77f3536ef30dd5a130ec2d7.tar.gz fatcat-cli-4f4c1e78186ad9bcd77f3536ef30dd5a130ec2d7.zip |
search: container and file indexes
-rw-r--r-- | fatcat-cli/src/commands.rs | 32 | ||||
-rw-r--r-- | fatcat-cli/src/lib.rs | 8 | ||||
-rw-r--r-- | fatcat-cli/src/main.rs | 20 | ||||
-rw-r--r-- | 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<Self, Self::Err> { 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<SearchResults> { 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)) |