Skip to content

Commit d3e89fe

Browse files
committed
Make tests pass
1 parent 428672c commit d3e89fe

File tree

3 files changed

+63
-130
lines changed

3 files changed

+63
-130
lines changed

src/documents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub struct DocumentsQuery<'a, Http: HttpClient> {
193193
/// Filters to apply.
194194
///
195195
/// Available since v1.2 of Meilisearch
196-
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/fine_tuning_results/filtering#filter-basics) to learn the syntax.
196+
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/filtering_and_sorting) to learn the syntax.
197197
#[serde(skip_serializing_if = "Option::is_none")]
198198
pub filter: Option<&'a str>,
199199
}

src/search.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub struct SearchQuery<'a, Http: HttpClient> {
282282
pub hits_per_page: Option<usize>,
283283
/// Filter applied to documents.
284284
///
285-
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/advanced/filtering) to learn the syntax.
285+
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/filtering_and_sorting) to learn the syntax.
286286
#[serde(skip_serializing_if = "Option::is_none")]
287287
pub filter: Option<Filter<'a>>,
288288
/// Facets for which to retrieve the matching count.
@@ -971,7 +971,7 @@ pub struct FacetSearchQuery<'a, Http: HttpClient = DefaultHttpClient> {
971971
pub search_query: Option<&'a str>,
972972
/// Filter applied to documents.
973973
///
974-
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/advanced/filtering) to learn the syntax.
974+
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/filtering_and_sorting) to learn the syntax.
975975
#[serde(skip_serializing_if = "Option::is_none")]
976976
pub filter: Option<Filter<'a>>,
977977
/// Defines the strategy on how to handle search queries containing multiple words.
@@ -1078,7 +1078,7 @@ pub struct FacetSearchResponse {
10781078
}
10791079

10801080
#[cfg(test)]
1081-
mod tests {
1081+
pub(crate) mod tests {
10821082
use crate::{
10831083
client::*,
10841084
key::{Action, KeyBuilder},
@@ -1091,19 +1091,19 @@ mod tests {
10911091
use serde_json::{json, Map, Value};
10921092

10931093
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1094-
struct Nested {
1094+
pub struct Nested {
10951095
child: String,
10961096
}
10971097

10981098
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1099-
struct Document {
1100-
id: usize,
1101-
value: String,
1102-
kind: String,
1103-
number: i32,
1104-
nested: Nested,
1099+
pub struct Document {
1100+
pub id: usize,
1101+
pub value: String,
1102+
pub kind: String,
1103+
pub number: i32,
1104+
pub nested: Nested,
11051105
#[serde(skip_serializing_if = "Option::is_none", default)]
1106-
_vectors: Option<Vectors>,
1106+
pub _vectors: Option<Vectors>,
11071107
}
11081108

11091109
#[derive(Debug, Serialize, Deserialize, PartialEq)]
@@ -1120,7 +1120,7 @@ mod tests {
11201120
}
11211121

11221122
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1123-
struct Vectors(HashMap<String, Vector>);
1123+
pub struct Vectors(HashMap<String, Vector>);
11241124

11251125
impl<T: Into<Vec<f32>>> From<T> for Vectors {
11261126
fn from(value: T) -> Self {
@@ -1151,7 +1151,7 @@ mod tests {
11511151
vector
11521152
}
11531153

1154-
async fn setup_test_index(client: &Client, index: &Index) -> Result<(), Error> {
1154+
pub(crate) async fn setup_test_index(client: &Client, index: &Index) -> Result<(), Error> {
11551155
let t0 = index.add_documents(&[
11561156
Document { id: 0, kind: "text".into(), number: 0, value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), nested: Nested { child: S("first") }, _vectors: Some(Vectors::from(vectorize(false, 0))) },
11571157
Document { id: 1, kind: "text".into(), number: 10, value: S("dolor sit amet, consectetur adipiscing elit"), nested: Nested { child: S("second") }, _vectors: Some(Vectors::from(vectorize(false, 1))) },
@@ -1225,7 +1225,7 @@ mod tests {
12251225
Ok(())
12261226
}
12271227

1228-
async fn setup_hybrid_searching(client: &Client, index: &Index) -> Result<(), Error> {
1228+
pub(crate) async fn setup_embedder(client: &Client, index: &Index) -> Result<(), Error> {
12291229
use crate::settings::Embedder;
12301230
let embedder_setting = Embedder {
12311231
source: EmbedderSource::UserProvided,
@@ -1998,7 +1998,7 @@ mod tests {
19981998

19991999
#[meilisearch_test]
20002000
async fn test_with_vectors(client: Client, index: Index) -> Result<(), Error> {
2001-
setup_hybrid_searching(&client, &index).await?;
2001+
setup_embedder(&client, &index).await?;
20022002
setup_test_index(&client, &index).await?;
20032003

20042004
let results: SearchResults<Document> = index
@@ -2024,7 +2024,7 @@ mod tests {
20242024

20252025
#[meilisearch_test]
20262026
async fn test_hybrid(client: Client, index: Index) -> Result<(), Error> {
2027-
setup_hybrid_searching(&client, &index).await?;
2027+
setup_embedder(&client, &index).await?;
20282028
setup_test_index(&client, &index).await?;
20292029

20302030
// Search for an Harry Potter but with lorem ipsum's id

src/similar.rs

Lines changed: 46 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ pub struct SimilarResults<T> {
8383
pub struct SimilarQuery<'a, Http: HttpClient> {
8484
#[serde(skip_serializing)]
8585
index: &'a Index<Http>,
86-
86+
8787
/// Document id
8888
pub id: &'a str,
8989

9090
/// embedder name
9191
pub embedder: &'a str,
92-
92+
9393
/// The number of documents to skip.
9494
/// If the value of the parameter `offset` is `n`, the `n` first documents (ordered by relevance) will not be returned.
9595
/// This is helpful for pagination.
@@ -111,7 +111,7 @@ pub struct SimilarQuery<'a, Http: HttpClient> {
111111

112112
/// Filter applied to documents.
113113
///
114-
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/advanced/filtering) to learn the syntax.
114+
/// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/filtering_and_sorting) to learn the syntax.
115115
#[serde(skip_serializing_if = "Option::is_none")]
116116
pub filter: Option<Filter<'a>>,
117117

@@ -178,7 +178,7 @@ impl<'a, Http: HttpClient> SimilarQuery<'a, Http> {
178178
self.filter = Some(Filter::new(Either::Left(filter)));
179179
self
180180
}
181-
181+
182182
pub fn with_array_filter<'b>(
183183
&'b mut self,
184184
filter: Vec<&'a str>,
@@ -236,116 +236,33 @@ mod tests {
236236
use std::vec;
237237

238238
use super::*;
239-
use crate::{client::*, search::*};
239+
use crate::{
240+
client::*,
241+
search::{
242+
tests::{setup_embedder, setup_test_index, Document},
243+
*,
244+
},
245+
};
240246
use meilisearch_test_macro::meilisearch_test;
241-
use serde::{Deserialize, Serialize};
242-
use std::collections::HashMap;
243-
244-
#[derive(Debug, Serialize, Deserialize, PartialEq)]
245-
struct Nested {
246-
child: String,
247-
}
248-
249-
#[derive(Debug, Serialize, Deserialize, PartialEq)]
250-
struct Document {
251-
id: usize,
252-
title: String,
253-
_vectors: HashMap<String, Vec<f64>>,
254-
}
255-
256-
async fn setup_test_vector_index(client: &Client, index: &Index) -> Result<(), Error> {
257-
let v = vec![0.5, 0.5];
258-
let mut vectors = HashMap::new();
259-
260-
vectors.insert("default".to_string(), v.clone());
261-
262-
let t0 = index
263-
.add_documents(
264-
&[
265-
Document {
266-
id: 0,
267-
title: "text".into(),
268-
_vectors: vectors.clone(),
269-
},
270-
Document {
271-
id: 1,
272-
title: "text".into(),
273-
_vectors: vectors.clone(),
274-
},
275-
Document {
276-
id: 2,
277-
title: "title".into(),
278-
_vectors: vectors.clone(),
279-
},
280-
Document {
281-
id: 3,
282-
title: "title".into(),
283-
_vectors: vectors.clone(),
284-
},
285-
Document {
286-
id: 4,
287-
title: "title".into(),
288-
_vectors: vectors.clone(),
289-
},
290-
Document {
291-
id: 5,
292-
title: "title".into(),
293-
_vectors: vectors.clone(),
294-
},
295-
Document {
296-
id: 6,
297-
title: "title".into(),
298-
_vectors: vectors.clone(),
299-
},
300-
Document {
301-
id: 7,
302-
title: "title".into(),
303-
_vectors: vectors.clone(),
304-
},
305-
Document {
306-
id: 8,
307-
title: "title".into(),
308-
_vectors: vectors.clone(),
309-
},
310-
Document {
311-
id: 9,
312-
title: "title".into(),
313-
_vectors: vectors.clone(),
314-
},
315-
],
316-
None,
317-
)
318-
.await?;
319-
320-
let t1 = index.set_filterable_attributes(["title"]).await?;
321-
t1.wait_for_completion(client, None, None).await?;
322-
t0.wait_for_completion(client, None, None).await?;
323-
Ok(())
324-
}
325-
326-
#[meilisearch_test]
327-
async fn test_similar_builder(_client: Client, index: Index) -> Result<(), Error> {
328-
let mut query = SimilarQuery::new(&index, "1", "default");
329-
query.with_offset(1).with_limit(1);
330-
331-
Ok(())
332-
}
333247

334248
#[meilisearch_test]
335249
async fn test_query_limit(client: Client, index: Index) -> Result<(), Error> {
336-
setup_test_vector_index(&client, &index).await?;
250+
setup_embedder(&client, &index).await?;
251+
setup_test_index(&client, &index).await?;
337252

338253
let mut query = SimilarQuery::new(&index, "1", "default");
339-
query.with_limit(5);
254+
query.with_limit(3);
340255

341256
let results: SimilarResults<Document> = query.execute().await?;
342-
assert_eq!(results.hits.len(), 5);
257+
assert_eq!(results.hits.len(), 3);
343258
Ok(())
344259
}
345260

346261
#[meilisearch_test]
347262
async fn test_query_offset(client: Client, index: Index) -> Result<(), Error> {
348-
setup_test_vector_index(&client, &index).await?;
263+
setup_embedder(&client, &index).await?;
264+
setup_test_index(&client, &index).await?;
265+
349266
let mut query = SimilarQuery::new(&index, "1", "default");
350267
query.with_offset(6);
351268

@@ -356,42 +273,54 @@ mod tests {
356273

357274
#[meilisearch_test]
358275
async fn test_query_filter(client: Client, index: Index) -> Result<(), Error> {
359-
setup_test_vector_index(&client, &index).await?;
276+
setup_embedder(&client, &index).await?;
277+
setup_test_index(&client, &index).await?;
360278

361279
let mut query = SimilarQuery::new(&index, "1", "default");
362280

363281
let results: SimilarResults<Document> =
364-
query.with_filter("title = \"title\"").execute().await?;
282+
query.with_filter("kind = \"title\"").execute().await?;
365283
assert_eq!(results.hits.len(), 8);
366284

367285
let results: SimilarResults<Document> =
368-
query.with_filter("NOT title = \"title\"").execute().await?;
369-
assert_eq!(results.hits.len(), 2);
286+
query.with_filter("NOT kind = \"title\"").execute().await?;
287+
assert_eq!(results.hits.len(), 1);
370288
Ok(())
371289
}
372290

373291
#[meilisearch_test]
374292
async fn test_query_filter_with_array(client: Client, index: Index) -> Result<(), Error> {
375-
setup_test_vector_index(&client, &index).await?;
293+
setup_embedder(&client, &index).await?;
294+
setup_test_index(&client, &index).await?;
295+
376296
let mut query = SimilarQuery::new(&index, "1", "default");
377297
let results: SimilarResults<Document> = query
378-
.with_array_filter(vec!["title = \"title\"", "title = \"text\""])
298+
.with_array_filter(vec!["kind = \"title\"", "kind = \"text\""])
379299
.execute()
380300
.await?;
381-
assert_eq!(results.hits.len(), 10);
301+
assert_eq!(results.hits.len(), 0);
302+
303+
let mut query = SimilarQuery::new(&index, "1", "default");
304+
let results: SimilarResults<Document> = query
305+
.with_array_filter(vec!["kind = \"title\"", "number <= 50"])
306+
.execute()
307+
.await?;
308+
assert_eq!(results.hits.len(), 4);
382309

383310
Ok(())
384311
}
385312

386313
#[meilisearch_test]
387314
async fn test_query_attributes_to_retrieve(client: Client, index: Index) -> Result<(), Error> {
388-
setup_test_vector_index(&client, &index).await?;
315+
setup_embedder(&client, &index).await?;
316+
setup_test_index(&client, &index).await?;
317+
389318
let mut query = SimilarQuery::new(&index, "1", "default");
390319
let results: SimilarResults<Document> = query
391320
.with_attributes_to_retrieve(Selectors::All)
392321
.execute()
393322
.await?;
394-
assert_eq!(results.hits.len(), 10);
323+
assert_eq!(results.hits.len(), 9);
395324

396325
let mut query = SimilarQuery::new(&index, "1", "default");
397326
query.with_attributes_to_retrieve(Selectors::Some(&["title", "id"])); // omit the "value" field
@@ -401,7 +330,8 @@ mod tests {
401330

402331
#[meilisearch_test]
403332
async fn test_query_show_ranking_score(client: Client, index: Index) -> Result<(), Error> {
404-
setup_test_vector_index(&client, &index).await?;
333+
setup_embedder(&client, &index).await?;
334+
setup_test_index(&client, &index).await?;
405335

406336
let mut query = SimilarQuery::new(&index, "1", "default");
407337
query.with_show_ranking_score(true);
@@ -415,7 +345,8 @@ mod tests {
415345
client: Client,
416346
index: Index,
417347
) -> Result<(), Error> {
418-
setup_test_vector_index(&client, &index).await?;
348+
setup_embedder(&client, &index).await?;
349+
setup_test_index(&client, &index).await?;
419350

420351
let mut query = SimilarQuery::new(&index, "1", "default");
421352
query.with_show_ranking_score_details(true);
@@ -429,7 +360,9 @@ mod tests {
429360
client: Client,
430361
index: Index,
431362
) -> Result<(), Error> {
432-
setup_test_vector_index(&client, &index).await?;
363+
setup_embedder(&client, &index).await?;
364+
setup_test_index(&client, &index).await?;
365+
433366
let mut query = SimilarQuery::new(&index, "1", "default");
434367
query.with_ranking_score_threshold(1.0);
435368
let results: SimilarResults<Document> = query.execute().await?;

0 commit comments

Comments
 (0)