diff --git a/crates/meilisearch/src/routes/indexes/mod.rs b/crates/meilisearch/src/routes/indexes/mod.rs index 7d073ec5f..b36dbbbff 100644 --- a/crates/meilisearch/src/routes/indexes/mod.rs +++ b/crates/meilisearch/src/routes/indexes/mod.rs @@ -29,6 +29,8 @@ pub mod documents; pub mod facet_search; pub mod search; mod search_analytics; +#[cfg(test)] +mod search_test; 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 2f5cb4a36..966361e76 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()) { @@ -356,30 +356,3 @@ 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(),]); - } -} 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..b56fb4e8b --- /dev/null +++ b/crates/meilisearch/src/routes/indexes/search_test.rs @@ -0,0 +1,22 @@ +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(),]); +}