send the analytics even when the search fail

This commit is contained in:
Tamo 2021-11-02 12:38:01 +01:00
parent c32f13a909
commit 904bae98f8
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
3 changed files with 16 additions and 14 deletions

View File

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

View File

@ -364,7 +364,7 @@ impl SearchAggregator {
ret
}
pub fn finish(&mut self, result: &SearchResult) {
pub fn succeed(&mut self, result: &SearchResult) {
self.total_succeeded += 1;
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 search_result = meilisearch
.search(path.into_inner().index_uid, query)
.await?;
let search_result = meilisearch.search(path.into_inner().index_uid, query).await;
if let Ok(ref search_result) = search_result {
aggregate.succeed(search_result);
}
analytics.get_search(aggregate);
let search_result = search_result?;
// Tests that the nb_hits is always set to false
#[cfg(test)]
assert!(!search_result.exhaustive_nb_hits);
aggregate.finish(&search_result);
analytics.get_search(aggregate);
debug!("returns: {:?}", 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 search_result = meilisearch
.search(path.into_inner().index_uid, query)
.await?;
let search_result = meilisearch.search(path.into_inner().index_uid, query).await;
if let Ok(ref search_result) = search_result {
aggregate.succeed(search_result);
}
analytics.get_search(aggregate);
let search_result = search_result?;
// Tests that the nb_hits is always set to false
#[cfg(test)]
assert!(!search_result.exhaustive_nb_hits);
aggregate.finish(&search_result);
analytics.post_search(aggregate);
debug!("returns: {:?}", search_result);
Ok(HttpResponse::Ok().json(search_result))
}