From 56db54486cfb14d4e1e13229b60353e03b5ea635 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 19 Jan 2023 13:37:34 +0100 Subject: [PATCH 1/3] Add tests --- meilisearch/tests/search/errors.rs | 94 +++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 42f248452..f50edd13f 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -333,7 +333,7 @@ async fn search_non_filterable_facets() { snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { - "message": "Invalid facet distribution, the fields `doggo` are not set as filterable.", + "message": "Invalid facet distribution, attribute `doggo` is not filterable. The available filterable attribute is `title`.", "code": "invalid_search_facets", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_search_facets" @@ -344,7 +344,97 @@ async fn search_non_filterable_facets() { snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { - "message": "Invalid facet distribution, the fields `doggo` are not set as filterable.", + "message": "Invalid facet distribution, attribute `doggo` is not filterable. The available filterable attribute is `title`.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_facets" + } + "###); +} + +#[actix_rt::test] +async fn search_non_filterable_facets_multiple_filterable() { + let server = Server::new().await; + let index = server.index("test"); + index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; + index.wait_task(0).await; + + let (response, code) = index.search_post(json!({"facets": ["doggo"]})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, attribute `doggo` is not filterable. The available filterable attributes are `genres, title`.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_facets" + } + "###); + + let (response, code) = index.search_get("facets=doggo").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, attribute `doggo` is not filterable. The available filterable attributes are `genres, title`.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_facets" + } + "###); +} + +#[actix_rt::test] +async fn search_non_filterable_facets_no_filterable() { + let server = Server::new().await; + let index = server.index("test"); + index.update_settings(json!({"filterableAttributes": []})).await; + index.wait_task(0).await; + + let (response, code) = index.search_post(json!({"facets": ["doggo"]})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, this index does not have configured filterable attributes.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_facets" + } + "###); + + let (response, code) = index.search_get("facets=doggo").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, this index does not have configured filterable attributes.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_facets" + } + "###); +} + +#[actix_rt::test] +async fn search_non_filterable_facets_multiple_facets() { + let server = Server::new().await; + let index = server.index("test"); + index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; + index.wait_task(0).await; + + let (response, code) = index.search_post(json!({"facets": ["doggo", "neko"]})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, attributes `doggo, neko` are not filterable. The available filterable attributes are `genres, title`.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_facets" + } + "###); + + let (response, code) = index.search_get("facets=doggo,neko").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, attributes `doggo, neko` are not filterable. The available filterable attributes are `genres, title`.", "code": "invalid_search_facets", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_search_facets" From f0e6b9c0c5d0e3a6a3d987ae7cd706ae0482c7e4 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Thu, 19 Jan 2023 17:29:54 +0100 Subject: [PATCH 2/3] Update deserr to 0.3.0 --- meilisearch-types/Cargo.toml | 2 +- meilisearch/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 8d7f673d9..b71e7e46c 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -9,7 +9,7 @@ actix-web = { version = "4.2.1", default-features = false } anyhow = "1.0.65" convert_case = "0.6.0" csv = "1.1.6" -deserr = "0.1.5" +deserr = "0.3.0" either = { version = "1.6.1", features = ["serde"] } enum-iterator = "1.1.3" file-store = { path = "../file-store" } diff --git a/meilisearch/Cargo.toml b/meilisearch/Cargo.toml index 9a0c9bd0b..b0592f9d1 100644 --- a/meilisearch/Cargo.toml +++ b/meilisearch/Cargo.toml @@ -19,7 +19,7 @@ byte-unit = { version = "4.0.14", default-features = false, features = ["std", " bytes = "1.2.1" clap = { version = "4.0.9", features = ["derive", "env"] } crossbeam-channel = "0.5.6" -deserr = "0.1.5" +deserr = "0.3.0" dump = { path = "../dump" } either = "1.8.0" env_logger = "0.9.1" From c79b6a1ee419d5d2bc7427907c32895753b452c1 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 19 Jan 2023 20:54:42 +0100 Subject: [PATCH 3/3] bump milli --- Cargo.lock | 24 ++++++++++++------------ meilisearch-types/Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c41a3406..a55e6dc49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1009,9 +1009,9 @@ dependencies = [ [[package]] name = "deserr" -version = "0.1.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3c6417f0bf7561774690e3d47f9659b0cbc3614c7af7bfda404fda7a2c11d3" +checksum = "28380303ca15ec07e1d5b079baf19cf849b09edad5cab219c1c51b2bd07523de" dependencies = [ "deserr-internal", "serde-cs", @@ -1020,9 +1020,9 @@ dependencies = [ [[package]] name = "deserr-internal" -version = "0.1.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196415cbd3b782cddecbdd69da18cd9b19e1bb0bdbb649e87b5afd83fa8d322b" +checksum = "860928cd8af78d223a3d70dd581f21d7c3de8aa2eecd938e0c0a399ded7c1451" dependencies = [ "convert_case 0.5.0", "proc-macro2", @@ -1300,8 +1300,8 @@ dependencies = [ [[package]] name = "filter-parser" -version = "0.39.1" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.1#0c7d1f761e5db6d086f27d3f0f47a97c7f4a5f08" +version = "0.40.0" +source = "git+https://github.com/meilisearch/milli.git?tag=v0.40.0#1c4b1b3b2dcd1b84da603a381c898da879c4adb5" dependencies = [ "nom", "nom_locate", @@ -1319,8 +1319,8 @@ dependencies = [ [[package]] name = "flatten-serde-json" -version = "0.39.1" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.1#0c7d1f761e5db6d086f27d3f0f47a97c7f4a5f08" +version = "0.40.0" +source = "git+https://github.com/meilisearch/milli.git?tag=v0.40.0#1c4b1b3b2dcd1b84da603a381c898da879c4adb5" dependencies = [ "serde_json", ] @@ -1884,8 +1884,8 @@ dependencies = [ [[package]] name = "json-depth-checker" -version = "0.39.1" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.1#0c7d1f761e5db6d086f27d3f0f47a97c7f4a5f08" +version = "0.40.0" +source = "git+https://github.com/meilisearch/milli.git?tag=v0.40.0#1c4b1b3b2dcd1b84da603a381c898da879c4adb5" dependencies = [ "serde_json", ] @@ -2431,8 +2431,8 @@ dependencies = [ [[package]] name = "milli" -version = "0.39.1" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.1#0c7d1f761e5db6d086f27d3f0f47a97c7f4a5f08" +version = "0.40.0" +source = "git+https://github.com/meilisearch/milli.git?tag=v0.40.0#1c4b1b3b2dcd1b84da603a381c898da879c4adb5" dependencies = [ "bimap", "bincode", diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index b71e7e46c..3bc43bee3 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -16,7 +16,7 @@ file-store = { path = "../file-store" } flate2 = "1.0.24" fst = "0.4.7" memmap2 = "0.5.7" -milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.39.1", default-features = false } +milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.40.0", default-features = false } roaring = { version = "0.10.0", features = ["serde"] } serde = { version = "1.0.145", features = ["derive"] } serde-cs = "0.2.4"