1865: Aggregate the search even when it fails fail r=MarinPostma a=irevoire



Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
bors[bot] 2021-11-03 16:49:05 +00:00 committed by GitHub
commit 4095ec462e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View File

@ -18,7 +18,7 @@ impl SearchAggregator {
Self::default() Self::default()
} }
pub fn finish(&mut self, _: &dyn Any) {} pub fn succeed(&mut self, _: &dyn Any) {}
} }
impl MockAnalytics { impl MockAnalytics {

View File

@ -364,7 +364,7 @@ impl SearchAggregator {
ret ret
} }
pub fn finish(&mut self, result: &SearchResult) { pub fn succeed(&mut self, result: &SearchResult) {
self.total_succeeded += 1; self.total_succeeded += 1;
self.time_spent.push(result.processing_time_ms as usize); self.time_spent.push(result.processing_time_ms as usize);
} }

View File

@ -118,17 +118,18 @@ pub async fn search_with_url_query(
let mut aggregate = SearchAggregator::from_query(&query, &req); let mut aggregate = SearchAggregator::from_query(&query, &req);
let search_result = meilisearch let search_result = meilisearch.search(path.into_inner().index_uid, query).await;
.search(path.into_inner().index_uid, query) if let Ok(ref search_result) = search_result {
.await?; aggregate.succeed(search_result);
}
analytics.get_search(aggregate);
let search_result = search_result?;
// Tests that the nb_hits is always set to false // Tests that the nb_hits is always set to false
#[cfg(test)] #[cfg(test)]
assert!(!search_result.exhaustive_nb_hits); assert!(!search_result.exhaustive_nb_hits);
aggregate.finish(&search_result);
analytics.get_search(aggregate);
debug!("returns: {:?}", search_result); debug!("returns: {:?}", search_result);
Ok(HttpResponse::Ok().json(search_result)) Ok(HttpResponse::Ok().json(search_result))
} }
@ -145,17 +146,18 @@ pub async fn search_with_post(
let mut aggregate = SearchAggregator::from_query(&query, &req); let mut aggregate = SearchAggregator::from_query(&query, &req);
let search_result = meilisearch let search_result = meilisearch.search(path.into_inner().index_uid, query).await;
.search(path.into_inner().index_uid, query) if let Ok(ref search_result) = search_result {
.await?; aggregate.succeed(search_result);
}
analytics.get_search(aggregate);
let search_result = search_result?;
// Tests that the nb_hits is always set to false // Tests that the nb_hits is always set to false
#[cfg(test)] #[cfg(test)]
assert!(!search_result.exhaustive_nb_hits); assert!(!search_result.exhaustive_nb_hits);
aggregate.finish(&search_result);
analytics.post_search(aggregate);
debug!("returns: {:?}", search_result); debug!("returns: {:?}", search_result);
Ok(HttpResponse::Ok().json(search_result)) Ok(HttpResponse::Ok().json(search_result))
} }