mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
Merge pull request #716 from MarinPostma/rename-facet
rename facets to facetsDistribution
This commit is contained in:
commit
b859477ffd
@ -248,7 +248,7 @@ impl<'a> SearchBuilder<'a> {
|
||||
exhaustive_nb_hits: search_result.exhaustive_nb_hit,
|
||||
processing_time_ms: time_ms,
|
||||
query: self.query.to_string(),
|
||||
facets: search_result.facets,
|
||||
facets_distribution: search_result.facets,
|
||||
};
|
||||
|
||||
Ok(results)
|
||||
@ -334,7 +334,7 @@ pub struct SearchResult {
|
||||
pub processing_time_ms: usize,
|
||||
pub query: String,
|
||||
#[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.
|
||||
|
@ -33,7 +33,7 @@ struct SearchQuery {
|
||||
filters: Option<String>,
|
||||
matches: Option<bool>,
|
||||
facet_filters: Option<String>,
|
||||
facets: Option<String>,
|
||||
facets_distribution: Option<String>,
|
||||
}
|
||||
|
||||
#[get("/indexes/{index_uid}/search", wrap = "Authentication::Public")]
|
||||
@ -94,7 +94,7 @@ async fn search_with_url_query(
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(facets) = ¶ms.facets {
|
||||
if let Some(facets) = ¶ms.facets_distribution {
|
||||
match index.main.attributes_for_faceting(&reader)? {
|
||||
Some(ref attrs) => {
|
||||
let field_ids = prepare_facet_list(&facets, &schema, attrs)?;
|
||||
|
@ -1298,7 +1298,7 @@ async fn test_facet_count() {
|
||||
let mut server = common::Server::test_server().await;
|
||||
|
||||
// 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;
|
||||
assert_eq!(status_code, 400);
|
||||
|
||||
@ -1308,38 +1308,38 @@ async fn test_facet_count() {
|
||||
server.update_all_settings(body).await;
|
||||
// same as before, but now facets are set:
|
||||
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
|
||||
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 facets = response.get("facets").unwrap().as_object().unwrap();
|
||||
let facets = response.get("facetsDistribution").unwrap().as_object().unwrap();
|
||||
eprintln!("response: {:#?}", response);
|
||||
assert_eq!(facets.values().count(), 2);
|
||||
assert_ne!(!facets.get("color").unwrap().as_object().unwrap().values().count(), 0);
|
||||
assert_ne!(!facets.get("tags").unwrap().as_object().unwrap().values().count(), 0);
|
||||
// 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;
|
||||
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:
|
||||
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;
|
||||
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
|
||||
let query = "q=a&facets=%5B%5D";
|
||||
let query = "q=a&facetsDistribution=%5B%5D";
|
||||
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:
|
||||
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;
|
||||
assert_eq!(status_code, 400);
|
||||
// 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;
|
||||
assert_eq!(status_code, 400);
|
||||
// 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;
|
||||
assert_eq!(status_code, 400);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user