mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
commit
dcb93e3166
@ -3,4 +3,4 @@
|
||||
- Add the number of hits in search result (#541)
|
||||
- Add support for aligned crop in search result (#543)
|
||||
- Sanitize the content displayed in the web interface (#539)
|
||||
- Add support of nested null and boolean values (#571 and #568)
|
||||
- Add support of nested null, boolean and seq values (#571 and #568, #574)
|
||||
|
@ -8,7 +8,7 @@ pub struct ConvertToString;
|
||||
impl ser::Serializer for ConvertToString {
|
||||
type Ok = String;
|
||||
type Error = SerializerError;
|
||||
type SerializeSeq = ser::Impossible<Self::Ok, Self::Error>;
|
||||
type SerializeSeq = SeqConvertToString;
|
||||
type SerializeTuple = ser::Impossible<Self::Ok, Self::Error>;
|
||||
type SerializeTupleStruct = ser::Impossible<Self::Ok, Self::Error>;
|
||||
type SerializeTupleVariant = ser::Impossible<Self::Ok, Self::Error>;
|
||||
@ -135,8 +135,8 @@ impl ser::Serializer for ConvertToString {
|
||||
}
|
||||
|
||||
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
||||
Err(SerializerError::UnserializableType {
|
||||
type_name: "sequence",
|
||||
Ok(SeqConvertToString {
|
||||
text: String::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -254,3 +254,26 @@ impl ser::SerializeStruct for StructConvertToString {
|
||||
Ok(self.text)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SeqConvertToString {
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl ser::SerializeSeq for SeqConvertToString {
|
||||
type Ok = String;
|
||||
type Error = SerializerError;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ser::Serialize,
|
||||
{
|
||||
let text = key.serialize(ConvertToString)?;
|
||||
self.text.push_str(&text);
|
||||
self.text.push_str(" ");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
Ok(self.text)
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ fn check_add_documents_with_primary_key_param() {
|
||||
let update_id = response["updateId"].as_u64().unwrap();
|
||||
server.wait_update_id(update_id);
|
||||
|
||||
// 3 - Check update sucess
|
||||
// 3 - Check update success
|
||||
|
||||
let (response, status_code) = server.get_update_status(update_id);
|
||||
assert_eq!(status_code, 200);
|
||||
@ -70,7 +70,7 @@ fn check_add_documents_with_nested_boolean() {
|
||||
let update_id = response["updateId"].as_u64().unwrap();
|
||||
server.wait_update_id(update_id);
|
||||
|
||||
// 3 - Check update sucess
|
||||
// 3 - Check update success
|
||||
|
||||
let (response, status_code) = server.get_update_status(update_id);
|
||||
assert_eq!(status_code, 200);
|
||||
@ -105,9 +105,73 @@ fn check_add_documents_with_nested_null() {
|
||||
let update_id = response["updateId"].as_u64().unwrap();
|
||||
server.wait_update_id(update_id);
|
||||
|
||||
// 3 - Check update sucess
|
||||
// 3 - Check update success
|
||||
|
||||
let (response, status_code) = server.get_update_status(update_id);
|
||||
assert_eq!(status_code, 200);
|
||||
assert_eq!(response["status"], "processed");
|
||||
}
|
||||
|
||||
// Test issue https://github.com/meilisearch/MeiliSearch/issues/574
|
||||
#[test]
|
||||
fn check_add_documents_with_nested_sequence() {
|
||||
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 seq in a nested object
|
||||
|
||||
let body = json!([{
|
||||
"id": 0,
|
||||
"foo": {
|
||||
"bar": [123,456],
|
||||
"fez": [{
|
||||
"id": 255,
|
||||
"baz": "leesz",
|
||||
"fuzz": {
|
||||
"fax": [234]
|
||||
},
|
||||
"sas": []
|
||||
}],
|
||||
"foz": [{
|
||||
"id": 255,
|
||||
"baz": "leesz",
|
||||
"fuzz": {
|
||||
"fax": [234]
|
||||
},
|
||||
"sas": []
|
||||
},
|
||||
{
|
||||
"id": 256,
|
||||
"baz": "loss",
|
||||
"fuzz": {
|
||||
"fax": [235]
|
||||
},
|
||||
"sas": [321, 321]
|
||||
}]
|
||||
}
|
||||
}]);
|
||||
|
||||
let url = "/indexes/tasks/documents";
|
||||
let (response, status_code) = server.post_request(&url, body.clone());
|
||||
eprintln!("{:#?}", response);
|
||||
assert_eq!(status_code, 202);
|
||||
let update_id = response["updateId"].as_u64().unwrap();
|
||||
server.wait_update_id(update_id);
|
||||
|
||||
// 3 - Check update success
|
||||
|
||||
let (response, status_code) = server.get_update_status(update_id);
|
||||
assert_eq!(status_code, 200);
|
||||
assert_eq!(response["status"], "processed");
|
||||
|
||||
let url = "/indexes/tasks/search?q=leesz";
|
||||
let (response, status_code) = server.get_request(&url);
|
||||
assert_eq!(status_code, 200);
|
||||
assert_eq!(response["hits"], body);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user