From 69aee870da40bbcec3bfd6041dbaf868d85745c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 31 Mar 2020 10:39:58 +0200 Subject: [PATCH] Make the engine index booleans The engine will see the values like text "true" and "false" --- .../src/serde/convert_to_string.rs | 6 +-- meilisearch-http/tests/documents_add.rs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/meilisearch-core/src/serde/convert_to_string.rs b/meilisearch-core/src/serde/convert_to_string.rs index 718bd1bf2..bac0de99e 100644 --- a/meilisearch-core/src/serde/convert_to_string.rs +++ b/meilisearch-core/src/serde/convert_to_string.rs @@ -16,10 +16,8 @@ impl ser::Serializer for ConvertToString { type SerializeStruct = StructConvertToString; type SerializeStructVariant = ser::Impossible; - fn serialize_bool(self, _value: bool) -> Result { - Err(SerializerError::UnserializableType { - type_name: "boolean", - }) + fn serialize_bool(self, value: bool) -> Result { + Ok(value.to_string()) } fn serialize_char(self, value: char) -> Result { diff --git a/meilisearch-http/tests/documents_add.rs b/meilisearch-http/tests/documents_add.rs index 7ba726810..ca87a8027 100644 --- a/meilisearch-http/tests/documents_add.rs +++ b/meilisearch-http/tests/documents_add.rs @@ -36,3 +36,43 @@ fn check_add_documents_with_primary_key_param() { assert_eq!(status_code, 200); assert_eq!(response["status"], "processed"); } + +// Test issue https://github.com/meilisearch/MeiliSearch/issues/568 +#[test] +fn check_add_documents_with_nested_boolean() { + let mut server = common::Server::with_uid("tasks"); + + // 1 - Create the index with no primary_key + + let body = json!({ "uid": "tasks" }); + let (response, status_code) = server.create_index(body); + assert_eq!(status_code, 201); + assert_eq!(response["primaryKey"], json!(null)); + + // 2 - Add a document that contains a boolean in a nested object + + let body = json!([{ + "id": 12161, + "created_at": "2019-04-10T14:57:57.522Z", + "foo": { + "bar": { + "id": 121, + "crash": false + }, + "id": 45912 + } + }]); + + let url = "/indexes/tasks/documents"; + let (response, status_code) = server.post_request(&url, body); + eprintln!("{:#?}", response); + assert_eq!(status_code, 202); + let update_id = response["updateId"].as_u64().unwrap(); + server.wait_update_id(update_id); + + // 3 - Check update sucess + + let (response, status_code) = server.get_update_status(update_id); + assert_eq!(status_code, 200); + assert_eq!(response["status"], "processed"); +}