-
Notifications
You must be signed in to change notification settings - Fork 28
/
CommonTest.kt
119 lines (109 loc) · 3.3 KB
/
CommonTest.kt
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
/*
* Copyright (c) 2016. Michael Buhot m.buhot@gmail.com
*/
package mbuhot.eskotlin.query.fulltext
import mbuhot.eskotlin.query.should_render_as
import org.junit.Test
class CommonTest {
@Test
fun `test common terms query`() {
val query = common {
"body" {
query = "this is bonsai cool"
cutoff_frequency = 0.001f
}
}
query should_render_as """
{
"common": {
"body": {
"query": "this is bonsai cool",
"high_freq_operator": "OR",
"low_freq_operator": "OR",
"cutoff_frequency": 0.001,
"boost": 1.0
}
}
}
"""
}
@Test
fun `test common terms with low_frequency operator`() {
val query = common {
"body" {
query = "nelly the elephant as a cartoon"
cutoff_frequency = 0.001f
low_freq_operator = "and"
}
}
query should_render_as """
{
"common": {
"body": {
"query": "nelly the elephant as a cartoon",
"high_freq_operator": "OR",
"low_freq_operator": "AND",
"cutoff_frequency": 0.001,
"boost": 1.0
}
}
}
"""
}
@Test
fun `test common terms with minimum_should_match`() {
val query = common {
"body" {
query = "nelly the elephant as a cartoon"
cutoff_frequency = 0.001f
minimum_should_match.low_freq = 2
}
}
query should_render_as """
{
"common": {
"body": {
"query": "nelly the elephant as a cartoon",
"high_freq_operator": "OR",
"low_freq_operator": "OR",
"cutoff_frequency": 0.001,
"minimum_should_match": {
"low_freq": "2"
},
"boost": 1.0
}
}
}
"""
}
@Test
fun `test common terms with separate minimum_should_match high and low`() {
val query = common {
"body" {
query = "nelly the elephant not as a cartoon"
cutoff_frequency = 0.001f
minimum_should_match {
low_freq = 2
high_freq = 3
}
}
}
query should_render_as """
{
"common": {
"body": {
"query": "nelly the elephant not as a cartoon",
"high_freq_operator": "OR",
"low_freq_operator": "OR",
"cutoff_frequency": 0.001,
"minimum_should_match": {
"low_freq": "2",
"high_freq": "3"
},
"boost": 1.0
}
}
}
"""
}
}