Skip to content

Add support for returning document vector data when get one document #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub struct DocumentQuery<'a, Http: HttpClient> {
/// The fields that should appear in the documents. By default, all of the fields are present.
#[serde(skip_serializing_if = "Option::is_none")]
pub fields: Option<Vec<&'a str>>,
#[serde(skip_serializing_if = "Option::is_none", rename = "retrieveVectors")]
pub retrieve_vectors: Option<bool>,
}

impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
Expand All @@ -90,6 +92,7 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
DocumentQuery {
index,
fields: None,
retrieve_vectors: None,
}
}

Expand Down Expand Up @@ -117,6 +120,30 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
self
}

/// Return document vector data with search result.
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, documents::*};
/// #
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let index = client.index("document_query_with_retrieve_vectors");
/// let mut document_query = DocumentQuery::new(&index);
///
/// document_query.with_retrieve_vectors(true);
/// ```
pub fn with_retrieve_vectors(
&mut self,
retrieve_vectors: bool,
) -> &mut DocumentQuery<'a, Http> {
self.retrieve_vectors = Some(retrieve_vectors);
self
}

/// Execute the get document query.
///
/// # Example
Expand All @@ -143,7 +170,9 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
/// # let index = client.index("document_query_execute");
/// # index.add_or_replace(&[MyObject{id:"1".to_string(), kind:String::from("a kind")},MyObject{id:"2".to_string(), kind:String::from("some kind")}], None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
///
/// let document = DocumentQuery::new(&index).with_fields(["id"])
/// let document = DocumentQuery::new(&index)
/// .with_fields(["id"]).
/// .with_retrieve_vectors(true)
/// .execute::<MyObjectReduced>("1")
/// .await
/// .unwrap();
Expand Down