-
Notifications
You must be signed in to change notification settings - Fork 28
/
MultiMatchTest.kt
148 lines (136 loc) · 4.46 KB
/
MultiMatchTest.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* 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 MultiMatchTest {
@Test
fun `test multi_match`() {
val query = multi_match {
query = "this is a test"
fields = listOf("subject", "message")
}
query should_render_as """
{
"multi_match": {
"query": "this is a test",
"fields": ["message^1.0", "subject^1.0"],
"type": "best_fields",
"operator": "OR",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
"""
}
@Test
fun `test multi_match with best_fields type`() {
val query = multi_match {
query = "brown fox"
type = "best_fields"
fields = listOf("subject", "message")
tie_breaker = 0.3f
}
query should_render_as """
{
"multi_match": {
"query": "brown fox",
"fields": ["message^1.0", "subject^1.0"],
"type": "best_fields",
"operator": "OR",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"tie_breaker": 0.3,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
"""
}
@Test
fun `test multi_match with operator`() {
val query = multi_match {
query = "Will Smith"
type = "cross_fields"
fields = listOf("first_name", "last_name")
operator = "and"
}
query should_render_as """
{
"multi_match": {
"query": "Will Smith",
"fields": ["first_name^1.0", "last_name^1.0"],
"type": "cross_fields",
"operator": "AND",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
"""
}
@Test
fun `test multi_match with analyzer`() {
val query = multi_match {
query = "Jon"
type = "cross_fields"
analyzer = "standard"
fields = listOf("first", "last", "*.edge")
}
query should_render_as """
{
"multi_match": {
"query": "Jon",
"fields": ["*.edge^1.0", "first^1.0", "last^1.0"],
"type": "cross_fields",
"operator": "OR",
"analyzer": "standard",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
"""
}
@Test
fun `test multi_match with boost`() {
val query = multi_match {
query = "this is a test"
fields = listOf("subject","message^2.0")
}
query should_render_as """
{
"multi_match": {
"query": "this is a test",
"fields": ["message^2.0", "subject^1.0"],
"type": "best_fields",
"operator": "OR",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
"""
}
}