rename facets to facetsDistribution

This commit is contained in:
mpostma 2020-05-26 17:56:07 +02:00
parent c1a2c7b610
commit b6570f7016
3 changed files with 17 additions and 17 deletions

View File

@ -248,7 +248,7 @@ impl<'a> SearchBuilder<'a> {
exhaustive_nb_hits: search_result.exhaustive_nb_hit, exhaustive_nb_hits: search_result.exhaustive_nb_hit,
processing_time_ms: time_ms, processing_time_ms: time_ms,
query: self.query.to_string(), query: self.query.to_string(),
facets: search_result.facets, facets_distribution: search_result.facets,
}; };
Ok(results) Ok(results)
@ -334,7 +334,7 @@ pub struct SearchResult {
pub processing_time_ms: usize, pub processing_time_ms: usize,
pub query: String, pub query: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub facets: Option<HashMap<String, HashMap<String, usize>>>, pub facets_distribution: Option<HashMap<String, HashMap<String, usize>>>,
} }
/// returns the start index and the length on the crop. /// returns the start index and the length on the crop.

View File

@ -33,7 +33,7 @@ struct SearchQuery {
filters: Option<String>, filters: Option<String>,
matches: Option<bool>, matches: Option<bool>,
facet_filters: Option<String>, facet_filters: Option<String>,
facets: Option<String>, facets_distribution: Option<String>,
} }
#[get("/indexes/{index_uid}/search", wrap = "Authentication::Public")] #[get("/indexes/{index_uid}/search", wrap = "Authentication::Public")]
@ -94,7 +94,7 @@ async fn search_with_url_query(
} }
} }
if let Some(facets) = &params.facets { if let Some(facets) = &params.facets_distribution {
match index.main.attributes_for_faceting(&reader)? { match index.main.attributes_for_faceting(&reader)? {
Some(ref attrs) => { Some(ref attrs) => {
let field_ids = prepare_facet_list(&facets, &schema, attrs)?; let field_ids = prepare_facet_list(&facets, &schema, attrs)?;

View File

@ -1298,7 +1298,7 @@ async fn test_facet_count() {
let mut server = common::Server::test_server().await; let mut server = common::Server::test_server().await;
// test no facets set, search on color // test no facets set, search on color
let query = "q=a&facets=%5B%22color%22%5D"; let query = "q=a&facetsDistribution=%5B%22color%22%5D";
let (_response, status_code) = server.search(query).await; let (_response, status_code) = server.search(query).await;
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
@ -1308,38 +1308,38 @@ async fn test_facet_count() {
server.update_all_settings(body).await; server.update_all_settings(body).await;
// same as before, but now facets are set: // same as before, but now facets are set:
let (response, _status_code) = server.search(query).await; let (response, _status_code) = server.search(query).await;
assert_eq!(response.get("facets").unwrap().as_object().unwrap().values().count(), 1); assert_eq!(response.get("facetsDistribution").unwrap().as_object().unwrap().values().count(), 1);
// searching on color and tags // searching on color and tags
let query = "q=a&facets=%5B%22color%22,%20%22tags%22%5D"; let query = "q=a&facetsDistribution=%5B%22color%22,%20%22tags%22%5D";
let (response, _status_code) = server.search(query).await; let (response, _status_code) = server.search(query).await;
let facets = response.get("facets").unwrap().as_object().unwrap(); let facets = response.get("facetsDistribution").unwrap().as_object().unwrap();
eprintln!("response: {:#?}", response); eprintln!("response: {:#?}", response);
assert_eq!(facets.values().count(), 2); assert_eq!(facets.values().count(), 2);
assert_ne!(!facets.get("color").unwrap().as_object().unwrap().values().count(), 0); assert_ne!(!facets.get("color").unwrap().as_object().unwrap().values().count(), 0);
assert_ne!(!facets.get("tags").unwrap().as_object().unwrap().values().count(), 0); assert_ne!(!facets.get("tags").unwrap().as_object().unwrap().values().count(), 0);
// wildcard // wildcard
let query = "q=a&facets=%5B%22*%22%5D"; let query = "q=a&facetsDistribution=%5B%22*%22%5D";
let (response, _status_code) = server.search(query).await; let (response, _status_code) = server.search(query).await;
assert_eq!(response.get("facets").unwrap().as_object().unwrap().values().count(), 2); assert_eq!(response.get("facetsDistribution").unwrap().as_object().unwrap().values().count(), 2);
// wildcard with other attributes: // wildcard with other attributes:
let query = "q=a&facets=%5B%22color%22,%20%22*%22%5D"; let query = "q=a&facetsDistribution=%5B%22color%22,%20%22*%22%5D";
let (response, _status_code) = server.search(query).await; let (response, _status_code) = server.search(query).await;
assert_eq!(response.get("facets").unwrap().as_object().unwrap().values().count(), 2); assert_eq!(response.get("facetsDistribution").unwrap().as_object().unwrap().values().count(), 2);
// empty facet list // empty facet list
let query = "q=a&facets=%5B%5D"; let query = "q=a&facetsDistribution=%5B%5D";
let (response, _status_code) = server.search(query).await; let (response, _status_code) = server.search(query).await;
assert_eq!(response.get("facets").unwrap().as_object().unwrap().values().count(), 0); assert_eq!(response.get("facetsDistribution").unwrap().as_object().unwrap().values().count(), 0);
// attr not set as facet passed: // attr not set as facet passed:
let query = "q=a&facets=%5B%22gender%22%5D"; let query = "q=a&facetsDistribution=%5B%22gender%22%5D";
let (_response, status_code) = server.search(query).await; let (_response, status_code) = server.search(query).await;
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
// string instead of array: // string instead of array:
let query = "q=a&facets=%22gender%22"; let query = "q=a&faceDistribution=%22gender%22";
let (_response, status_code) = server.search(query).await; let (_response, status_code) = server.search(query).await;
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
// invalid value in array: // invalid value in array:
let query = "q=a&facets=%5B%22color%22,%20true%5D"; let query = "q=a&facetsDistribution=%5B%22color%22,%20true%5D";
let (_response, status_code) = server.search(query).await; let (_response, status_code) = server.search(query).await;
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
} }