mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 07:56:28 +00:00 
			
		
		
		
	implement index search methods
This commit is contained in:
		| @@ -97,7 +97,7 @@ actix-rt = "2.1.0" | ||||
| assert-json-diff = { branch = "master", git = "https://github.com/qdequele/assert-json-diff" } | ||||
| mockall = "0.9.1" | ||||
| paste = "1.0.5" | ||||
| serde_url_params = "0.2.0" | ||||
| serde_url_params = "0.2.1" | ||||
| tempdir = "0.3.7" | ||||
| urlencoding = "1.1.1" | ||||
|  | ||||
|   | ||||
| @@ -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