From 277a0a79677432c7b91a31d3126b15e3b70b37ec Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 6 Jun 2022 10:17:33 +0200 Subject: [PATCH] Bump serde-cs to simplify our usage of the star_or function --- Cargo.lock | 4 +-- meilisearch-http/Cargo.toml | 2 +- .../src/routes/indexes/documents.rs | 4 +-- meilisearch-http/src/routes/indexes/search.rs | 29 ++++--------------- meilisearch-http/src/routes/tasks.rs | 6 ++-- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 317ae620a..a1be24517 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3078,9 +3078,9 @@ dependencies = [ [[package]] name = "serde-cs" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d5b0435c9139761fbe5abeb1283234bcfbde88fadc2ae432579648fbce72ad" +checksum = "8202c9f3f58762d274952790ff8a1f1f625b5664f75e5dc1952c8dcacc64a925" dependencies = [ "serde", ] diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index b9771afa2..ac4fed7b1 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -62,7 +62,7 @@ rustls = "0.20.4" rustls-pemfile = "0.3.0" segment = { version = "0.2.0", optional = true } serde = { version = "1.0.136", features = ["derive"] } -serde-cs = "0.2.2" +serde-cs = "0.2.3" serde_json = { version = "1.0.79", features = ["preserve_order"] } sha2 = "0.10.2" siphasher = "0.3.10" diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index f506e587c..b5f578a56 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -99,7 +99,7 @@ pub async fn get_document( let index = path.index_uid.clone(); let id = path.document_id.clone(); let GetDocument { fields } = params.into_inner(); - let attributes_to_retrieve = fields.map(CS::into_inner).and_then(fold_star_or); + let attributes_to_retrieve = fields.and_then(fold_star_or); let document = meilisearch .document(index, id, attributes_to_retrieve) @@ -143,7 +143,7 @@ pub async fn get_all_documents( offset, fields, } = params.into_inner(); - let attributes_to_retrieve = fields.map(CS::into_inner).and_then(fold_star_or); + let attributes_to_retrieve = fields.and_then(fold_star_or); let (total, documents) = meilisearch .documents(path.into_inner(), offset, limit, attributes_to_retrieve) diff --git a/meilisearch-http/src/routes/indexes/search.rs b/meilisearch-http/src/routes/indexes/search.rs index 2f3f4a83b..4eaa65b9d 100644 --- a/meilisearch-http/src/routes/indexes/search.rs +++ b/meilisearch-http/src/routes/indexes/search.rs @@ -50,23 +50,6 @@ pub struct SearchQueryGet { impl From for SearchQuery { fn from(other: SearchQueryGet) -> Self { - let attributes_to_retrieve = other - .attributes_to_retrieve - .map(CS::into_inner) - .and_then(fold_star_or); - - let attributes_to_crop = other - .attributes_to_crop - .map(CS::into_inner) - .and_then(fold_star_or); - - let attributes_to_highlight = other - .attributes_to_highlight - .map(CS::into_inner) - .and_then(fold_star_or); - - let facets = other.facets.map(CS::into_inner).and_then(fold_star_or); - let filter = match other.filter { Some(f) => match serde_json::from_str(&f) { Ok(v) => Some(v), @@ -75,20 +58,18 @@ impl From for SearchQuery { None => None, }; - let sort = other.sort.map(|attr| fix_sort_query_parameters(&attr)); - Self { q: other.q, offset: other.offset, limit: other.limit.unwrap_or_else(DEFAULT_SEARCH_LIMIT), - attributes_to_retrieve, - attributes_to_crop, + attributes_to_retrieve: other.attributes_to_retrieve.and_then(fold_star_or), + attributes_to_crop: other.attributes_to_crop.and_then(fold_star_or), crop_length: other.crop_length, - attributes_to_highlight, + attributes_to_highlight: other.attributes_to_highlight.and_then(fold_star_or), filter, - sort, + sort: other.sort.map(|attr| fix_sort_query_parameters(&attr)), show_matches_position: other.show_matches_position, - facets, + facets: other.facets.and_then(fold_star_or), highlight_pre_tag: other.highlight_pre_tag, highlight_post_tag: other.highlight_post_tag, crop_marker: other.crop_marker, diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index b13c04dc7..14716ff6b 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -81,9 +81,9 @@ async fn get_tasks( // We first transform a potential indexUid=* into a "not specified indexUid filter" // for every one of the filters: type, status, and indexUid. - let type_: Option> = type_.map(CS::into_inner).and_then(fold_star_or); - let status: Option> = status.map(CS::into_inner).and_then(fold_star_or); - let index_uid: Option> = index_uid.map(CS::into_inner).and_then(fold_star_or); + let type_: Option> = type_.and_then(fold_star_or); + let status: Option> = status.and_then(fold_star_or); + let index_uid: Option> = index_uid.and_then(fold_star_or); // Then we filter on potential indexes and make sure that the search filter // restrictions are also applied.