diff --git a/meilisearch-http/tests/index.rs b/meilisearch-http/tests/index.rs index 3215cc4b0..b637134a7 100644 --- a/meilisearch-http/tests/index.rs +++ b/meilisearch-http/tests/index.rs @@ -1,4 +1,5 @@ use serde_json::json; +use assert_json_diff::assert_json_eq; mod common; @@ -467,3 +468,33 @@ fn create_index_failed() { assert_eq!(res_value.as_object().unwrap().len(), 1); assert_eq!(message, "invalid data"); } + + +#[test] +fn create_index_with_identifier() { + let mut server = common::Server::with_uid("movies"); + + let body = json!({ + "uid": "movies", + "identifier": "id", + }); + + let (_response, status_code) = server.create_index(body); + assert_eq!(status_code, 201); + + let body = json!([{ + "id": 123, + "text": "The mask" + }]); + + server.add_or_replace_multiple_documents(body.clone()); + + let (response, _status_code) = server.get_document(123); + + let expect = json!({ + "id": 123, + "text": "The mask" + }); + + assert_json_eq!(response, expect, ordered: false); +} diff --git a/meilisearch-schema/src/schema.rs b/meilisearch-schema/src/schema.rs index 4283f203d..2f9eee4f5 100644 --- a/meilisearch-schema/src/schema.rs +++ b/meilisearch-schema/src/schema.rs @@ -21,13 +21,21 @@ impl Schema { let mut fields_map = FieldsMap::default(); let field_id = fields_map.insert(name).unwrap(); + let mut displayed = HashSet::new(); + let mut indexed = Vec::new(); + let mut indexed_map = HashMap::new(); + + displayed.insert(field_id); + indexed.push(field_id); + indexed_map.insert(field_id, 0.into()); + Schema { fields_map, identifier: field_id, ranked: HashSet::new(), - displayed: HashSet::new(), - indexed: Vec::new(), - indexed_map: HashMap::new(), + displayed, + indexed, + indexed_map, accept_new_fields: true, } }