Skip to content

Commit f374f81

Browse files
committed
Added locales parameter to SearchQuery
1 parent 38309ef commit f374f81

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,3 +1739,12 @@ search_parameter_reference_ranking_score_threshold_1: |-
17391739
.execute()
17401740
.await
17411741
.unwrap();
1742+
search_parameter_reference_locales_1: |-
1743+
let res = client
1744+
.index("books")
1745+
.search()
1746+
.with_query("進撃の巨人")
1747+
.with_locales(&["jpn"])
1748+
.execute()
1749+
.await
1750+
.unwrap();

src/search.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ pub struct SearchQuery<'a, Http: HttpClient> {
344344
#[serde(skip_serializing_if = "Option::is_none")]
345345
pub ranking_score_threshold: Option<f64>,
346346

347+
/// Defines the language of the search query.
348+
#[serde(skip_serializing_if = "Option::is_none")]
349+
pub locales: Option<&'a [&'a str]>,
350+
347351
#[serde(skip_serializing_if = "Option::is_none")]
348352
pub(crate) index_uid: Option<&'a str>,
349353
}
@@ -377,6 +381,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
377381
index_uid: None,
378382
distinct: None,
379383
ranking_score_threshold: None,
384+
locales: None,
380385
}
381386
}
382387
pub fn with_query<'b>(&'b mut self, query: &'a str) -> &'b mut SearchQuery<'a, Http> {
@@ -580,6 +585,10 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
580585
self.ranking_score_threshold = Some(ranking_score_threshold);
581586
self
582587
}
588+
pub fn with_locales<'b>(&'b mut self, locales: &'a [&'a str]) -> &'b mut SearchQuery<'a, Http> {
589+
self.locales = Some(locales);
590+
self
591+
}
583592
pub fn build(&mut self) -> SearchQuery<'a, Http> {
584593
self.clone()
585594
}
@@ -1161,6 +1170,18 @@ mod tests {
11611170
Ok(())
11621171
}
11631172

1173+
#[meilisearch_test]
1174+
async fn test_query_locales(client: Client, index: Index) -> Result<(), Error> {
1175+
setup_test_index(&client, &index).await?;
1176+
1177+
let mut query = SearchQuery::new(&index);
1178+
query.with_query("Harry Styles");
1179+
query.with_locales(&["eng"]);
1180+
let results: SearchResults<Document> = index.execute_query(&query).await.unwrap();
1181+
assert_eq!(results.hits.len(), 7);
1182+
Ok(())
1183+
}
1184+
11641185
#[meilisearch_test]
11651186
async fn test_phrase_search(client: Client, index: Index) -> Result<(), Error> {
11661187
setup_test_index(&client, &index).await?;

0 commit comments

Comments
 (0)