1717import org .elasticsearch .common .xcontent .XContentHelper ;
1818import org .elasticsearch .plugins .Plugin ;
1919import org .elasticsearch .test .ESIntegTestCase ;
20-
2120import org .elasticsearch .xcontent .XContentType ;
2221import org .elasticsearch .xpack .core .XPackClientPlugin ;
2322import org .hamcrest .Matchers ;
@@ -41,11 +40,7 @@ public class SparseVectorIndexOptionsIT extends ESIntegTestCase {
4140 private final boolean testIndexShouldPrune ;
4241 private final boolean testQueryShouldNotPrune ;
4342
44- public SparseVectorIndexOptionsIT (
45- boolean setIndexOptions ,
46- boolean setIndexShouldPrune ,
47- boolean setQueryShouldNotPrune
48- ) {
43+ public SparseVectorIndexOptionsIT (boolean setIndexOptions , boolean setIndexShouldPrune , boolean setQueryShouldNotPrune ) {
4944 this .testHasIndexOptions = setIndexOptions ;
5045 this .testIndexShouldPrune = setIndexShouldPrune ;
5146 this .testQueryShouldNotPrune = setQueryShouldNotPrune ;
@@ -114,7 +109,7 @@ private void assertCorrectResponse(Map<String, Object> responseMap) {
114109 List <Map <String , Object >> hits = (List <Map <String , Object >>) mapHits .get ("hits" );
115110 List <String > actualDocIds = new ArrayList <>();
116111 for (Map <String , Object > doc : hits ) {
117- actualDocIds .add ((String )doc .get ("_id" ));
112+ actualDocIds .add ((String ) doc .get ("_id" ));
118113 }
119114
120115 assertEquals (getAssertMessage ("Result document ids mismatch" ), expectedIds , actualDocIds );
@@ -131,18 +126,10 @@ private String getTestIndexMapping() {
131126 + TEST_PRUNING_TOKENS_WEIGHT_THRESHOLD
132127 + "}" ;
133128
134- String pruningMappingString = testIndexShouldPrune
135- ? "\" prune\" :true," + testPruningConfigMapping
136- : "\" prune\" :false" ;
137- String indexOptionsString = testHasIndexOptions
138- ? ",\" index_options\" :{" + pruningMappingString + "}"
139- : "" ;
140-
141- return "{\" properties\" :{\" "
142- + SPARSE_VECTOR_FIELD
143- + "\" :{\" type\" :\" sparse_vector\" "
144- + indexOptionsString
145- + "}}}" ;
129+ String pruningMappingString = testIndexShouldPrune ? "\" prune\" :true," + testPruningConfigMapping : "\" prune\" :false" ;
130+ String indexOptionsString = testHasIndexOptions ? ",\" index_options\" :{" + pruningMappingString + "}" : "" ;
131+
132+ return "{\" properties\" :{\" " + SPARSE_VECTOR_FIELD + "\" :{\" type\" :\" sparse_vector\" " + indexOptionsString + "}}}" ;
146133 }
147134
148135 private boolean isRunningAgainstOldCluster () {
@@ -157,9 +144,7 @@ private List<String> getTestExpectedDocIds() {
157144
158145 if (testHasIndexOptions ) {
159146 // index has set index options in the mapping
160- return testIndexShouldPrune
161- ? EXPECTED_DOC_IDS_WITH_PRUNING
162- : EXPECTED_DOC_IDS_WITHOUT_PRUNING ;
147+ return testIndexShouldPrune ? EXPECTED_DOC_IDS_WITH_PRUNING : EXPECTED_DOC_IDS_WITHOUT_PRUNING ;
163148 }
164149
165150 // default pruning should be true with default configuration
@@ -174,7 +159,7 @@ private Response performSearch(String source) throws IOException {
174159
175160 private String getBuilderForSearch () {
176161 boolean shouldUseDefaultTokens = (testQueryShouldNotPrune == false && testHasIndexOptions == false );
177- SparseVectorQueryBuilder queryBuilder = new SparseVectorQueryBuilder (
162+ SparseVectorQueryBuilder queryBuilder = new SparseVectorQueryBuilder (
178163 SPARSE_VECTOR_FIELD ,
179164 shouldUseDefaultTokens ? SEARCH_WEIGHTED_TOKENS_WITH_DEFAULTS : SEARCH_WEIGHTED_TOKENS ,
180165 null ,
@@ -218,9 +203,12 @@ private String getDescriptiveTestType() {
218203 }
219204
220205 private static final Map <String , String > TEST_DOCUMENTS = Map .of (
221- "1" , "{\" sparse_vector_field\" :{\" cheese\" : 2.671405,\" is\" : 0.11809908,\" comet\" : 0.26088917}}" ,
222- "2" , "{\" sparse_vector_field\" :{\" planet\" : 2.3438394,\" is\" : 0.54600334,\" astronomy\" : 0.36015007,\" moon\" : 0.20022368}}" ,
223- "3" , "{\" sparse_vector_field\" :{\" is\" : 0.6891394,\" globe\" : 0.484035,\" ocean\" : 0.080102935,\" underground\" : 0.053516876}}"
206+ "1" ,
207+ "{\" sparse_vector_field\" :{\" cheese\" : 2.671405,\" is\" : 0.11809908,\" comet\" : 0.26088917}}" ,
208+ "2" ,
209+ "{\" sparse_vector_field\" :{\" planet\" : 2.3438394,\" is\" : 0.54600334,\" astronomy\" : 0.36015007,\" moon\" : 0.20022368}}" ,
210+ "3" ,
211+ "{\" sparse_vector_field\" :{\" is\" : 0.6891394,\" globe\" : 0.484035,\" ocean\" : 0.080102935,\" underground\" : 0.053516876}}"
224212 );
225213
226214 private static final List <WeightedToken > SEARCH_WEIGHTED_TOKENS = List .of (
@@ -232,13 +220,9 @@ private String getDescriptiveTestType() {
232220 new WeightedToken ("is" , 0.54600334f )
233221 );
234222
235- private static final List <WeightedToken > SEARCH_WEIGHTED_TOKENS_WITH_DEFAULTS = List .of (
236- new WeightedToken ("planet" , 0.2f )
237- );
223+ private static final List <WeightedToken > SEARCH_WEIGHTED_TOKENS_WITH_DEFAULTS = List .of (new WeightedToken ("planet" , 0.2f ));
238224
239- private static final List <String > EXPECTED_DOC_IDS_WITHOUT_PRUNING = List .of (
240- "1" , "3" , "2"
241- );
225+ private static final List <String > EXPECTED_DOC_IDS_WITHOUT_PRUNING = List .of ("1" , "3" , "2" );
242226
243227 private static final List <String > EXPECTED_DOC_IDS_WITH_PRUNING = List .of ("1" );
244228
0 commit comments