Skip to content

Commit f5c48ff

Browse files
committed
Merge branch 'dev' into update-stats-response
2 parents e64a10e + a658ec4 commit f5c48ff

File tree

10 files changed

+1176
-86
lines changed

10 files changed

+1176
-86
lines changed

.code-samples.meilisearch.yaml

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Every example written here will be automatically fetched by
33
# the documentation on build
44
# You can read more on https://github.com/meilisearch/documentation/tree/main/learn
5+
# See the original at https://github.com/meilisearch/documentation/blob/main/.code-samples.meilisearch.yaml
56
---
67
synonyms_guide_1: |-
78
let mut synonyms = std::collections::HashMap::new();
@@ -581,8 +582,12 @@ get_faceting_settings_1: |-
581582
.await
582583
.unwrap();
583584
update_faceting_settings_1: |-
585+
let mut facet_sort_setting = BTreeMap::new();
586+
facet_sort_setting.insert(String::from("*"), FacetSortValue::Alpha);
587+
facet_sort_setting.insert(String::from("genres"), FacetSortValue::Count);
584588
let mut faceting = FacetingSettings {
585589
max_values_per_facet: 2,
590+
sort_facet_values_by: Some(facet_sort_setting),
586591
};
587592
588593
let task: TaskInfo = client
@@ -1045,8 +1050,8 @@ primary_field_guide_add_document_primary_key: |-
10451050
], Some("reference_number"))
10461051
.await
10471052
.unwrap();
1048-
getting_started_add_documents_md: |-
1049-
```toml
1053+
getting_started_add_documents: |-
1054+
// In your .toml file:
10501055
[dependencies]
10511056
meilisearch-sdk = "0.28.0"
10521057
# futures: because we want to block on futures
@@ -1057,9 +1062,8 @@ getting_started_add_documents_md: |-
10571062
serde_json = "1.0"
10581063
```
10591064
1060-
Documents in the Rust library are strongly typed.
1061-
1062-
```rust
1065+
// In your .rs file:
1066+
// Documents in the Rust library are strongly typed
10631067
#[derive(Serialize, Deserialize)]
10641068
struct Movie {
10651069
id: i64,
@@ -1069,23 +1073,17 @@ getting_started_add_documents_md: |-
10691073
release_date: i64,
10701074
genres: Vec<String>
10711075
}
1072-
```
1073-
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:
10761076
1077-
```rust
1077+
// You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
1078+
// You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
10781079
#[derive(Serialize, Deserialize)]
10791080
struct Movie {
10801081
id: i64,
10811082
#[serde(flatten)]
10821083
value: serde_json::Value,
10831084
}
1084-
```
1085-
1086-
Then, add documents into the index:
10871085
1088-
```rust
1086+
// Then, add documents into the index:
10891087
use meilisearch_sdk::{
10901088
indexes::*,
10911089
client::*,
@@ -1099,7 +1097,7 @@ getting_started_add_documents_md: |-
10991097
fn main() { block_on(async move {
11001098
let client = Client::new("http://localhost:7700", Some("aSampleMasterKey"));
11011099
1102-
// reading and parsing the file
1100+
// Reading and parsing the file
11031101
let mut file = File::open("movies.json")
11041102
.unwrap();
11051103
let mut content = String::new();
@@ -1109,19 +1107,15 @@ getting_started_add_documents_md: |-
11091107
let movies_docs: Vec<Movie> = serde_json::from_str(&content)
11101108
.unwrap();
11111109
1112-
// adding documents
1110+
// Adding documents
11131111
client
11141112
.index("movies")
11151113
.add_documents(&movies_docs, None)
11161114
.await
11171115
.unwrap();
11181116
})}
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
1117+
getting_started_search: |-
1118+
// You can build a `SearchQuery` and execute it later:
11251119
let query: SearchQuery = SearchQuery::new(&movies)
11261120
.with_query("botman")
11271121
.build();
@@ -1131,29 +1125,22 @@ getting_started_search_md: |-
11311125
.execute_query(&query)
11321126
.await
11331127
.unwrap();
1134-
```
11351128
1136-
You can build a `SearchQuery` and execute it directly:
1137-
```rust
1129+
// You can build a `SearchQuery` and execute it directly:
11381130
let results: SearchResults<Movie> = SearchQuery::new(&movies)
11391131
.with_query("botman")
11401132
.execute()
11411133
.await
11421134
.unwrap();
1143-
```
11441135
1145-
You can search in an index directly:
1146-
```rust
1136+
// You can search in an index directly:
11471137
let results: SearchResults<Movie> = client
11481138
.index("movies")
11491139
.search()
11501140
.with_query("botman")
11511141
.execute()
11521142
.await
11531143
.unwrap();
1154-
```
1155-
1156-
[About this SDK](https://github.com/meilisearch/meilisearch-rust/)
11571144
getting_started_update_ranking_rules: |-
11581145
let ranking_rules = [
11591146
"exactness",
@@ -1283,8 +1270,11 @@ getting_started_sorting: |-
12831270
.await
12841271
.unwrap();
12851272
getting_started_faceting: |-
1273+
let mut facet_sort_setting = BTreeMap::new();
1274+
facet_sort_setting.insert("*".to_string(), FacetSortValue::Count);
12861275
let mut faceting = FacetingSettings {
12871276
max_values_per_facet: 2,
1277+
sort_facet_values_by: Some(facet_sort_setting),
12881278
};
12891279
12901280
let task: TaskInfo = client
@@ -1650,7 +1640,7 @@ get_experimental_features_1: |-
16501640
update_experimental_features_1: |-
16511641
let client = Client::new("http://localhost:7700", Some("apiKey"));
16521642
let features = ExperimentalFeatures::new(&client);
1653-
// update the feature you want here
1643+
features.set_metrics(true)
16541644
let res = features
16551645
.update()
16561646
.await
@@ -1681,6 +1671,33 @@ reset_proximity_precision_settings_1: |-
16811671
.reset_proximity_precision()
16821672
.await
16831673
.unwrap();
1674+
facet_search_1: |-
1675+
let res = client.index("books")
1676+
.facet_search("genres")
1677+
.with_facet_query("fiction")
1678+
.with_filter("rating > 3")
1679+
.execute()
1680+
.await
1681+
.unwrap();
1682+
facet_search_2: |-
1683+
let mut facet_sort_setting = BTreeMap::new();
1684+
facet_sort_setting.insert("genres".to_string(), FacetSortValue::Count);
1685+
let faceting = FacetingSettings {
1686+
max_values_per_facet: 100,
1687+
sort_facet_values_by: Some(facet_sort_setting),
1688+
};
1689+
1690+
let res = client.index("books")
1691+
.set_faceting(&faceting)
1692+
.await
1693+
.unwrap();
1694+
facet_search_3: |-
1695+
let res = client.index("books")
1696+
.facet_search("genres")
1697+
.with_facet_query("c")
1698+
.execute()
1699+
.await
1700+
.unwrap();
16841701
get_search_cutoff_1: |-
16851702
let search_cutoff_ms: String = client
16861703
.index("movies")

.github/workflows/tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,36 @@ jobs:
8383
uses: ibiqlik/action-yamllint@v3
8484
with:
8585
config_file: .yamllint.yml
86+
87+
coverage:
88+
# Will not run if the actor is Dependabot (dependabot PRs)
89+
# Will not run if the event is a PR to bump-meilisearch-v* (so a pre-release PR)
90+
if: github.actor != 'dependabot[bot]' && !( github.event_name == 'pull_request' && startsWith(github.base_ref, 'bump-meilisearch-v') )
91+
runs-on: ubuntu-latest
92+
needs: integration_tests
93+
name: Code Coverage
94+
steps:
95+
- uses: actions/checkout@v4
96+
# Nightly Rust is used for cargo llvm-cov --doc below.
97+
- uses: dtolnay/rust-toolchain@nightly
98+
with:
99+
components: llvm-tools-preview
100+
- name: Install cargo-llvm-cov
101+
uses: taiki-e/install-action@v2
102+
with:
103+
tool: cargo-llvm-cov
104+
- name: Meilisearch (latest version) setup with Docker
105+
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
106+
- name: Collect coverage data
107+
# Generate separate reports for tests and doctests, and combine them.
108+
run: |
109+
set -euo pipefail
110+
cargo llvm-cov --no-report --all-features --workspace
111+
cargo llvm-cov --no-report --doc --all-features --workspace
112+
cargo llvm-cov report --doctests --codecov --output-path codecov.json
113+
- name: Upload coverage reports to Codecov
114+
uses: codecov/codecov-action@v5
115+
with:
116+
token: ${{ secrets.CODECOV_TOKEN }}
117+
files: codecov.json
118+
fail_ci_if_error: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<a href="https://github.com/meilisearch/meilisearch-rust/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
2525
<a href="https://github.com/meilisearch/meilisearch/discussions" alt="Discussions"><img src="https://img.shields.io/badge/github-discussions-red" /></a>
2626
<a href="https://ms-bors.herokuapp.com/repositories/62"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
27+
<a href="https://codecov.io/gh/meilisearch/meilisearch-rust" ><img src="https://codecov.io/gh/meilisearch/meilisearch-rust/graph/badge.svg?token=NVO9OI8JMG"/></a>
2728
</p>
2829

2930
<p align="center">⚡ The Meilisearch API client written for Rust 🦀</p>

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)