summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-08-09 11:24:37 -0700
committerBryan Newbold <bnewbold@archive.org>2021-08-09 11:25:02 -0700
commitf1499a583f7730c9133a56c0419a3a0fff7bb3a5 (patch)
tree4bdcb102b6ea736ed5f88cdd3e103e8e26a54405
parent9a456942e3b534f41ea668370ec5b91b58298020 (diff)
downloadfatcat-cli-f1499a583f7730c9133a56c0419a3a0fff7bb3a5.tar.gz
fatcat-cli-f1499a583f7730c9133a56c0419a3a0fff7bb3a5.zip
initial fatcat_refs search index support
-rw-r--r--fatcat-cli/src/commands.rs14
-rw-r--r--fatcat-cli/src/lib.rs2
-rw-r--r--fatcat-cli/src/main.rs5
-rw-r--r--fatcat-cli/src/search.rs15
4 files changed, 36 insertions, 0 deletions
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