mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 16:06:31 +00:00 
			
		
		
		
	send the analytics even when the search fail
This commit is contained in:
		| @@ -18,7 +18,7 @@ impl SearchAggregator { | ||||
|         Self::default() | ||||
|     } | ||||
|  | ||||
|     pub fn finish(&mut self, _: &dyn Any) {} | ||||
|     pub fn succeed(&mut self, _: &dyn Any) {} | ||||
| } | ||||
|  | ||||
| impl MockAnalytics { | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
|   | ||||
| @@ -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)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user