diff options
Diffstat (limited to 'fatcat-cli/src/search.rs')
-rw-r--r-- | fatcat-cli/src/search.rs | 142 |
1 files changed, 109 insertions, 33 deletions
diff --git a/fatcat-cli/src/search.rs b/fatcat-cli/src/search.rs index e4f7dce..7d03f6f 100644 --- a/fatcat-cli/src/search.rs +++ b/fatcat-cli/src/search.rs @@ -79,6 +79,7 @@ pub fn crude_search( SearchEntityType::Release => "fatcat_release", SearchEntityType::Container => "fatcat_container", SearchEntityType::File => "fatcat_file", + SearchEntityType::Scholar => "scholar_fulltext", }; let http_client = reqwest::blocking::Client::builder() .timeout(Duration::from_secs(10)) @@ -102,47 +103,122 @@ pub fn crude_search( Some(l) => (false, "_score", l), }; - let query_body = json!({ - "query": { - "boosting": { - "positive": { - "bool": { - "must": { - "query_string": { - "query": query, - "default_operator": "AND", - "analyze_wildcard": true, - "allow_leading_wildcard": false, - "lenient": true, - "fields": [ - "title^2", - "biblio", - ], + let query_body = match entity_type { + SearchEntityType::Release => json!({ + "query": { + "boosting": { + "positive": { + "bool": { + "must": { + "query_string": { + "query": query, + "default_operator": "AND", + "analyze_wildcard": true, + "allow_leading_wildcard": false, + "lenient": true, + "fields": [ + "title^2", + "biblio", + ], + }, + }, + "should": { + "term": { "in_ia": true }, }, }, - "should": { - "term": { "in_ia": true }, + }, + "negative": { + "bool": { + "should": [ + {"bool": { "must_not" : { "exists": { "field": "title" }}}}, + {"bool": { "must_not" : { "exists": { "field": "year" }}}}, + {"bool": { "must_not" : { "exists": { "field": "type" }}}}, + {"bool": { "must_not" : { "exists": { "field": "stage" }}}}, + ], }, }, + "negative_boost": 0.5, + }, + }, + "size": size, + "sort": [ sort_mode ], + "track_total_hits": true, + }), + SearchEntityType::Container => json!({ + "query": { + "query_string": { + "query": query, + "default_operator": "AND", + "analyze_wildcard": true, + "allow_leading_wildcard": false, + "lenient": true, + "fields": [ + "name^2", + "biblio", + ], }, - "negative": { - "bool": { - "should": [ - {"bool": { "must_not" : { "exists": { "field": "title" }}}}, - {"bool": { "must_not" : { "exists": { "field": "year" }}}}, - {"bool": { "must_not" : { "exists": { "field": "type" }}}}, - {"bool": { "must_not" : { "exists": { "field": "stage" }}}}, - ], + }, + "size": size, + "sort": [ sort_mode ], + "track_total_hits": true, + }), + SearchEntityType::File => 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, + }), + SearchEntityType::Scholar => json!({ + "query": { + "boosting": { + "positive": { + "bool": { + "must": { + "query_string": { + "query": query, + "default_operator": "AND", + "analyze_wildcard": true, + "allow_leading_wildcard": false, + "lenient": true, + "quote_field_suffix": ".exact", + "fields": [ + "title^4", + "biblio_all^3", + "everything", + ], + }, + }, + "should": { + "terms": { "access_type": ["ia_sim", "ia_file", "wayback"]}, + }, + }, }, + "negative": { + "bool": { + "should": [ + {"bool": { "must_not" : { "exists": { "field": "year" }}}}, + {"bool": { "must_not" : { "exists": { "field": "type" }}}}, + {"bool": { "must_not" : { "exists": { "field": "stage" }}}}, + {"bool": { "must_not" : { "exists": { "field": "biblio.container_name" }}}}, + ], + }, + }, + "negative_boost": 0.5, }, - "negative_boost": 0.5, }, - }, - "size": size, - "sort": [ sort_mode ], - "track_total_hits": true, - }) - .to_string(); + "size": size, + "sort": [ sort_mode ], + "track_total_hits": true, + }), + }.to_string(); let mut request = http_client .get(&request_url) |