From c0aa018c87d86923a08f67432e1d783a9b1dbd16 Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Sun, 8 Dec 2024 00:32:32 +0530 Subject: [PATCH 1/4] tests: split test in separate file Signed-off-by: Kushal Kumar --- crates/meilisearch/src/routes/indexes/mod.rs | 1 + .../meilisearch/src/routes/indexes/search.rs | 31 ++----------------- .../src/routes/indexes/search_test.rs | 26 ++++++++++++++++ 3 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 crates/meilisearch/src/routes/indexes/search_test.rs diff --git a/crates/meilisearch/src/routes/indexes/mod.rs b/crates/meilisearch/src/routes/indexes/mod.rs index 7d073ec5f..6879d17e7 100644 --- a/crates/meilisearch/src/routes/indexes/mod.rs +++ b/crates/meilisearch/src/routes/indexes/mod.rs @@ -28,6 +28,7 @@ use crate::Opt; pub mod documents; pub mod facet_search; pub mod search; +mod search_test; mod search_analytics; pub mod settings; mod settings_analytics; diff --git a/crates/meilisearch/src/routes/indexes/search.rs b/crates/meilisearch/src/routes/indexes/search.rs index 2f5cb4a36..6ada1d699 100644 --- a/crates/meilisearch/src/routes/indexes/search.rs +++ b/crates/meilisearch/src/routes/indexes/search.rs @@ -198,7 +198,7 @@ impl TryFrom for SearchQuery { // TODO: TAMO: split on :asc, and :desc, instead of doing some weird things /// Transform the sort query parameter into something that matches the post expected format. -fn fix_sort_query_parameters(sort_query: &str) -> Vec { +pub fn fix_sort_query_parameters(sort_query: &str) -> Vec { let mut sort_parameters = Vec::new(); let mut merge = false; for current_sort in sort_query.trim_matches('"').split(',').map(|s| s.trim()) { @@ -355,31 +355,4 @@ pub fn search_kind( (_, None, Some(_)) => Err(MeilisearchHttpError::MissingSearchHybrid.into()), } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_fix_sort_query_parameters() { - let sort = fix_sort_query_parameters("_geoPoint(12, 13):asc"); - assert_eq!(sort, vec!["_geoPoint(12,13):asc".to_string()]); - let sort = fix_sort_query_parameters("doggo:asc,_geoPoint(12.45,13.56):desc"); - assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(12.45,13.56):desc".to_string(),]); - let sort = fix_sort_query_parameters( - "doggo:asc , _geoPoint(12.45, 13.56, 2590352):desc , catto:desc", - ); - assert_eq!( - sort, - vec![ - "doggo:asc".to_string(), - "_geoPoint(12.45,13.56,2590352):desc".to_string(), - "catto:desc".to_string(), - ] - ); - let sort = fix_sort_query_parameters("doggo:asc , _geoPoint(1, 2), catto:desc"); - // This is ugly but eh, I don't want to write a full parser just for this unused route - assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(1,2),catto:desc".to_string(),]); - } -} +} \ No newline at end of file diff --git a/crates/meilisearch/src/routes/indexes/search_test.rs b/crates/meilisearch/src/routes/indexes/search_test.rs new file mode 100644 index 000000000..8b1605eb1 --- /dev/null +++ b/crates/meilisearch/src/routes/indexes/search_test.rs @@ -0,0 +1,26 @@ +#[cfg(test)] +pub mod search_test { + use crate::routes::indexes::search::fix_sort_query_parameters; + + #[test] + fn test_fix_sort_query_parameters() { + let sort = fix_sort_query_parameters("_geoPoint(12, 13):asc"); + assert_eq!(sort, vec!["_geoPoint(12,13):asc".to_string()]); + let sort = fix_sort_query_parameters("doggo:asc,_geoPoint(12.45,13.56):desc"); + assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(12.45,13.56):desc".to_string(),]); + let sort = fix_sort_query_parameters( + "doggo:asc , _geoPoint(12.45, 13.56, 2590352):desc , catto:desc", + ); + assert_eq!( + sort, + vec![ + "doggo:asc".to_string(), + "_geoPoint(12.45,13.56,2590352):desc".to_string(), + "catto:desc".to_string(), + ] + ); + let sort = fix_sort_query_parameters("doggo:asc , _geoPoint(1, 2), catto:desc"); + // This is ugly but eh, I don't want to write a full parser just for this unused route + assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(1,2),catto:desc".to_string(),]); + } +} From 34254b42b63692503f2fafd8a03ebf0d12ce8afd Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Tue, 10 Dec 2024 00:00:43 +0530 Subject: [PATCH 2/4] refactor: use test configuration on import Signed-off-by: Kushal Kumar --- crates/meilisearch/src/routes/indexes/mod.rs | 1 + crates/meilisearch/src/routes/indexes/search_test.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/meilisearch/src/routes/indexes/mod.rs b/crates/meilisearch/src/routes/indexes/mod.rs index 6879d17e7..c23edfc12 100644 --- a/crates/meilisearch/src/routes/indexes/mod.rs +++ b/crates/meilisearch/src/routes/indexes/mod.rs @@ -28,6 +28,7 @@ use crate::Opt; pub mod documents; pub mod facet_search; pub mod search; +#[cfg(test)] mod search_test; mod search_analytics; pub mod settings; diff --git a/crates/meilisearch/src/routes/indexes/search_test.rs b/crates/meilisearch/src/routes/indexes/search_test.rs index 8b1605eb1..fb9ef6154 100644 --- a/crates/meilisearch/src/routes/indexes/search_test.rs +++ b/crates/meilisearch/src/routes/indexes/search_test.rs @@ -1,4 +1,3 @@ -#[cfg(test)] pub mod search_test { use crate::routes::indexes::search::fix_sort_query_parameters; From 0c04cd1d9f94c907f1f7366548b3fafb2318d80f Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 16 Dec 2024 15:52:47 +0100 Subject: [PATCH 3/4] make clippy happy --- .../meilisearch/src/routes/indexes/search.rs | 3 +- .../src/routes/indexes/search_test.rs | 43 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/crates/meilisearch/src/routes/indexes/search.rs b/crates/meilisearch/src/routes/indexes/search.rs index 6ada1d699..bbf91ba1f 100644 --- a/crates/meilisearch/src/routes/indexes/search.rs +++ b/crates/meilisearch/src/routes/indexes/search.rs @@ -355,4 +355,5 @@ pub fn search_kind( (_, None, Some(_)) => Err(MeilisearchHttpError::MissingSearchHybrid.into()), } -} \ No newline at end of file +} + diff --git a/crates/meilisearch/src/routes/indexes/search_test.rs b/crates/meilisearch/src/routes/indexes/search_test.rs index fb9ef6154..b56fb4e8b 100644 --- a/crates/meilisearch/src/routes/indexes/search_test.rs +++ b/crates/meilisearch/src/routes/indexes/search_test.rs @@ -1,25 +1,22 @@ -pub mod search_test { - use crate::routes::indexes::search::fix_sort_query_parameters; +use crate::routes::indexes::search::fix_sort_query_parameters; - #[test] - fn test_fix_sort_query_parameters() { - let sort = fix_sort_query_parameters("_geoPoint(12, 13):asc"); - assert_eq!(sort, vec!["_geoPoint(12,13):asc".to_string()]); - let sort = fix_sort_query_parameters("doggo:asc,_geoPoint(12.45,13.56):desc"); - assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(12.45,13.56):desc".to_string(),]); - let sort = fix_sort_query_parameters( - "doggo:asc , _geoPoint(12.45, 13.56, 2590352):desc , catto:desc", - ); - assert_eq!( - sort, - vec![ - "doggo:asc".to_string(), - "_geoPoint(12.45,13.56,2590352):desc".to_string(), - "catto:desc".to_string(), - ] - ); - let sort = fix_sort_query_parameters("doggo:asc , _geoPoint(1, 2), catto:desc"); - // This is ugly but eh, I don't want to write a full parser just for this unused route - assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(1,2),catto:desc".to_string(),]); - } +#[test] +fn test_fix_sort_query_parameters() { + let sort = fix_sort_query_parameters("_geoPoint(12, 13):asc"); + assert_eq!(sort, vec!["_geoPoint(12,13):asc".to_string()]); + let sort = fix_sort_query_parameters("doggo:asc,_geoPoint(12.45,13.56):desc"); + assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(12.45,13.56):desc".to_string(),]); + let sort = + fix_sort_query_parameters("doggo:asc , _geoPoint(12.45, 13.56, 2590352):desc , catto:desc"); + assert_eq!( + sort, + vec![ + "doggo:asc".to_string(), + "_geoPoint(12.45,13.56,2590352):desc".to_string(), + "catto:desc".to_string(), + ] + ); + let sort = fix_sort_query_parameters("doggo:asc , _geoPoint(1, 2), catto:desc"); + // This is ugly but eh, I don't want to write a full parser just for this unused route + assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(1,2),catto:desc".to_string(),]); } From b004db37c78d834c810ea3ede2e1c6666a930b4b Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 16 Dec 2024 15:59:26 +0100 Subject: [PATCH 4/4] fmt --- crates/meilisearch/src/routes/indexes/mod.rs | 2 +- crates/meilisearch/src/routes/indexes/search.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/meilisearch/src/routes/indexes/mod.rs b/crates/meilisearch/src/routes/indexes/mod.rs index c23edfc12..b36dbbbff 100644 --- a/crates/meilisearch/src/routes/indexes/mod.rs +++ b/crates/meilisearch/src/routes/indexes/mod.rs @@ -28,9 +28,9 @@ use crate::Opt; pub mod documents; pub mod facet_search; pub mod search; +mod search_analytics; #[cfg(test)] mod search_test; -mod search_analytics; pub mod settings; mod settings_analytics; pub mod similar; diff --git a/crates/meilisearch/src/routes/indexes/search.rs b/crates/meilisearch/src/routes/indexes/search.rs index bbf91ba1f..966361e76 100644 --- a/crates/meilisearch/src/routes/indexes/search.rs +++ b/crates/meilisearch/src/routes/indexes/search.rs @@ -356,4 +356,3 @@ pub fn search_kind( (_, None, Some(_)) => Err(MeilisearchHttpError::MissingSearchHybrid.into()), } } -