32
32
33
33
package org .opensearch .index .query ;
34
34
35
- import org .apache .lucene .search .MatchAllDocsQuery ;
36
35
import org .apache .lucene .search .Query ;
37
36
import org .apache .lucene .search .TotalHits ;
38
- import org .opensearch .action .ListenableActionFuture ;
39
- import org .opensearch .action .search .SearchRequest ;
40
37
import org .opensearch .action .search .SearchResponse ;
41
38
import org .opensearch .core .common .bytes .BytesArray ;
42
- import org .opensearch .index .mapper .MappedFieldType ;
43
39
import org .opensearch .indices .TermsLookup ;
44
40
import org .opensearch .search .SearchHit ;
45
41
import org .opensearch .search .SearchHits ;
46
42
import org .opensearch .test .OpenSearchTestCase ;
47
- import org .opensearch .transport .client .Client ;
48
43
49
44
import java .io .IOException ;
50
45
import java .util .Arrays ;
51
- import java .util .Collections ;
52
- import java .util .List ;
53
- import java .util .Map ;
54
46
55
47
import static org .hamcrest .CoreMatchers .instanceOf ;
56
- import static org .mockito .ArgumentMatchers . any ;
57
- import static org .mockito .Mockito .* ;
48
+ import static org .mockito .Mockito . mock ;
49
+ import static org .mockito .Mockito .when ;
58
50
59
51
public class TermQueryWithDocIdAndQueryTests extends OpenSearchTestCase {
60
52
public void testTermsQueryWithIdOnlyAndVerifyResults () throws Exception {
@@ -72,9 +64,9 @@ public void testTermsQueryWithIdOnlyAndVerifyResults() throws Exception {
72
64
// Mock the search response
73
65
SearchResponse mockResponse = mock (SearchResponse .class );
74
66
SearchHits mockHits = new SearchHits (
75
- new SearchHit []{
67
+ new SearchHit [] {
76
68
new SearchHit (1 ).sourceRef (new BytesArray ("{\" name\" :\" Jane Doe\" ,\" student_id\" :\" 111\" }" )),
77
- new SearchHit (2 ).sourceRef (new BytesArray ("{\" name\" :\" Mary Major\" ,\" student_id\" :\" 222\" }" ))},
69
+ new SearchHit (2 ).sourceRef (new BytesArray ("{\" name\" :\" Mary Major\" ,\" student_id\" :\" 222\" }" )) },
78
70
new TotalHits (2 , TotalHits .Relation .EQUAL_TO ), // Use TotalHits instead of int
79
71
1.0f
80
72
);
@@ -112,9 +104,9 @@ public void testTermsQueryWithQueryOnlyAndVerifyResults() throws Exception {
112
104
// Mock the search response
113
105
SearchResponse mockResponse = mock (SearchResponse .class );
114
106
SearchHits mockHits = new SearchHits (
115
- new SearchHit []{
107
+ new SearchHit [] {
116
108
new SearchHit (1 ).sourceRef (new BytesArray ("{\" name\" :\" Jane Doe\" ,\" student_id\" :\" 111\" }" )),
117
- new SearchHit (2 ).sourceRef (new BytesArray ("{\" name\" :\" Mary Major\" ,\" student_id\" :\" 222\" }" ))},
109
+ new SearchHit (2 ).sourceRef (new BytesArray ("{\" name\" :\" Mary Major\" ,\" student_id\" :\" 222\" }" )) },
118
110
new TotalHits (2 , TotalHits .Relation .EQUAL_TO ),
119
111
1.0f
120
112
);
@@ -191,9 +183,9 @@ public void testTermsQueryWithInsertedData() throws Exception {
191
183
// Mock the search response
192
184
SearchResponse mockResponse = mock (SearchResponse .class );
193
185
SearchHits mockHits = new SearchHits (
194
- new SearchHit []{
186
+ new SearchHit [] {
195
187
new SearchHit (1 ).sourceRef (new BytesArray ("{\" name\" :\" John Smith\" ,\" student_id\" :\" 333\" }" )),
196
- new SearchHit (2 ).sourceRef (new BytesArray ("{\" name\" :\" Alice Brown\" ,\" student_id\" :\" 444\" }" ))},
188
+ new SearchHit (2 ).sourceRef (new BytesArray ("{\" name\" :\" Alice Brown\" ,\" student_id\" :\" 444\" }" )) },
197
189
new TotalHits (2 , TotalHits .Relation .EQUAL_TO ),
198
190
1.0f
199
191
);
@@ -210,9 +202,7 @@ public void testTermsQueryWithInsertedData() throws Exception {
210
202
211
203
public void testTermsQueryWithNoIdAndNoQuery () {
212
204
// Attempt to create a TermsLookup with no id and no query
213
- Exception exception = expectThrows (IllegalArgumentException .class , () -> {
214
- new TermsLookup ("classes" , null , "enrolled" );
215
- });
205
+ Exception exception = expectThrows (IllegalArgumentException .class , () -> { new TermsLookup ("classes" , null , "enrolled" ); });
216
206
217
207
// Verify the exception message
218
208
assertEquals (
@@ -256,7 +246,6 @@ public void testTermsQueryWithComplexQuery() throws Exception {
256
246
public void testRewriteWithTermsLookupQuery () throws IOException {
257
247
QueryBuilder spyQuery = mock (QueryBuilder .class );
258
248
259
-
260
249
TermsLookup termsLookup = new TermsLookup ("test-index" , null , "field" , spyQuery );
261
250
262
251
// Create the TermsQueryBuilder with the TermsLookup
@@ -276,15 +265,15 @@ public void testRewriteWithTermsLookupQuery() throws IOException {
276
265
assertEquals (1.0f , resultTermsQuery .boost (), 0.001f );
277
266
278
267
// Optionally, check the JSON representation if you want string-based asserts
279
- String expectedJson = "{\n " +
280
- " \" terms\" : {\n " +
281
- " \" field\" : [\n " +
282
- " \" value1\" ,\n " +
283
- " \" value2\" \n " +
284
- " ],\n " +
285
- " \" boost\" : 1.0\n " +
286
- " }\n " +
287
- "}" ;
268
+ String expectedJson = "{\n "
269
+ + " \" terms\" : {\n "
270
+ + " \" field\" : [\n "
271
+ + " \" value1\" ,\n "
272
+ + " \" value2\" \n "
273
+ + " ],\n "
274
+ + " \" boost\" : 1.0\n "
275
+ + " }\n "
276
+ + "}" ;
288
277
assertEquals (expectedJson , result .toString ());
289
278
}
290
279
}
0 commit comments