mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
Merge pull request #726 from MarinPostma/exhaustive-facet-count
Return the exhaustive facets count field
This commit is contained in:
commit
81b1aed7a1
@ -30,7 +30,7 @@ pub struct SortResult {
|
|||||||
pub nb_hits: usize,
|
pub nb_hits: usize,
|
||||||
pub exhaustive_nb_hit: bool,
|
pub exhaustive_nb_hit: bool,
|
||||||
pub facets: Option<HashMap<String, HashMap<String, usize>>>,
|
pub facets: Option<HashMap<String, HashMap<String, usize>>>,
|
||||||
pub exhaustive_facet_count: Option<bool>,
|
pub exhaustive_facets_count: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bucket_sort<'c, FI>(
|
pub fn bucket_sort<'c, FI>(
|
||||||
@ -118,7 +118,7 @@ where
|
|||||||
|
|
||||||
if let Some(f) = facet_count_docids {
|
if let Some(f) = facet_count_docids {
|
||||||
// hardcoded value, until approximation optimization
|
// hardcoded value, until approximation optimization
|
||||||
result.exhaustive_facet_count = Some(true);
|
result.exhaustive_facets_count = Some(true);
|
||||||
result.facets = Some(facet_count(f, &docids));
|
result.facets = Some(facet_count(f, &docids));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ where
|
|||||||
|
|
||||||
if let Some(f) = facet_count_docids {
|
if let Some(f) = facet_count_docids {
|
||||||
// hardcoded value, until approximation optimization
|
// hardcoded value, until approximation optimization
|
||||||
result.exhaustive_facet_count = Some(true);
|
result.exhaustive_facets_count = Some(true);
|
||||||
result.facets = Some(facet_count(f, &docids));
|
result.facets = Some(facet_count(f, &docids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +249,7 @@ impl<'a> SearchBuilder<'a> {
|
|||||||
processing_time_ms: time_ms,
|
processing_time_ms: time_ms,
|
||||||
query: self.query.to_string(),
|
query: self.query.to_string(),
|
||||||
facets_distribution: search_result.facets,
|
facets_distribution: search_result.facets,
|
||||||
|
exhaustive_facets_count: search_result.exhaustive_facets_count,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(results)
|
Ok(results)
|
||||||
@ -335,6 +336,8 @@ pub struct SearchResult {
|
|||||||
pub query: String,
|
pub query: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub facets_distribution: Option<HashMap<String, HashMap<String, usize>>>,
|
pub facets_distribution: Option<HashMap<String, HashMap<String, usize>>>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub exhaustive_facets_count: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns the start index and the length on the crop.
|
/// returns the start index and the length on the crop.
|
||||||
|
@ -1297,6 +1297,12 @@ async fn test_faceted_search_invalid() {
|
|||||||
async fn test_facet_count() {
|
async fn test_facet_count() {
|
||||||
let mut server = common::Server::test_server().await;
|
let mut server = common::Server::test_server().await;
|
||||||
|
|
||||||
|
// test without facet distribution
|
||||||
|
let query = "q=a";
|
||||||
|
let (response, _status_code) = server.search(query).await;
|
||||||
|
assert!(response.get("exhaustiveFacetsCount").is_none());
|
||||||
|
assert!(response.get("facetsDistribution").is_none());
|
||||||
|
|
||||||
// test no facets set, search on color
|
// test no facets set, search on color
|
||||||
let query = "q=a&facetsDistribution=%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;
|
||||||
@ -1308,6 +1314,7 @@ 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!(response.get("exhaustiveFacetsCount").is_some());
|
||||||
assert_eq!(response.get("facetsDistribution").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&facetsDistribution=%5B%22color%22,%20%22tags%22%5D";
|
let query = "q=a&facetsDistribution=%5B%22color%22,%20%22tags%22%5D";
|
||||||
|
Loading…
Reference in New Issue
Block a user