mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-30 23:46:28 +00:00 
			
		
		
		
	implement index search methods
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| use std::time::Duration; | ||||
| use std::{panic::{UnwindSafe, catch_unwind, resume_unwind}, time::Duration}; | ||||
|  | ||||
| use actix_web::http::StatusCode; | ||||
| use paste::paste; | ||||
| @@ -185,6 +185,33 @@ impl Index<'_> { | ||||
|         self.service.get(url).await | ||||
|     } | ||||
|  | ||||
|     pub async fn search(&self, query: Value, test: impl Fn(Value, StatusCode) + UnwindSafe + Clone) { | ||||
|         let (response, code) = self.search_post(query.clone()).await; | ||||
|         let t = test.clone(); | ||||
|         if let Err(e) = catch_unwind(move || t(response, code)) { | ||||
|             eprintln!("Error with post search"); | ||||
|             resume_unwind(e); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         let (response, code) = self.search_get(query).await; | ||||
|         if let Err(e) = catch_unwind(move || test(response, code)) { | ||||
|             eprintln!("Error with get search"); | ||||
|             resume_unwind(e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub async fn search_post(&self, query: Value) -> (Value, StatusCode) { | ||||
|         let url = format!("/indexes/{}/search", self.uid); | ||||
|         self.service.post(url, query).await | ||||
|     } | ||||
|  | ||||
|     pub async fn search_get(&self, query: Value) -> (Value, StatusCode) { | ||||
|         let params = serde_url_params::to_string(&query).unwrap(); | ||||
|         let url = format!("/indexes/{}/search?{}", self.uid, params); | ||||
|         self.service.get(url).await | ||||
|     } | ||||
|  | ||||
|     make_settings_test_routes!(distinct_attribute); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user