Skip to content

Commit 9722db2

Browse files
authored
Merge branch 'main' into patch-1
2 parents 47e1266 + 90a153c commit 9722db2

File tree

3 files changed

+114
-39
lines changed

3 files changed

+114
-39
lines changed

.code-samples.meilisearch.yaml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,8 @@ primary_field_guide_add_document_primary_key: |-
10451045
], Some("reference_number"))
10461046
.await
10471047
.unwrap();
1048-
getting_started_add_documents_md: |-
1049-
```toml
1048+
getting_started_add_documents: |-
1049+
// In your .toml file:
10501050
[dependencies]
10511051
meilisearch-sdk = "0.28.0"
10521052
# futures: because we want to block on futures
@@ -1057,9 +1057,8 @@ getting_started_add_documents_md: |-
10571057
serde_json = "1.0"
10581058
```
10591059
1060-
Documents in the Rust library are strongly typed.
1061-
1062-
```rust
1060+
// In your .rs file:
1061+
// Documents in the Rust library are strongly typed
10631062
#[derive(Serialize, Deserialize)]
10641063
struct Movie {
10651064
id: i64,
@@ -1069,23 +1068,17 @@ getting_started_add_documents_md: |-
10691068
release_date: i64,
10701069
genres: Vec<String>
10711070
}
1072-
```
10731071
1074-
You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
1075-
You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
1076-
1077-
```rust
1072+
// You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
1073+
// You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
10781074
#[derive(Serialize, Deserialize)]
10791075
struct Movie {
10801076
id: i64,
10811077
#[serde(flatten)]
10821078
value: serde_json::Value,
10831079
}
1084-
```
10851080
1086-
Then, add documents into the index:
1087-
1088-
```rust
1081+
// Then, add documents into the index:
10891082
use meilisearch_sdk::{
10901083
indexes::*,
10911084
client::*,
@@ -1099,7 +1092,7 @@ getting_started_add_documents_md: |-
10991092
fn main() { block_on(async move {
11001093
let client = Client::new("http://localhost:7700", Some("aSampleMasterKey"));
11011094
1102-
// reading and parsing the file
1095+
// Reading and parsing the file
11031096
let mut file = File::open("movies.json")
11041097
.unwrap();
11051098
let mut content = String::new();
@@ -1109,19 +1102,15 @@ getting_started_add_documents_md: |-
11091102
let movies_docs: Vec<Movie> = serde_json::from_str(&content)
11101103
.unwrap();
11111104
1112-
// adding documents
1105+
// Adding documents
11131106
client
11141107
.index("movies")
11151108
.add_documents(&movies_docs, None)
11161109
.await
11171110
.unwrap();
11181111
})}
1119-
```
1120-
1121-
[About this SDK](https://github.com/meilisearch/meilisearch-rust/)
1122-
getting_started_search_md: |-
1123-
You can build a `SearchQuery` and execute it later:
1124-
```rust
1112+
getting_started_search: |-
1113+
// You can build a `SearchQuery` and execute it later:
11251114
let query: SearchQuery = SearchQuery::new(&movies)
11261115
.with_query("botman")
11271116
.build();
@@ -1131,29 +1120,22 @@ getting_started_search_md: |-
11311120
.execute_query(&query)
11321121
.await
11331122
.unwrap();
1134-
```
11351123
1136-
You can build a `SearchQuery` and execute it directly:
1137-
```rust
1124+
// You can build a `SearchQuery` and execute it directly:
11381125
let results: SearchResults<Movie> = SearchQuery::new(&movies)
11391126
.with_query("botman")
11401127
.execute()
11411128
.await
11421129
.unwrap();
1143-
```
11441130
1145-
You can search in an index directly:
1146-
```rust
1131+
// You can search in an index directly:
11471132
let results: SearchResults<Movie> = client
11481133
.index("movies")
11491134
.search()
11501135
.with_query("botman")
11511136
.execute()
11521137
.await
11531138
.unwrap();
1154-
```
1155-
1156-
[About this SDK](https://github.com/meilisearch/meilisearch-rust/)
11571139
getting_started_update_ranking_rules: |-
11581140
let ranking_rules = [
11591141
"exactness",
@@ -1650,7 +1632,7 @@ get_experimental_features_1: |-
16501632
update_experimental_features_1: |-
16511633
let client = Client::new("http://localhost:7700", Some("apiKey"));
16521634
let features = ExperimentalFeatures::new(&client);
1653-
// update the feature you want here
1635+
features.set_metrics(true)
16541636
let res = features
16551637
.update()
16561638
.await

src/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ impl<Http: HttpClient> Client<Http> {
11191119
#[serde(rename_all = "camelCase")]
11201120
pub struct ClientStats {
11211121
pub database_size: usize,
1122+
pub used_database_size: usize,
11221123
#[serde(with = "time::serde::rfc3339::option")]
11231124
pub last_update: Option<OffsetDateTime>,
11241125
pub indexes: HashMap<String, IndexStats>,

src/features.rs

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ use serde::{Deserialize, Serialize};
88
/// Struct representing the experimental features result from the API.
99
#[derive(Clone, Debug, Deserialize)]
1010
#[serde(rename_all = "camelCase")]
11-
pub struct ExperimentalFeaturesResult {}
11+
pub struct ExperimentalFeaturesResult {
12+
pub metrics: bool,
13+
pub logs_route: bool,
14+
pub contains_filter: bool,
15+
pub network: bool,
16+
pub edit_documents_by_function: bool,
17+
}
1218

1319
/// Struct representing the experimental features request.
1420
///
@@ -28,12 +34,30 @@ pub struct ExperimentalFeaturesResult {}
2834
pub struct ExperimentalFeatures<'a, Http: HttpClient> {
2935
#[serde(skip_serializing)]
3036
client: &'a Client<Http>,
37+
38+
#[serde(skip_serializing_if = "Option::is_none")]
39+
pub metrics: Option<bool>,
40+
#[serde(skip_serializing_if = "Option::is_none")]
41+
pub contains_filter: Option<bool>,
42+
#[serde(skip_serializing_if = "Option::is_none")]
43+
pub logs_route: Option<bool>,
44+
#[serde(skip_serializing_if = "Option::is_none")]
45+
pub network: Option<bool>,
46+
#[serde(skip_serializing_if = "Option::is_none")]
47+
pub edit_documents_by_function: Option<bool>,
3148
}
3249

3350
impl<'a, Http: HttpClient> ExperimentalFeatures<'a, Http> {
3451
#[must_use]
3552
pub fn new(client: &'a Client<Http>) -> Self {
36-
ExperimentalFeatures { client }
53+
ExperimentalFeatures {
54+
client,
55+
metrics: None,
56+
logs_route: None,
57+
network: None,
58+
contains_filter: None,
59+
edit_documents_by_function: None,
60+
}
3761
}
3862

3963
/// Get all the experimental features
@@ -88,6 +112,34 @@ impl<'a, Http: HttpClient> ExperimentalFeatures<'a, Http> {
88112
)
89113
.await
90114
}
115+
116+
pub fn set_metrics(&mut self, metrics: bool) -> &mut Self {
117+
self.metrics = Some(metrics);
118+
self
119+
}
120+
121+
pub fn set_logs_route(&mut self, logs_route: bool) -> &mut Self {
122+
self.logs_route = Some(logs_route);
123+
self
124+
}
125+
126+
pub fn set_contains_filter(&mut self, contains_filter: bool) -> &mut Self {
127+
self.contains_filter = Some(contains_filter);
128+
self
129+
}
130+
131+
pub fn set_edit_documents_by_function(
132+
&mut self,
133+
edit_documents_by_function: bool,
134+
) -> &mut Self {
135+
self.edit_documents_by_function = Some(edit_documents_by_function);
136+
self
137+
}
138+
139+
pub fn set_network(&mut self, network: bool) -> &mut Self {
140+
self.network = Some(network);
141+
self
142+
}
91143
}
92144

93145
#[cfg(test)]
@@ -96,12 +148,52 @@ mod tests {
96148
use meilisearch_test_macro::meilisearch_test;
97149

98150
#[meilisearch_test]
99-
async fn test_experimental_features_get(client: Client) {
100-
let features = ExperimentalFeatures::new(&client);
101-
// set feature here, once some exist again
151+
async fn test_experimental_features_set_metrics(client: Client) {
152+
let mut features = ExperimentalFeatures::new(&client);
153+
features.set_metrics(true);
154+
let _ = features.update().await.unwrap();
155+
156+
let res = features.get().await.unwrap();
157+
assert!(res.metrics)
158+
}
159+
160+
#[meilisearch_test]
161+
async fn test_experimental_features_set_logs_route(client: Client) {
162+
let mut features = ExperimentalFeatures::new(&client);
163+
features.set_logs_route(true);
164+
let _ = features.update().await.unwrap();
165+
166+
let res = features.get().await.unwrap();
167+
assert!(res.logs_route)
168+
}
169+
170+
#[meilisearch_test]
171+
async fn test_experimental_features_set_contains_filter(client: Client) {
172+
let mut features = ExperimentalFeatures::new(&client);
173+
features.set_contains_filter(true);
174+
let _ = features.update().await.unwrap();
175+
176+
let res = features.get().await.unwrap();
177+
assert!(res.contains_filter)
178+
}
179+
180+
#[meilisearch_test]
181+
async fn test_experimental_features_set_network(client: Client) {
182+
let mut features = ExperimentalFeatures::new(&client);
183+
features.set_network(true);
184+
let _ = features.update().await.unwrap();
185+
186+
let res = features.get().await.unwrap();
187+
assert!(res.network)
188+
}
189+
190+
#[meilisearch_test]
191+
async fn test_experimental_features_set_edit_documents_by_function(client: Client) {
192+
let mut features = ExperimentalFeatures::new(&client);
193+
features.set_edit_documents_by_function(true);
102194
let _ = features.update().await.unwrap();
103195

104-
let _res = features.get().await.unwrap();
105-
// assert that the feature has been set once they exist again
196+
let res = features.get().await.unwrap();
197+
assert!(res.edit_documents_by_function)
106198
}
107199
}

0 commit comments

Comments
 (0)