mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
Change lacking errors
This commit is contained in:
parent
c32f13a909
commit
30a094cbb2
14 changed files with 128 additions and 61 deletions
|
@ -7,6 +7,7 @@ use actix_web::http::StatusCode;
|
|||
use paste::paste;
|
||||
use serde_json::{json, Value};
|
||||
use tokio::time::sleep;
|
||||
use urlencoding::encode;
|
||||
|
||||
use super::service::Service;
|
||||
|
||||
|
@ -14,12 +15,12 @@ macro_rules! make_settings_test_routes {
|
|||
($($name:ident),+) => {
|
||||
$(paste! {
|
||||
pub async fn [<update_$name>](&self, value: Value) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/{}", self.uid, stringify!($name).replace("_", "-"));
|
||||
let url = format!("/indexes/{}/settings/{}", encode(self.uid.as_ref()).to_string(), stringify!($name).replace("_", "-"));
|
||||
self.service.post(url, value).await
|
||||
}
|
||||
|
||||
pub async fn [<get_$name>](&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/{}", self.uid, stringify!($name).replace("_", "-"));
|
||||
let url = format!("/indexes/{}/settings/{}", encode(self.uid.as_ref()).to_string(), stringify!($name).replace("_", "-"));
|
||||
self.service.get(url).await
|
||||
}
|
||||
})*
|
||||
|
@ -34,12 +35,15 @@ pub struct Index<'a> {
|
|||
#[allow(dead_code)]
|
||||
impl Index<'_> {
|
||||
pub async fn get(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}", self.uid);
|
||||
let url = format!("/indexes/{}", encode(self.uid.as_ref()).to_string());
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
pub async fn load_test_set(&self) -> u64 {
|
||||
let url = format!("/indexes/{}/documents", self.uid);
|
||||
let url = format!(
|
||||
"/indexes/{}/documents",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
let (response, code) = self
|
||||
.service
|
||||
.post_str(url, include_str!("../assets/test_set.json"))
|
||||
|
@ -62,13 +66,13 @@ impl Index<'_> {
|
|||
let body = json!({
|
||||
"primaryKey": primary_key,
|
||||
});
|
||||
let url = format!("/indexes/{}", self.uid);
|
||||
let url = format!("/indexes/{}", encode(self.uid.as_ref()).to_string());
|
||||
|
||||
self.service.put(url, body).await
|
||||
}
|
||||
|
||||
pub async fn delete(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}", self.uid);
|
||||
let url = format!("/indexes/{}", encode(self.uid.as_ref()).to_string());
|
||||
self.service.delete(url).await
|
||||
}
|
||||
|
||||
|
@ -78,8 +82,15 @@ impl Index<'_> {
|
|||
primary_key: Option<&str>,
|
||||
) -> (Value, StatusCode) {
|
||||
let url = match primary_key {
|
||||
Some(key) => format!("/indexes/{}/documents?primaryKey={}", self.uid, key),
|
||||
None => format!("/indexes/{}/documents", self.uid),
|
||||
Some(key) => format!(
|
||||
"/indexes/{}/documents?primaryKey={}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
key
|
||||
),
|
||||
None => format!(
|
||||
"/indexes/{}/documents",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
),
|
||||
};
|
||||
self.service.post(url, documents).await
|
||||
}
|
||||
|
@ -90,15 +101,26 @@ impl Index<'_> {
|
|||
primary_key: Option<&str>,
|
||||
) -> (Value, StatusCode) {
|
||||
let url = match primary_key {
|
||||
Some(key) => format!("/indexes/{}/documents?primaryKey={}", self.uid, key),
|
||||
None => format!("/indexes/{}/documents", self.uid),
|
||||
Some(key) => format!(
|
||||
"/indexes/{}/documents?primaryKey={}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
key
|
||||
),
|
||||
None => format!(
|
||||
"/indexes/{}/documents",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
),
|
||||
};
|
||||
self.service.put(url, documents).await
|
||||
}
|
||||
|
||||
pub async fn wait_update_id(&self, update_id: u64) -> Value {
|
||||
// try 10 times to get status, or panic to not wait forever
|
||||
let url = format!("/indexes/{}/updates/{}", self.uid, update_id);
|
||||
let url = format!(
|
||||
"/indexes/{}/updates/{}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
update_id
|
||||
);
|
||||
for _ in 0..10 {
|
||||
let (response, status_code) = self.service.get(&url).await;
|
||||
assert_eq!(status_code, 200, "response: {}", response);
|
||||
|
@ -113,12 +135,16 @@ impl Index<'_> {
|
|||
}
|
||||
|
||||
pub async fn get_update(&self, update_id: u64) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/updates/{}", self.uid, update_id);
|
||||
let url = format!(
|
||||
"/indexes/{}/updates/{}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
update_id
|
||||
);
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
pub async fn list_updates(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/updates", self.uid);
|
||||
let url = format!("/indexes/{}/updates", encode(self.uid.as_ref()).to_string());
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
|
@ -127,12 +153,19 @@ impl Index<'_> {
|
|||
id: u64,
|
||||
_options: Option<GetDocumentOptions>,
|
||||
) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/documents/{}", self.uid, id);
|
||||
let url = format!(
|
||||
"/indexes/{}/documents/{}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
id
|
||||
);
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
pub async fn get_all_documents(&self, options: GetAllDocumentsOptions) -> (Value, StatusCode) {
|
||||
let mut url = format!("/indexes/{}/documents?", self.uid);
|
||||
let mut url = format!(
|
||||
"/indexes/{}/documents?",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
if let Some(limit) = options.limit {
|
||||
url.push_str(&format!("limit={}&", limit));
|
||||
}
|
||||
|
@ -152,39 +185,58 @@ impl Index<'_> {
|
|||
}
|
||||
|
||||
pub async fn delete_document(&self, id: u64) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/documents/{}", self.uid, id);
|
||||
let url = format!(
|
||||
"/indexes/{}/documents/{}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
id
|
||||
);
|
||||
self.service.delete(url).await
|
||||
}
|
||||
|
||||
pub async fn clear_all_documents(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/documents", self.uid);
|
||||
let url = format!(
|
||||
"/indexes/{}/documents",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
self.service.delete(url).await
|
||||
}
|
||||
|
||||
pub async fn delete_batch(&self, ids: Vec<u64>) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/documents/delete-batch", self.uid);
|
||||
let url = format!(
|
||||
"/indexes/{}/documents/delete-batch",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
self.service
|
||||
.post(url, serde_json::to_value(&ids).unwrap())
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn settings(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings", self.uid);
|
||||
let url = format!(
|
||||
"/indexes/{}/settings",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
pub async fn update_settings(&self, settings: Value) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings", self.uid);
|
||||
let url = format!(
|
||||
"/indexes/{}/settings",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
self.service.post(url, settings).await
|
||||
}
|
||||
|
||||
pub async fn delete_settings(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings", self.uid);
|
||||
let url = format!(
|
||||
"/indexes/{}/settings",
|
||||
encode(self.uid.as_ref()).to_string()
|
||||
);
|
||||
self.service.delete(url).await
|
||||
}
|
||||
|
||||
pub async fn stats(&self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/stats", self.uid);
|
||||
let url = format!("/indexes/{}/stats", encode(self.uid.as_ref()).to_string());
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
|
@ -209,13 +261,17 @@ impl Index<'_> {
|
|||
}
|
||||
|
||||
pub async fn search_post(&self, query: Value) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/search", self.uid);
|
||||
let url = format!("/indexes/{}/search", encode(self.uid.as_ref()).to_string());
|
||||
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);
|
||||
let url = format!(
|
||||
"/indexes/{}/search?{}",
|
||||
encode(self.uid.as_ref()).to_string(),
|
||||
params
|
||||
);
|
||||
self.service.get(url).await
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue