Skip to content

Commit

Permalink
Merge branch 'main' into vector-search-embedder
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Jul 8, 2024
2 parents 464de44 + c673c8d commit 4cf2da8
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
37 changes: 36 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ primary_field_guide_add_document_primary_key: |-
getting_started_add_documents_md: |-
```toml
[dependencies]
meilisearch-sdk = "0.26.1"
meilisearch-sdk = "0.27.0"
# futures: because we want to block on futures
futures = "0.3"
# serde: required if you are going to use documents
Expand Down Expand Up @@ -1704,3 +1704,38 @@ create_snapshot_1: |-
.create_snapshot()
.await
.unwrap();
search_parameter_reference_distinct_1: |-
let res = client
.index("INDEX_NAME")
.search()
.with_query("QUERY TERMS")
.with_distinct("ATTRIBUTE_A")
.execute()
.await
.unwrap();
distinct_attribute_guide_filterable_1: |-
let task: TaskInfo = client
.index("products")
.settings()
.set_filterable_attributes(["product_id", "sku", "url"])
.execute()
.await
.unwrap();
distinct_attribute_guide_distinct_parameter_1: |-
let res = client
.index("products")
.search()
.with_query("white shirt")
.with_distinct("sku")
.execute()
.await
.unwrap();
search_parameter_reference_ranking_score_threshold_1: |-
let res = client
.index("INDEX_NAME")
.search()
.with_query("badman")
.with_ranking_score_threshold(0.2)
.execute()
.await
.unwrap();
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meilisearch-sdk"
version = "0.26.1"
version = "0.27.0"
authors = ["Mubelotix <[email protected]>"]
edition = "2018"
description = "Rust wrapper for the Meilisearch API. Meilisearch is a powerful, fast, open-source, easy to use and deploy search engine."
Expand All @@ -21,7 +21,7 @@ time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsi
yaup = "0.3.1"
either = { version = "1.8.0", features = ["serde"] }
thiserror = "1.0.37"
meilisearch-index-setting-macro = { path = "meilisearch-index-setting-macro", version = "0.26.1" }
meilisearch-index-setting-macro = { path = "meilisearch-index-setting-macro", version = "0.27.0" }
pin-project-lite = { version = "0.2.13", optional = true }
reqwest = { version = "0.12.3", optional = true, default-features = false, features = ["rustls-tls", "http2", "stream"] }
bytes = { version = "1.6", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To use `meilisearch-sdk`, add this to your `Cargo.toml`:

```toml
[dependencies]
meilisearch-sdk = "0.26.1"
meilisearch-sdk = "0.27.0"
```

The following optional dependencies may also be useful:
Expand Down
2 changes: 1 addition & 1 deletion README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To use `meilisearch-sdk`, add this to your `Cargo.toml`:

```toml
[dependencies]
meilisearch-sdk = "0.26.1"
meilisearch-sdk = "0.27.0"
```

The following optional dependencies may also be useful:
Expand Down
2 changes: 1 addition & 1 deletion meilisearch-index-setting-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meilisearch-index-setting-macro"
version = "0.26.1"
version = "0.27.0"
description = "Helper tool to generate settings of a Meilisearch index"
edition = "2021"
license = "MIT"
Expand Down
51 changes: 50 additions & 1 deletion src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ pub struct SearchQuery<'a, Http: HttpClient> {
#[serde(skip_serializing_if = "Option::is_none")]
pub matching_strategy: Option<MatchingStrategies>,

///Defines one attribute in the filterableAttributes list as a distinct attribute.
#[serde(skip_serializing_if = "Option::is_none")]
pub distinct: Option<&'a str>,

///Excludes results below the specified ranking score.
#[serde(skip_serializing_if = "Option::is_none")]
pub ranking_score_threshold: Option<f64>,

#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) index_uid: Option<&'a str>,

Expand Down Expand Up @@ -404,6 +412,8 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
hybrid: None,
vector: None,
retrieve_vectors: None,
distinct: None,
ranking_score_threshold: None,
}
}
pub fn with_query<'b>(&'b mut self, query: &'a str) -> &'b mut SearchQuery<'a, Http> {
Expand Down Expand Up @@ -622,8 +632,18 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
self.vector = Some(vector);
self
}

#[must_use]
pub fn with_distinct<'b>(&'b mut self, distinct: &'a str) -> &'b mut SearchQuery<'a, Http> {
self.distinct = Some(distinct);
self
}
pub fn with_ranking_score_threshold<'b>(
&'b mut self,
ranking_score_threshold: f64,
) -> &'b mut SearchQuery<'a, Http> {
self.ranking_score_threshold = Some(ranking_score_threshold);
self
}
pub fn build(&mut self) -> SearchQuery<'a, Http> {
self.clone()
}
Expand Down Expand Up @@ -1218,6 +1238,21 @@ mod tests {
Ok(())
}

#[meilisearch_test]
async fn test_query_show_ranking_score_threshold(
client: Client,
index: Index,
) -> Result<(), Error> {
setup_test_index(&client, &index).await?;

let mut query = SearchQuery::new(&index);
query.with_query("dolor text");
query.with_ranking_score_threshold(1.0);
let results: SearchResults<Document> = index.execute_query(&query).await.unwrap();
assert!(results.hits.is_empty());
Ok(())
}

#[meilisearch_test]
async fn test_phrase_search(client: Client, index: Index) -> Result<(), Error> {
setup_test_index(&client, &index).await?;
Expand Down Expand Up @@ -1275,6 +1310,20 @@ mod tests {
Ok(())
}

#[meilisearch_test]
async fn test_distinct(client: Client, index: Index) -> Result<(), Error> {
setup_test_index(&client, &index).await?;

let results = SearchQuery::new(&index)
.with_distinct("kind")
.execute::<Document>()
.await
.unwrap();

assert_eq!(results.hits.len(), 2);
Ok(())
}

#[meilisearch_test]
async fn test_generate_tenant_token_from_client(
client: Client,
Expand Down

0 comments on commit 4cf2da8

Please sign in to comment.