-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_string_test.rs
133 lines (111 loc) · 3.39 KB
/
query_string_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use os_query_builder_rs::full_text::query_string::QueryString;
use serde_json::json;
use os_query_builder_rs::misc::fuzziness::Fuzziness;
use os_query_builder_rs::model::Query;
#[test]
fn first_example_docs_test() {
let query_sting = QueryString::new().query("the wind AND (rises OR rising)");
let query = Query::new()
.query(query_sting);
let actual_json = json!(query);
let excepted_json = json!({
"query": {
"query_string": {
"query": "the wind AND (rises OR rising)"
}
}
});
assert_eq!(excepted_json, actual_json);
}
#[test]
fn first_example_from_docs_with_fuzziness_auto_test() {
let query_sting = QueryString::new()
.query("the wind AND (rises OR rising)")
.fuzziness(Fuzziness::Auto);
let query = Query::new()
.query(query_sting);
let actual_json = json!(query);
let excepted_json = json!({
"query": {
"query_string": {
"query": "the wind AND (rises OR rising)",
"fuzziness": "AUTO"
}
}
});
assert_eq!(excepted_json, actual_json);
}
#[test]
fn first_example_from_docs_with_fuzziness_uint_test() {
let query_sting = QueryString::new()
.query("the wind AND (rises OR rising)")
.fuzziness(Fuzziness::Uint(10));
let query = Query::new()
.query(query_sting);
let actual_json = json!(query);
let excepted_json = json!({
"query": {
"query_string": {
"query": "the wind AND (rises OR rising)",
"fuzziness": 10
}
}
});
assert_eq!(excepted_json, actual_json);
}
#[test]
fn simple_test() {
let query_sting = QueryString::new()
.query("historical epic heroic")
.minimum_should_match("2");
let query = Query::new()
.query(query_sting);
let actual_json = json!(query);
let excepted_json = json!({
"query": {
"query_string": {
"query": "historical epic heroic",
"minimum_should_match": "2"
}
}
});
assert_eq!(excepted_json, actual_json);
}
#[test]
fn query_string_all_fields_test() {
let query_sting = QueryString::new()
.query("historical epic heroic")
.minimum_should_match("2")
.fuzzy_transpositions(true)
.lenient(false)
.fuzziness(Fuzziness::Uint(10))
.analyzer("stop")
.auto_generate_synonyms_phrase_query(true)
.analyze_wildcard(false)
.allow_leading_wildcard(false)
.fuzzy_max_expansions(100u64)
.phrase_slop(150u64)
.enable_position_increments(false);
let query = Query::new()
.query(query_sting);
let actual_json = json!(query);
let excepted_json = json!({
"query": {
"query_string": {
"query": "historical epic heroic",
"minimum_should_match": "2",
"fuzzy_transpositions": true,
"lenient": false,
"fuzziness": 10,
"analyzer": "stop",
"auto_generate_synonyms_phrase_query":true,
"analyze_wildcard": false,
"allow_leading_wildcard": false,
"fuzzy_max_expansions":100,
"phrase_slop": 150,
"enable_position_increments": false
}
}
});
assert_eq!(excepted_json, actual_json);
}