From 0447594e027cdd559f98849bb8480f28501617ac Mon Sep 17 00:00:00 2001 From: many Date: Thu, 17 Dec 2020 15:13:58 +0100 Subject: [PATCH] add search test on chinese scripts --- meilisearch-http/src/helpers/meilisearch.rs | 3 +- meilisearch-http/tests/assets/test_set.json | 14 ++--- meilisearch-http/tests/search.rs | 60 +++++++++++++++++++++ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/meilisearch-http/src/helpers/meilisearch.rs b/meilisearch-http/src/helpers/meilisearch.rs index 2db6472ca..57186a2d8 100644 --- a/meilisearch-http/src/helpers/meilisearch.rs +++ b/meilisearch-http/src/helpers/meilisearch.rs @@ -597,7 +597,7 @@ mod tests { let mut m = Vec::new(); m.push(MatchPosition { - start: 510, + start: 529, length: 9, }); matches.insert("description".to_string(), m); @@ -613,6 +613,7 @@ mod tests { assert_eq!(result, result_expected); } + #[test] fn highlight_longest_match() { let data = r#"{ diff --git a/meilisearch-http/tests/assets/test_set.json b/meilisearch-http/tests/assets/test_set.json index 63534c896..b035ac334 100644 --- a/meilisearch-http/tests/assets/test_set.json +++ b/meilisearch-http/tests/assets/test_set.json @@ -1590,18 +1590,18 @@ "tags": [] }, { - "id": 76, + "id": 77, "isActive": false, "balance": "$1,274.29", "picture": "http://placehold.it/32x32", "age": 25, - "color": "Green", - "name": "Clarice Gardner", - "gender": "female", - "email": "claricegardner@chorizon.com", + "color": "Red", + "name": "孙武", + "gender": "male", + "email": "SunTzu@chorizon.com", "phone": "+1 (810) 407-3258", - "address": "894 Brooklyn Road, Utting, New Hampshire, 6404", - "about": "Elit occaecat aute ea adipisicing mollit cupidatat aliquip excepteur veniam minim. Sunt quis dolore in commodo aute esse quis. Lorem in cillum commodo eu anim commodo mollit. Adipisicing enim sunt adipisicing cupidatat adipisicing eiusmod eu do sit nisi.\r\n", + "address": "吴国", + "about": "孫武(前544年-前470年或前496年),字長卿,春秋時期齊國人,著名軍事家、政治家,兵家代表人物。兵書《孙子兵法》的作者,後人尊稱為孫子、兵聖、東方兵聖,山東、蘇州等地尚有祀奉孫武的廟宇兵聖廟。其族人为乐安孙氏始祖,次子孙明为富春孙氏始祖。\r\n", "registered": "2014-10-20T10:13:32 -02:00", "latitude": 17.11935, "longitude": 65.38197, diff --git a/meilisearch-http/tests/search.rs b/meilisearch-http/tests/search.rs index 6a496809e..82804a019 100644 --- a/meilisearch-http/tests/search.rs +++ b/meilisearch-http/tests/search.rs @@ -358,6 +358,66 @@ async fn search_with_attribute_to_highlight_wildcard() { }); } +#[actix_rt::test] +async fn search_with_attribute_to_highlight_wildcard_chinese() { + let mut server = common::Server::test_server().await; + + let query = json!({ + "q": "子孙", + "limit": 1, + "attributesToHighlight": ["*"] + }); + + let expected = json!([ + { + "id": 77, + "isActive": false, + "balance": "$1,274.29", + "picture": "http://placehold.it/32x32", + "age": 25, + "color": "Red", + "name": "孙武", + "gender": "male", + "email": "SunTzu@chorizon.com", + "phone": "+1 (810) 407-3258", + "address": "吴国", + "about": "孫武(前544年-前470年或前496年),字長卿,春秋時期齊國人,著名軍事家、政治家,兵家代表人物。兵書《孙子兵法》的作者,後人尊稱為孫子、兵聖、東方兵聖,山東、蘇州等地尚有祀奉孫武的廟宇兵聖廟。其族人为乐安孙氏始祖,次子孙明为富春孙氏始祖。\r\n", + "registered": "2014-10-20T10:13:32 -02:00", + "latitude": 17.11935, + "longitude": 65.38197, + "tags": [ + "new issue", + "wontfix" + ], + "_formatted": { + "id": 77, + "isActive": false, + "balance": "$1,274.29", + "picture": "http://placehold.it/32x32", + "age": 25, + "color": "Red", + "name": "孙武", + "gender": "male", + "email": "SunTzu@chorizon.com", + "phone": "+1 (810) 407-3258", + "address": "吴国", + "about": "孫武(前544年-前470年或前496年),字長卿,春秋時期齊國人,著名軍事家、政治家,兵家代表人物。兵書《孙子兵法》的作者,後人尊稱為孫子、兵聖、東方兵聖,山東、蘇州等地尚有祀奉孫武的廟宇兵聖廟。其族人为乐安氏始祖,次子孙明为富春氏始祖。\r\n", + "registered": "2014-10-20T10:13:32 -02:00", + "latitude": 17.11935, + "longitude": 65.38197, + "tags": [ + "new issue", + "wontfix" + ] + } + } + ]); + + test_post_get_search!(server, query, |response, _status_code| { + assert_json_eq!(expected.clone(), response["hits"].clone(), ordered: false); + }); +} + #[actix_rt::test] async fn search_with_attribute_to_highlight_1() { let mut server = common::Server::test_server().await;