From b6570f7016e7ea8ab5706f2f8965a81fdbb698a7 Mon Sep 17 00:00:00 2001 From: mpostma Date: Tue, 26 May 2020 17:56:07 +0200 Subject: [PATCH] rename facets to facetsDistribution --- meilisearch-http/src/helpers/meilisearch.rs | 4 ++-- meilisearch-http/src/routes/search.rs | 4 ++-- meilisearch-http/tests/search.rs | 26 ++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/meilisearch-http/src/helpers/meilisearch.rs b/meilisearch-http/src/helpers/meilisearch.rs index 3ef83ba1e..6e27b03f2 100644 --- a/meilisearch-http/src/helpers/meilisearch.rs +++ b/meilisearch-http/src/helpers/meilisearch.rs @@ -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>>, + pub facets_distribution: Option>>, } /// returns the start index and the length on the crop. diff --git a/meilisearch-http/src/routes/search.rs b/meilisearch-http/src/routes/search.rs index 7739ea1d8..2bc7b45d0 100644 --- a/meilisearch-http/src/routes/search.rs +++ b/meilisearch-http/src/routes/search.rs @@ -33,7 +33,7 @@ struct SearchQuery { filters: Option, matches: Option, facet_filters: Option, - facets: Option, + facets_distribution: Option, } #[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)?; diff --git a/meilisearch-http/tests/search.rs b/meilisearch-http/tests/search.rs index c4c3b0a30..37f363062 100644 --- a/meilisearch-http/tests/search.rs +++ b/meilisearch-http/tests/search.rs @@ -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); }