Skip to content

Commit 0c9777f

Browse files
committed
Add meaning test
1 parent d3e89fe commit 0c9777f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/similar.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ impl<'a, Http: HttpClient> SimilarQuery<'a, Http> {
219219
self
220220
}
221221

222+
pub fn with_retrieve_vectors<'b>(
223+
&'b mut self,
224+
retrieve_vectors: bool,
225+
) -> &'b mut SimilarQuery<'a, Http> {
226+
self.retrieve_vectors = Some(retrieve_vectors);
227+
self
228+
}
229+
222230
pub fn build(&mut self) -> SimilarQuery<'a, Http> {
223231
self.clone()
224232
}
@@ -245,6 +253,28 @@ mod tests {
245253
};
246254
use meilisearch_test_macro::meilisearch_test;
247255

256+
#[meilisearch_test]
257+
async fn test_similar_results(client: Client, index: Index) -> Result<(), Error> {
258+
setup_embedder(&client, &index).await?;
259+
setup_test_index(&client, &index).await?;
260+
261+
// Test on a non-harry-potter document
262+
let mut query = SimilarQuery::new(&index, "0", "default");
263+
query.with_limit(1);
264+
let results: SimilarResults<Document> = query.execute().await?;
265+
let result = results.hits.first().unwrap();
266+
assert_eq!(result.result.id, 1);
267+
268+
// Test on a harry-potter document
269+
let mut query = SimilarQuery::new(&index, "3", "default");
270+
query.with_limit(1);
271+
let results: SimilarResults<Document> = query.execute().await?;
272+
let result = results.hits.first().unwrap();
273+
assert_eq!(result.result.id, 4);
274+
275+
Ok(())
276+
}
277+
248278
#[meilisearch_test]
249279
async fn test_query_limit(client: Client, index: Index) -> Result<(), Error> {
250280
setup_embedder(&client, &index).await?;

0 commit comments

Comments
 (0)