@@ -99,7 +99,8 @@ public static class Builder extends FieldMapper.Builder {
9999
100100 private final Parameter <Boolean > stored = Parameter .storeParam (m -> toType (m ).fieldType ().isStored (), false );
101101 private final Parameter <Map <String , String >> meta = Parameter .metaParam ();
102- private final Parameter <IndexOptions > indexOptions = new Parameter <>(SPARSE_VECTOR_INDEX_OPTIONS ,
102+ private final Parameter <IndexOptions > indexOptions = new Parameter <>(
103+ SPARSE_VECTOR_INDEX_OPTIONS ,
103104 true ,
104105 () -> null ,
105106 (n , c , o ) -> parseIndexOptions (c , o ),
@@ -170,8 +171,12 @@ private static SparseVectorFieldMapper.IndexOptions parseIndexOptions(MappingPar
170171
171172 Map <String , Object > indexOptionsMap = XContentMapValues .nodeMapValue (propNode , SPARSE_VECTOR_INDEX_OPTIONS );
172173
173- XContentParser parser =
174- new MapXContentParser (NamedXContentRegistry .EMPTY , DeprecationHandler .IGNORE_DEPRECATIONS , indexOptionsMap , XContentType .JSON );
174+ XContentParser parser = new MapXContentParser (
175+ NamedXContentRegistry .EMPTY ,
176+ DeprecationHandler .IGNORE_DEPRECATIONS ,
177+ indexOptionsMap ,
178+ XContentType .JSON
179+ );
175180
176181 try {
177182 return INDEX_OPTIONS_PARSER .parse (parser , null );
@@ -205,11 +210,10 @@ public SparseVectorFieldType(
205210 @ Nullable SparseVectorFieldMapper .IndexOptions indexOptions
206211 ) {
207212 super (name , true , isStored , false , TextSearchInfo .SIMPLE_MATCH_ONLY , meta );
208- this .indexOptions = indexOptions != null
209- ? indexOptions
213+ this .indexOptions = indexOptions != null ? indexOptions
210214 : SparseVectorFieldMapper .indexVersionSupportsDefaultPruningConfig (indexVersion )
211215 ? new IndexOptions (true , new TokenPruningConfig ())
212- : null ;
216+ : null ;
213217 }
214218
215219 public IndexOptions getIndexOptions () {
@@ -277,13 +281,14 @@ public Query finalizeSparseVectorQuery(
277281 }
278282
279283 return (shouldPruneTokens != null && shouldPruneTokens )
280- ? WeightedTokensUtils .queryBuilderWithPrunedTokens (
281- fieldName ,
282- tokenPruningConfig == null ? new TokenPruningConfig () : tokenPruningConfig ,
283- queryVectors ,
284- this ,
285- context
286- ) : WeightedTokensUtils .queryBuilderWithAllTokens (fieldName , queryVectors , this , context );
284+ ? WeightedTokensUtils .queryBuilderWithPrunedTokens (
285+ fieldName ,
286+ tokenPruningConfig == null ? new TokenPruningConfig () : tokenPruningConfig ,
287+ queryVectors ,
288+ this ,
289+ context
290+ )
291+ : WeightedTokensUtils .queryBuilderWithAllTokens (fieldName , queryVectors , this , context );
287292 }
288293
289294 private static String indexedValueForSearch (Object value ) {
@@ -344,7 +349,8 @@ public void parse(DocumentParserContext context) throws IOException {
344349
345350 if (context .parser ().currentToken () != Token .START_OBJECT ) {
346351 throw new IllegalArgumentException (
347- "[sparse_vector] fields must be json objects, expected a START_OBJECT but got: " + context .parser ().currentToken ());
352+ "[sparse_vector] fields must be json objects, expected a START_OBJECT but got: " + context .parser ().currentToken ()
353+ );
348354 }
349355
350356 final boolean isWithinLeaf = context .path ().isWithinLeafObject ();
@@ -372,8 +378,10 @@ public void parse(DocumentParserContext context) throws IOException {
372378 }
373379 } else {
374380 throw new IllegalArgumentException (
375- "[sparse_vector] fields take hashes that map a feature to a strictly positive " + "float, but got unexpected token "
376- + token );
381+ "[sparse_vector] fields take hashes that map a feature to a strictly positive "
382+ + "float, but got unexpected token "
383+ + token
384+ );
377385 }
378386 }
379387 if (context .indexSettings ().getIndexVersionCreated ().onOrAfter (SPARSE_VECTOR_IN_FIELD_NAMES_INDEX_VERSION )) {
@@ -396,10 +404,8 @@ protected String contentType() {
396404
397405 private static boolean indexVersionSupportsDefaultPruningConfig (IndexVersion indexVersion ) {
398406 // default pruning for 9.1.0+ or 8.19.0+ is true for this index
399- return (
400- indexVersion .onOrAfter (SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION ) ||
401- indexVersion .between (SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION_8_X , IndexVersions .UPGRADE_TO_LUCENE_10_0_0 )
402- );
407+ return (indexVersion .onOrAfter (SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION )
408+ || indexVersion .between (SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION_8_X , IndexVersions .UPGRADE_TO_LUCENE_10_0_0 ));
403409 }
404410
405411 private static class SparseVectorValueFetcher implements ValueFetcher {
@@ -522,8 +528,14 @@ public static class IndexOptions implements ToXContent {
522528 IndexOptions (@ Nullable Boolean prune , @ Nullable TokenPruningConfig pruningConfig ) {
523529 if (pruningConfig != null && (prune == null || prune == false )) {
524530 throw new IllegalArgumentException (
525- "[" + SPARSE_VECTOR_INDEX_OPTIONS + "] field [" + PRUNING_CONFIG_FIELD_NAME .getPreferredName ()
526- + "] should only be set if [" + PRUNE_FIELD_NAME .getPreferredName () + "] is set to true" );
531+ "["
532+ + SPARSE_VECTOR_INDEX_OPTIONS
533+ + "] field ["
534+ + PRUNING_CONFIG_FIELD_NAME .getPreferredName ()
535+ + "] should only be set if ["
536+ + PRUNE_FIELD_NAME .getPreferredName ()
537+ + "] is set to true"
538+ );
527539 }
528540
529541 this .prune = prune ;
0 commit comments