19
19
20
20
package org .elasticsearch .search .searchafter ;
21
21
22
+ import org .apache .lucene .document .LatLonDocValuesField ;
23
+ import org .apache .lucene .search .FieldComparator ;
24
+ import org .apache .lucene .search .SortField ;
25
+ import org .apache .lucene .search .SortedNumericSortField ;
26
+ import org .apache .lucene .search .SortedSetSortField ;
22
27
import org .elasticsearch .common .geo .GeoPoint ;
23
28
import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
24
29
import org .elasticsearch .common .text .Text ;
27
32
import org .elasticsearch .common .xcontent .XContentParser ;
28
33
import org .elasticsearch .common .xcontent .XContentType ;
29
34
import org .elasticsearch .common .xcontent .json .JsonXContent ;
35
+ import org .elasticsearch .index .fielddata .IndexFieldData ;
36
+ import org .elasticsearch .search .MultiValueMode ;
30
37
import org .elasticsearch .test .ESTestCase ;
31
- import org .hamcrest .Matchers ;
32
38
33
39
import java .io .IOException ;
34
40
import java .util .Collections ;
35
41
42
+ import static org .elasticsearch .search .searchafter .SearchAfterBuilder .extractSortType ;
36
43
import static org .elasticsearch .test .EqualsHashCodeTestUtils .checkEqualsAndHashCode ;
44
+ import static org .hamcrest .Matchers .equalTo ;
37
45
38
46
public class SearchAfterBuilderTests extends ESTestCase {
39
47
private static final int NUMBER_OF_TESTBUILDERS = 20 ;
@@ -182,7 +190,7 @@ public void testWithNullArray() throws Exception {
182
190
builder .setSortValues (null );
183
191
fail ("Should fail on null array." );
184
192
} catch (NullPointerException e ) {
185
- assertThat (e .getMessage (), Matchers . equalTo ("Values cannot be null." ));
193
+ assertThat (e .getMessage (), equalTo ("Values cannot be null." ));
186
194
}
187
195
}
188
196
@@ -192,7 +200,7 @@ public void testWithEmptyArray() throws Exception {
192
200
builder .setSortValues (new Object [0 ]);
193
201
fail ("Should fail on empty array." );
194
202
} catch (IllegalArgumentException e ) {
195
- assertThat (e .getMessage (), Matchers . equalTo ("Values must contains at least one value." ));
203
+ assertThat (e .getMessage (), equalTo ("Values must contains at least one value." ));
196
204
}
197
205
}
198
206
@@ -215,4 +223,29 @@ private static void randomSearchFromBuilderWithSortValueThrows(Object containing
215
223
Exception e = expectThrows (IllegalArgumentException .class , () -> builder .setSortValues (values ));
216
224
assertEquals (e .getMessage (), "Can't handle search_after field value of type [" + containing .getClass () + "]" );
217
225
}
226
+
227
+ public void testExtractSortType () throws Exception {
228
+ SortField .Type type = extractSortType (LatLonDocValuesField .newDistanceSort ("field" , 0.0 , 180.0 ));
229
+ assertThat (type , equalTo (SortField .Type .DOUBLE ));
230
+ IndexFieldData .XFieldComparatorSource source = new IndexFieldData .XFieldComparatorSource (null , MultiValueMode .MIN , null ) {
231
+ @ Override
232
+ public SortField .Type reducedType () {
233
+ return SortField .Type .STRING ;
234
+ }
235
+
236
+ @ Override
237
+ public FieldComparator <?> newComparator (String fieldname , int numHits , int sortPos , boolean reversed ) {
238
+ return null ;
239
+ }
240
+ };
241
+
242
+ type = extractSortType (new SortField ("field" , source ));
243
+ assertThat (type , equalTo (SortField .Type .STRING ));
244
+
245
+ type = extractSortType (new SortedNumericSortField ("field" , SortField .Type .DOUBLE ));
246
+ assertThat (type , equalTo (SortField .Type .DOUBLE ));
247
+
248
+ type = extractSortType (new SortedSetSortField ("field" , false ));
249
+ assertThat (type , equalTo (SortField .Type .STRING ));
250
+ }
218
251
}
0 commit comments