Skip to content
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

Update get one document for v0.28.0 #323

Merged
merged 79 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a37ffd3
Update task api v0.28.0
bidoubiwa Jul 7, 2022
b9ffd60
Update tests to be relevant with the structures where they are ran
bidoubiwa Jul 11, 2022
c527312
Update types in code-samples
bidoubiwa Jul 11, 2022
17d6c19
Remove clearAll task type
bidoubiwa Jul 11, 2022
ff0d350
Add index_uid as an optional in the Tasks
bidoubiwa Jul 11, 2022
9241a7b
Add comments on best builder implementation
bidoubiwa Jul 19, 2022
eb38d18
Add execute function on get_tasks
bidoubiwa Aug 2, 2022
d37be56
Update code samples
bidoubiwa Aug 3, 2022
61be5a5
Remove out of context comment
bidoubiwa Aug 3, 2022
7aa409b
Merge
bidoubiwa Aug 3, 2022
c968df3
Fix tests
bidoubiwa Aug 3, 2022
c21b18f
Fix pagination tests
bidoubiwa Aug 3, 2022
012f939
Update HTTP methods for v0.28.0
bidoubiwa Aug 3, 2022
0cb9e93
Fix clippy
bidoubiwa Aug 3, 2022
a485ba5
Merge branch 'update_task_api_for_v0.28.0' of github.com:meilisearch/…
bidoubiwa Aug 3, 2022
f86bff4
Remove comment of task tests since the tests are now sucesful
bidoubiwa Aug 3, 2022
734fd13
Fix doc tests
bidoubiwa Aug 3, 2022
e5821c4
Merge branch 'update_task_api_for_v0.28.0' of github.com:meilisearch/…
bidoubiwa Aug 3, 2022
11bfb7e
Update keys for v0.28.0
bidoubiwa Aug 4, 2022
6b70f5a
Fix get tasks inside index structure
bidoubiwa Aug 4, 2022
604e08d
Make description and name optional in keys
bidoubiwa Aug 8, 2022
67637c2
Fix none doc tests with new get_tasks api
bidoubiwa Aug 8, 2022
c2dcd92
Add from and limit in tasks params
bidoubiwa Aug 8, 2022
efff813
Add warning on failing test
bidoubiwa Aug 8, 2022
f0020b6
Merge branch 'update_task_api_for_v0.28.0' of https://github.com/meil…
bidoubiwa Aug 8, 2022
e0762b1
Merge
bidoubiwa Aug 8, 2022
c1796a3
Update keys design
bidoubiwa Aug 9, 2022
abc0f7b
Update task API
bidoubiwa Aug 9, 2022
eaef1ea
Remove useless comment
bidoubiwa Aug 9, 2022
bdf4f13
Merge branch 'update_task_api_for_v0.28.0' of https://github.com/meil…
bidoubiwa Aug 9, 2022
2441da1
Merge branch 'update_http_methods_for_v0.28.0' of https://github.com/…
bidoubiwa Aug 9, 2022
d506eae
Remove client as mandatory parameter for the keyUpdater
bidoubiwa Aug 10, 2022
c803fd5
Add doc and tests on doc
bidoubiwa Aug 10, 2022
cdc2a41
Fix docs tests on keys in client
bidoubiwa Aug 10, 2022
b2ba741
Fix docs tests
bidoubiwa Aug 10, 2022
24ff749
Remove dbg
bidoubiwa Aug 10, 2022
1b41330
Add with_uid filter
bidoubiwa Aug 10, 2022
f6f821d
Add new actions on key creation
bidoubiwa Aug 10, 2022
710b2d6
Remove new line at the start of docs
bidoubiwa Aug 10, 2022
54d29eb
Fix clippy errors
bidoubiwa Aug 10, 2022
2439778
Merge branch 'update_keys_for_v0.28.0' of https://github.com/meilisea…
bidoubiwa Aug 10, 2022
3989758
Rename type in Task structure
bidoubiwa Aug 10, 2022
668ba13
Removed useless newlines
bidoubiwa Aug 10, 2022
ac95329
Fix typo in comment
bidoubiwa Aug 10, 2022
66bd1a5
Add missing semi-column
bidoubiwa Aug 10, 2022
3adc25e
t checkout uMerge branch 'update_task_api_for_v0.28.0' of https://git…
bidoubiwa Aug 10, 2022
17f1ecf
Merge
bidoubiwa Aug 10, 2022
31b3941
Update indexes api for v0.28.0
bidoubiwa Aug 10, 2022
7865c1f
Merge
bidoubiwa Aug 22, 2022
027181b
Improve doc comments
bidoubiwa Aug 22, 2022
761a9df
Merge branch 'update_keys_for_v0.28.0' of github.com:meilisearch/meil…
bidoubiwa Aug 22, 2022
9b36f77
Change indexes methods
bidoubiwa Aug 23, 2022
335fbf1
Add index query and index updater
bidoubiwa Aug 23, 2022
7b5b5e2
Add documentation and doc tests on indexes routes
bidoubiwa Aug 24, 2022
3012f2a
Add tests on get indexes with params
bidoubiwa Aug 24, 2022
62e5f2c
Add test on index update
bidoubiwa Aug 24, 2022
555f7dd
Fix clippy
bidoubiwa Aug 24, 2022
e253823
update nb hits to estimated_nb_hits
bidoubiwa Aug 24, 2022
7c8d8a0
remove exhaustive facets count
bidoubiwa Aug 24, 2022
3d1682d
Change matches to show_matches_position
bidoubiwa Aug 24, 2022
de69f44
Change matches_info to matches_position
bidoubiwa Aug 24, 2022
f7d9862
Update search api for v0.28.1
bidoubiwa Aug 24, 2022
c6c2833
Improve comment syntax
bidoubiwa Aug 24, 2022
49ec3c5
Hide client creation in search query builder doc test
bidoubiwa Aug 24, 2022
c3f3939
Add DocumentsQuery and DocumentsResults
bidoubiwa Aug 24, 2022
33629b9
Resolve merge conflicts
bidoubiwa Aug 25, 2022
2062dce
Rollback wrong merging
bidoubiwa Aug 25, 2022
25fb8b5
Merge branch 'update_search_for_v0.28.0' of github.com:meilisearch/me…
bidoubiwa Aug 25, 2022
8c1bcba
Fix failing key tests
bidoubiwa Aug 25, 2022
405e0f4
Merge branch 'update_search_for_v0.28.0' of github.com:meilisearch/me…
bidoubiwa Aug 25, 2022
1499f7e
Merge branch 'bump-meilisearch-v0.28.0' of github.com:meilisearch/mei…
bidoubiwa Aug 25, 2022
4754825
Add documentation
bidoubiwa Aug 25, 2022
a262309
Fix execute doc test
bidoubiwa Aug 25, 2022
be22268
Fix clippy tests
bidoubiwa Aug 25, 2022
9f7f0e9
Fix comments
bidoubiwa Aug 29, 2022
248994e
Update get one document for v0.28.0
bidoubiwa Aug 29, 2022
4b8f887
Use struct instead of query creation on get_document parameters
bidoubiwa Aug 29, 2022
18aa8b4
Show partialEq on Movie struct
bidoubiwa Aug 29, 2022
331f8b1
Fix merge conflicts
bidoubiwa Aug 29, 2022
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
7 changes: 7 additions & 0 deletions src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ pub struct DocumentsResults<T> {
pub total: u32,
}

#[derive(Debug, Clone, Serialize)]
pub struct DocumentQuery<'a> {
/// 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>>,
}

#[derive(Debug, Clone, Serialize)]
pub struct DocumentsQuery<'a> {
#[serde(skip_serializing)]
Expand Down
44 changes: 26 additions & 18 deletions src/indexes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
client::Client,
documents::{DocumentsQuery, DocumentsResults},
documents::{DocumentQuery, DocumentsQuery, DocumentsResults},
errors::Error,
request::*,
search::*,
Expand Down Expand Up @@ -285,40 +285,48 @@ impl Index {
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// #[derive(Serialize, Deserialize, Debug)]
/// # #[derive(PartialEq)]
/// #[derive(Serialize, Debug)]
/// struct Movie {
/// name: String,
/// description: String,
/// age: Option<usize>
/// }
///
/// #[derive(Deserialize, Debug, PartialEq)]
/// struct ReturnedMovie {
/// name: String,
/// description: String
/// }
///
///
/// # futures::executor::block_on(async move {
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
/// let movies = client.index("get_document");
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage."), age: Some(1)}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
///
/// // retrieve a document (you have to put the document in the index before)
/// let interstellar = movies.get_document::<Movie>("Interstellar").await.unwrap();
/// let interstellar = movies.get_document::<ReturnedMovie>("Interstellar", Some(["name", "description"].to_vec())).await.unwrap();
///
/// assert_eq!(interstellar, Movie {
/// assert_eq!(interstellar, ReturnedMovie {
/// name: String::from("Interstellar"),
/// description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
/// description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage."),
/// });
/// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn get_document<T: 'static + DeserializeOwned>(&self, uid: &str) -> Result<T, Error> {
request::<(), T>(
&format!(
"{}/indexes/{}/documents/{}",
self.client.host, self.uid, uid
),
&self.client.api_key,
Method::Get(()),
200,
)
.await
pub async fn get_document<T: 'static + DeserializeOwned>(
&self,
document_id: &str,
fields: Option<Vec<&str>>,
) -> Result<T, Error> {
let url = format!(
"{}/indexes/{}/documents/{}",
self.client.host, self.uid, document_id
);

let query = DocumentQuery { fields };

request::<&DocumentQuery, T>(&url, &self.client.api_key, Method::Get(&query), 200).await
}

/// Get [Document]s by batch.
Expand Down