Merge pull request #726 from MarinPostma/exhaustive-facet-count

Return the exhaustive facets count field
This commit is contained in:
Clément Renault 2020-05-28 12:39:00 +02:00 committed by GitHub
commit 81b1aed7a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -30,7 +30,7 @@ pub struct SortResult {
pub nb_hits: usize,
pub exhaustive_nb_hit: bool,
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>(
@ -118,7 +118,7 @@ where
if let Some(f) = facet_count_docids {
// hardcoded value, until approximation optimization
result.exhaustive_facet_count = Some(true);
result.exhaustive_facets_count = Some(true);
result.facets = Some(facet_count(f, &docids));
}
@ -265,7 +265,7 @@ where
if let Some(f) = facet_count_docids {
// hardcoded value, until approximation optimization
result.exhaustive_facet_count = Some(true);
result.exhaustive_facets_count = Some(true);
result.facets = Some(facet_count(f, &docids));
}

View File

@ -249,6 +249,7 @@ impl<'a> SearchBuilder<'a> {
processing_time_ms: time_ms,
query: self.query.to_string(),
facets_distribution: search_result.facets,
exhaustive_facets_count: search_result.exhaustive_facets_count,
};
Ok(results)
@ -335,6 +336,8 @@ pub struct SearchResult {
pub query: String,
#[serde(skip_serializing_if = "Option::is_none")]
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.

View File

@ -1297,6 +1297,12 @@ async fn test_faceted_search_invalid() {
async fn test_facet_count() {
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
let query = "q=a&facetsDistribution=%5B%22color%22%5D";
let (_response, status_code) = server.search(query).await;
@ -1308,6 +1314,7 @@ 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!(response.get("exhaustiveFacetsCount").is_some());
assert_eq!(response.get("facetsDistribution").unwrap().as_object().unwrap().values().count(), 1);
// searching on color and tags
let query = "q=a&facetsDistribution=%5B%22color%22,%20%22tags%22%5D";