Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ pub struct SearchResults<T> {
skip_serializing_if = "Option::is_none"
)]
pub query_vector: Option<Vec<f32>>,
/// The search query's performance trace.
/// Returned when `showPerformanceDetails` is enabled.
pub performance_details: Option<Value>,
}

fn serialize_attributes_to_crop_with_wildcard<S: Serializer>(
Expand Down Expand Up @@ -424,6 +427,12 @@ pub struct SearchQuery<'a, Http: HttpClient> {

#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) federation_options: Option<QueryFederationOptions>,

/// Defines whether to return performance trace.
///
/// **Default: `false`**
#[serde(skip_serializing_if = "Option::is_none")]
pub show_performance_details: Option<bool>,
}

#[derive(Debug, Serialize, Clone)]
Expand Down Expand Up @@ -473,6 +482,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
ranking_score_threshold: None,
locales: None,
federation_options: None,
show_performance_details: None,
}
}

Expand Down Expand Up @@ -752,6 +762,15 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
self
}

/// Request performance details in the response.
pub fn with_show_performance_details<'b>(
&'b mut self,
show_performance_details: bool,
) -> &'b mut SearchQuery<'a, Http> {
self.show_performance_details = Some(show_performance_details);
self
}

/// Execute the query and fetch the results.
pub async fn execute<T: 'static + DeserializeOwned + Send + Sync>(
&'a self,
Expand Down Expand Up @@ -880,6 +899,10 @@ pub struct FederationOptions {
/// Request to merge the facets to enforce a maximum number of values per facet.
#[serde(skip_serializing_if = "Option::is_none")]
pub merge_facets: Option<MergeFacets>,

/// Request performance details in the response.
#[serde(skip_serializing_if = "Option::is_none")]
pub show_performance_details: Option<bool>,
}

impl<'a, Http: HttpClient> FederatedMultiSearchQuery<'a, '_, Http> {
Expand Down Expand Up @@ -929,6 +952,9 @@ pub struct FederatedMultiSearchResponse<T> {

/// Indicates which remote requests failed and why
pub remote_errors: Option<HashMap<String, MeilisearchError>>,

/// The performance trace for the query.
pub performance_details: Option<Value>,
}

/// Returned for each hit in `_federation` when doing federated multi search.
Expand Down Expand Up @@ -2305,4 +2331,70 @@ pub(crate) mod tests {
assert_eq!(res.facet_hits[0].count, 7);
Ok(())
}

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

let res = index
.search()
.with_show_performance_details(true)
.with_query("Lorem")
.execute::<Value>()
.await?;

assert!(res.performance_details.is_some());

Ok(())
}

#[meilisearch_test]
async fn test_multi_search_with_show_performance_details(
client: Client,
index: Index,
) -> Result<(), Error> {
setup_test_index(&client, &index).await?;
let search_query_1 = SearchQuery::new(&index)
.with_query("Sorcerer's Stone")
.with_show_performance_details(true)
.build();
let search_query_2 = SearchQuery::new(&index)
.with_query("Chamber of Secrets")
.build();

let response = client
.multi_search()
.with_search_query(search_query_1)
.with_search_query(search_query_2)
.execute::<Document>()
.await
.unwrap();

assert!(response.results[0].performance_details.is_some());
Ok(())
}

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

let response = client
.multi_search()
.with_federation(FederationOptions {
show_performance_details: Some(true),
..Default::default()
})
.execute::<Value>()
.await?;

assert!(response.performance_details.is_some());

Ok(())
}
}
33 changes: 33 additions & 0 deletions src/similar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct SimilarResults<T> {
pub limit: Option<usize>,
/// Estimated total number of matches
pub estimated_total_hits: Option<usize>,
/// Performance trace of the query
pub performance_details: Option<Value>,
/// Processing time of the query
pub processing_time_ms: usize,
/// Identifier of the target document
Expand Down Expand Up @@ -125,6 +127,12 @@ pub struct SimilarQuery<'a, Http: HttpClient> {
/// **Default: `false`**
#[serde(skip_serializing_if = "Option::is_none")]
pub retrieve_vectors: Option<bool>,

/// Defines whether to return performance trace
///
/// **Default: `false`**
#[serde(skip_serializing_if = "Option::is_none")]
pub show_performance_details: Option<bool>,
}

#[allow(missing_docs)]
Expand All @@ -143,6 +151,7 @@ impl<'a, Http: HttpClient> SimilarQuery<'a, Http> {
show_ranking_score_details: None,
ranking_score_threshold: None,
retrieve_vectors: None,
show_performance_details: None,
}
}

Expand Down Expand Up @@ -209,6 +218,15 @@ impl<'a, Http: HttpClient> SimilarQuery<'a, Http> {
self
}

/// Request performance trace in the response.
pub fn with_show_performance_details<'b>(
&'b mut self,
show_performance_details: bool,
) -> &'b mut SimilarQuery<'a, Http> {
self.show_performance_details = Some(show_performance_details);
self
}

/// Execute the query and fetch the results.
pub async fn execute<T: 'static + DeserializeOwned + Send + Sync>(
&'a self,
Expand Down Expand Up @@ -389,4 +407,19 @@ mod tests {
assert!(results.hits[0].result._vectors.is_some());
Ok(())
}

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

let mut query = SimilarQuery::new(&index, "1", "default");
query.with_show_performance_details(true);
let results: SimilarResults<Document> = query.execute().await?;
assert!(results.performance_details.is_some());
Ok(())
}
}
Loading