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(),]); + } +}