Skip to content

Commit 606c4d3

Browse files
authored
Remove set_health method and rename method get_health into health (#59)
* Remove UpdateHealth method and rename method get_health into health * Remove the warning
1 parent a71f121 commit 606c4d3

File tree

3 files changed

+15
-54
lines changed

3 files changed

+15
-54
lines changed

.code-samples.meilisearch.yaml

+10-12
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,8 @@ get_index_stats_1: |-
193193
get_indexes_stats_1: |-
194194
let stats: ClientStats = client.get_stats().await.unwrap();
195195
get_health_1: |-
196-
// get_health() return an Err() if the server is not healthy, so this example would panic due to the unwrap
197-
client.get_health().await.unwrap();
198-
update_health_1: |-
199-
client.set_health(false).await.unwrap();
196+
// health() return an Err() if the server is not healthy, so this example would panic due to the unwrap
197+
client.health().await.unwrap();
200198
get_version_1: |-
201199
let version: Version = client.get_version().await.unwrap();
202200
distinct_attribute_guide_1: |-
@@ -287,7 +285,7 @@ search_parameter_guide_crop_1: |-
287285
.execute()
288286
.await
289287
.unwrap();
290-
288+
291289
// Get the formatted results
292290
let formatted_results: Vec<&Movie> = results.hits.iter().map(|r| r.formatted_result.as_ref().unwrap()).collect();
293291
search_parameter_guide_highlight_1: |-
@@ -297,7 +295,7 @@ search_parameter_guide_highlight_1: |-
297295
.execute()
298296
.await
299297
.unwrap();
300-
298+
301299
// Get the formatted results
302300
let formatted_results: Vec<&Movie> = results.hits.iter().map(|r| r.formatted_result.as_ref().unwrap()).collect();
303301
search_parameter_guide_filter_1: |-
@@ -323,7 +321,7 @@ search_parameter_guide_matches_1: |-
323321
.execute()
324322
.await
325323
.unwrap();
326-
324+
327325
// Get the matches info
328326
let matched_info: Vec<&HashMap<String, Vec<MatchRange>>> = results.hits.iter().map(|r| r.matches_info.as_ref().unwrap()).collect();
329327
settings_guide_synonyms_1: |-
@@ -426,7 +424,7 @@ getting_started_create_index_md: |-
426424
async fn main() {
427425
let client = Client::new("http://localhost:7700", "masterKey");
428426
// create an index if the index does not exist
429-
let movies = client.get_or_create("movies").await.unwrap();
427+
let movies = client.get_or_create("movies").await.unwrap();
430428
431429
// some code
432430
}
@@ -452,7 +450,7 @@ getting_started_add_documents_md: |-
452450
fn get_uid(&self) -> &Self::UIDType { &self.id }
453451
}
454452
```
455-
453+
456454
You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
457455
You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
458456
@@ -479,7 +477,7 @@ getting_started_add_documents_md: |-
479477
let mut content = String::new();
480478
file.read_to_string(&mut content).unwrap();
481479
let movies_docs: Vec<Movie> = serde_json::from_str(&content).unwrap();
482-
480+
483481
// adding documents
484482
movies.add_documents(&movies_docs, None).await.unwrap();
485483
```
@@ -489,10 +487,10 @@ getting_started_search_md: |-
489487
let query: Query = Query::new(&movies)
490488
.with_query("botman")
491489
.build();
492-
490+
493491
let results: SearchResults<Movie> = movies.execute_query(&query).await.unwrap();
494492
```
495-
493+
496494
You can build a Query and execute it directly:
497495
```rust
498496
let results: SearchResults<Movie> = Query::new(&movies)

src/client.rs

+3-39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{errors::*, indexes::*, request::*};
22
use serde_json::{json, Value};
3-
use serde::{Serialize, Deserialize};
3+
use serde::{Deserialize};
44
use std::collections::HashMap;
55

66
/// The top-level struct of the SDK, representing a client containing [indexes](../indexes/struct.Index.html).
@@ -186,7 +186,7 @@ impl<'a> Client<'a> {
186186
/// # async fn main() {
187187
/// let client = Client::new("http://localhost:7700", "masterKey");
188188
///
189-
/// match client.get_health().await {
189+
/// match client.health().await {
190190
/// Ok(()) => println!("server is operational"),
191191
/// Err(Error::MeiliSearchError { error_code: ErrorCode::Maintenance, .. }) => {
192192
/// eprintln!("server is in maintenance")
@@ -195,7 +195,7 @@ impl<'a> Client<'a> {
195195
/// }
196196
/// # }
197197
/// ```
198-
pub async fn get_health(&self) -> Result<(), Error> {
198+
pub async fn health(&self) -> Result<(), Error> {
199199
let r = request::<(), ()>(
200200
&format!("{}/health", self.host),
201201
self.apikey,
@@ -211,42 +211,6 @@ impl<'a> Client<'a> {
211211
}
212212
}
213213

214-
/// Update health of MeiliSearch server.
215-
///
216-
/// # Example
217-
///
218-
/// ```
219-
/// # use meilisearch_sdk::{client::*, indexes::*};
220-
/// #
221-
/// # #[tokio::main]
222-
/// # async fn main() {
223-
/// let client = Client::new("http://localhost:7700", "masterKey");
224-
///
225-
/// client.set_health(false).await.unwrap();
226-
/// # client.set_health(true).await.unwrap();
227-
/// # }
228-
/// ```
229-
pub async fn set_health(&self, health: bool) -> Result<(), Error> {
230-
#[derive(Debug, Serialize)]
231-
struct HealthBody {
232-
health: bool
233-
}
234-
235-
let r = request::<HealthBody, ()>(
236-
&format!("{}/health", self.host),
237-
self.apikey,
238-
Method::Put(HealthBody { health }),
239-
204,
240-
)
241-
.await;
242-
match r {
243-
// This shouldn't be an error; The status code is 200, but the request
244-
// function only supports one successful error code for some reason
245-
Err(Error::Empty) => Ok(()),
246-
e => e,
247-
}
248-
}
249-
250214
/// Get version of the MeiliSearch server.
251215
///
252216
/// # Example

src/errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum Error {
2121
/// The MeiliSearch server returned invalid JSON for a request.
2222
ParseError(serde_json::Error),
2323
/// An erroring status code, but no body
24-
// This is a hack to make Client::get_health work, since the request module
24+
// This is a hack to make Client::health work, since the request module
2525
// treats anything other than the expected status as an error. Since 204 is
2626
// specified, a successful status of 200 is treated as an error with an
2727
// empty body.
@@ -97,8 +97,7 @@ pub enum ErrorCode {
9797
InternalError,
9898
/// The provided token is invalid.
9999
InvalidToken,
100-
/// The MeiliSearch instance is under maintenance. You can set the maintenance
101-
/// state by using the `set_healthy` method of a Client.
100+
/// The MeiliSearch instance is under maintenance.
102101
Maintenance,
103102
/// The requested resources are protected with an API key, which was not
104103
/// provided in the request header.

0 commit comments

Comments
 (0)