2020-04-03 15:00:41 +02:00
|
|
|
use assert_json_diff::assert_json_eq;
|
|
|
|
use serde_json::json;
|
|
|
|
use std::convert::Into;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_basic() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender",
|
|
|
|
"color",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"balance"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"stopWords": null,
|
|
|
|
"synonyms": null,
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=ea%20exercitation&limit=3";
|
|
|
|
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$2,467.47",
|
|
|
|
"age": 34,
|
|
|
|
"color": "blue",
|
|
|
|
"name": "Patricia Goff",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "patriciagoff@chorizon.com",
|
|
|
|
"phone": "+1 (864) 463-2277",
|
|
|
|
"address": "866 Hornell Loop, Cresaptown, Ohio, 1700"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$3,344.40",
|
|
|
|
"age": 35,
|
|
|
|
"color": "blue",
|
|
|
|
"name": "Adeline Flynn",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "adelineflynn@chorizon.com",
|
|
|
|
"phone": "+1 (994) 600-2840",
|
|
|
|
"address": "428 Paerdegat Avenue, Hollymead, Pennsylvania, 948"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$3,394.96",
|
|
|
|
"age": 25,
|
|
|
|
"color": "blue",
|
|
|
|
"name": "Aida Kirby",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "aidakirby@chorizon.com",
|
|
|
|
"phone": "+1 (942) 532-2325",
|
|
|
|
"address": "797 Engert Avenue, Wilsonia, Idaho, 6532"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_stop_words() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender",
|
|
|
|
"color",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"balance"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
2020-06-27 12:49:19 +02:00
|
|
|
"stopWords": ["ea"],
|
2020-04-03 15:00:41 +02:00
|
|
|
"synonyms": null,
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=ea%20exercitation&limit=3";
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,921.58",
|
|
|
|
"age": 31,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Harper Carson",
|
|
|
|
"gender": "male",
|
|
|
|
"email": "harpercarson@chorizon.com",
|
|
|
|
"phone": "+1 (912) 430-3243",
|
|
|
|
"address": "883 Dennett Place, Knowlton, New Mexico, 9219"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,706.13",
|
|
|
|
"age": 27,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Cherry Orr",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "cherryorr@chorizon.com",
|
|
|
|
"phone": "+1 (995) 479-3174",
|
|
|
|
"address": "442 Beverly Road, Ventress, New Mexico, 3361"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,476.39",
|
|
|
|
"age": 28,
|
|
|
|
"color": "brown",
|
|
|
|
"name": "Maureen Dale",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "maureendale@chorizon.com",
|
|
|
|
"phone": "+1 (984) 538-3684",
|
|
|
|
"address": "817 Newton Street, Bannock, Wyoming, 1468"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_synonyms() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender",
|
|
|
|
"color",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"balance"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"stopWords": null,
|
|
|
|
"synonyms": {
|
2020-06-27 12:49:19 +02:00
|
|
|
"application": [
|
|
|
|
"exercitation"
|
|
|
|
]
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=application&limit=3";
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,921.58",
|
|
|
|
"age": 31,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Harper Carson",
|
|
|
|
"gender": "male",
|
|
|
|
"email": "harpercarson@chorizon.com",
|
|
|
|
"phone": "+1 (912) 430-3243",
|
|
|
|
"address": "883 Dennett Place, Knowlton, New Mexico, 9219"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,706.13",
|
|
|
|
"age": 27,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Cherry Orr",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "cherryorr@chorizon.com",
|
|
|
|
"phone": "+1 (995) 479-3174",
|
|
|
|
"address": "442 Beverly Road, Ventress, New Mexico, 3361"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,476.39",
|
|
|
|
"age": 28,
|
|
|
|
"color": "brown",
|
|
|
|
"name": "Maureen Dale",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "maureendale@chorizon.com",
|
|
|
|
"phone": "+1 (984) 538-3684",
|
|
|
|
"address": "817 Newton Street, Bannock, Wyoming, 1468"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_ranking_rules() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender",
|
|
|
|
"color",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"balance"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"stopWords": null,
|
|
|
|
"synonyms": null,
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=exarcitation&limit=3";
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,921.58",
|
|
|
|
"age": 31,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Harper Carson",
|
|
|
|
"gender": "male",
|
|
|
|
"email": "harpercarson@chorizon.com",
|
|
|
|
"phone": "+1 (912) 430-3243",
|
|
|
|
"address": "883 Dennett Place, Knowlton, New Mexico, 9219"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,706.13",
|
|
|
|
"age": 27,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Cherry Orr",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "cherryorr@chorizon.com",
|
|
|
|
"phone": "+1 (995) 479-3174",
|
|
|
|
"address": "442 Beverly Road, Ventress, New Mexico, 3361"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,476.39",
|
|
|
|
"age": 28,
|
|
|
|
"color": "brown",
|
|
|
|
"name": "Maureen Dale",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "maureendale@chorizon.com",
|
|
|
|
"phone": "+1 (984) 538-3684",
|
|
|
|
"address": "817 Newton Street, Bannock, Wyoming, 1468"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-06-27 12:49:19 +02:00
|
|
|
println!("{}", response["hits"].clone());
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_searchable_attributes() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender",
|
|
|
|
"color",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"balance"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"stopWords": null,
|
2020-06-27 12:49:19 +02:00
|
|
|
"synonyms": {
|
|
|
|
"exarcitation": [
|
|
|
|
"exercitation"
|
|
|
|
]
|
|
|
|
},
|
2020-04-03 15:00:41 +02:00
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=Carol&limit=3";
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,440.09",
|
|
|
|
"age": 40,
|
|
|
|
"color": "blue",
|
|
|
|
"name": "Levy Whitley",
|
|
|
|
"gender": "male",
|
|
|
|
"email": "levywhitley@chorizon.com",
|
|
|
|
"phone": "+1 (911) 458-2411",
|
|
|
|
"address": "187 Thomas Street, Hachita, North Carolina, 2989"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"balance": "$1,977.66",
|
|
|
|
"age": 36,
|
|
|
|
"color": "brown",
|
|
|
|
"name": "Combs Stanley",
|
|
|
|
"gender": "male",
|
|
|
|
"email": "combsstanley@chorizon.com",
|
|
|
|
"phone": "+1 (827) 419-2053",
|
|
|
|
"address": "153 Beverley Road, Siglerville, South Carolina, 3666"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_displayed_attributes() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender",
|
|
|
|
"color",
|
|
|
|
"email",
|
|
|
|
"phone"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"stopWords": null,
|
|
|
|
"synonyms": null,
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=exercitation&limit=3";
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"age": 31,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Harper Carson",
|
|
|
|
"gender": "male",
|
|
|
|
"email": "harpercarson@chorizon.com",
|
|
|
|
"phone": "+1 (912) 430-3243"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"age": 27,
|
|
|
|
"color": "green",
|
|
|
|
"name": "Cherry Orr",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "cherryorr@chorizon.com",
|
|
|
|
"phone": "+1 (995) 479-3174"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"age": 28,
|
|
|
|
"color": "brown",
|
|
|
|
"name": "Maureen Dale",
|
|
|
|
"gender": "female",
|
|
|
|
"email": "maureendale@chorizon.com",
|
|
|
|
"phone": "+1 (984) 538-3684"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn search_with_settings_searchable_attributes_2() {
|
2020-06-27 12:49:19 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
|
|
|
let config = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(age)",
|
2020-04-03 15:00:41 +02:00
|
|
|
"exactness",
|
2020-06-27 12:49:19 +02:00
|
|
|
"desc(balance)"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"age",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-06-27 12:49:19 +02:00
|
|
|
"name",
|
|
|
|
"age",
|
|
|
|
"gender"
|
2020-04-03 15:00:41 +02:00
|
|
|
],
|
|
|
|
"stopWords": null,
|
|
|
|
"synonyms": null,
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(config).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
|
2020-06-27 12:49:19 +02:00
|
|
|
let query = "q=exercitation&limit=3";
|
2020-04-03 15:00:41 +02:00
|
|
|
let expect = json!([
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"age": 31,
|
|
|
|
"name": "Harper Carson",
|
|
|
|
"gender": "male"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"age": 27,
|
|
|
|
"name": "Cherry Orr",
|
|
|
|
"gender": "female"
|
2020-04-03 15:00:41 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-27 12:49:19 +02:00
|
|
|
"age": 28,
|
|
|
|
"name": "Maureen Dale",
|
|
|
|
"gender": "female"
|
2020-04-03 15:00:41 +02:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-06-01 14:54:12 +02:00
|
|
|
let (response, _status_code) = server.search_get(query).await;
|
2020-04-03 15:00:41 +02:00
|
|
|
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
|
|
|
}
|
2020-06-27 10:38:08 +02:00
|
|
|
|
|
|
|
// issue #798
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn distinct_attributes_returns_name_not_id() {
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
let settings = json!({
|
|
|
|
"distinctAttribute": "color",
|
|
|
|
});
|
|
|
|
server.update_all_settings(settings).await;
|
|
|
|
let (response, _) = server.get_all_settings().await;
|
|
|
|
assert_eq!(response["distinctAttribute"], "color");
|
|
|
|
let (response, _) = server.get_distinct_attribute().await;
|
|
|
|
assert_eq!(response, "color");
|
|
|
|
}
|