@@ -351,13 +351,6 @@ public TransportVersion getMinimalSupportedVersion() {
351351 }
352352
353353 private TokenPruningConfig getTokenPruningConfigForQuery (MappedFieldType ft , SearchExecutionContext context ) {
354- TokenPruningConfig queryPruningConfig = (shouldPruneTokens != null && shouldPruneTokens ) ? tokenPruningConfig : null ;
355-
356- // query values should always override any index options
357- if (shouldPruneTokens != null ) {
358- return queryPruningConfig ;
359- }
360-
361354 // if we are not on a supported index version, do not prune by default
362355 // nor do we check the index options
363356 if (context .indexVersionCreated ().onOrAfter (IndexVersions .SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT ) == false
@@ -366,34 +359,33 @@ private TokenPruningConfig getTokenPruningConfigForQuery(MappedFieldType ft, Sea
366359 IndexVersions .SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT_BACKPORT_8_X ,
367360 IndexVersions .UPGRADE_TO_LUCENE_10_0_0
368361 ) == false ) {
369- return null ;
362+ return ( shouldPruneTokens != null && shouldPruneTokens ) ? tokenPruningConfig : null ;
370363 }
371364
372- if (ft instanceof SparseVectorFieldMapper .SparseVectorFieldType asSVFieldType ) {
373- Boolean pruneTokensToUse = shouldPruneTokens ;
374- TokenPruningConfig pruningConfigToUse = tokenPruningConfig ;
365+ Boolean shouldQueryPruneTokens = shouldPruneTokens ;
366+ TokenPruningConfig pruningConfigToUse = tokenPruningConfig ;
375367
376- if (asSVFieldType .getIndexOptions () != null ) {
377- pruneTokensToUse = asSVFieldType .getIndexOptions ().getPrune ();
378- pruningConfigToUse = pruningConfigToUse == null ? asSVFieldType .getIndexOptions ().getPruningConfig () : pruningConfigToUse ;
379- }
368+ if (ft instanceof SparseVectorFieldMapper .SparseVectorFieldType asSVFieldType
369+ && asSVFieldType .getIndexOptions () != null
370+ ) {
371+ shouldQueryPruneTokens = shouldQueryPruneTokens == null ? asSVFieldType .getIndexOptions ().getPrune () : shouldQueryPruneTokens ;
372+ pruningConfigToUse = pruningConfigToUse == null ? asSVFieldType .getIndexOptions ().getPruningConfig () : pruningConfigToUse ;
373+ }
380374
381- // if we're still null, use defaults
382- pruneTokensToUse = pruneTokensToUse == null ? true : pruneTokensToUse ;
383- pruningConfigToUse = pruningConfigToUse == null
384- ? new TokenPruningConfig (
385- TokenPruningConfig .DEFAULT_TOKENS_FREQ_RATIO_THRESHOLD ,
386- TokenPruningConfig .DEFAULT_TOKENS_WEIGHT_THRESHOLD ,
387- false
388- )
389- : pruningConfigToUse ;
390-
391- return pruneTokensToUse ? pruningConfigToUse : null ;
375+ if (shouldQueryPruneTokens != null && shouldQueryPruneTokens == false ) {
376+ return null ;
392377 }
393378
394- // should never happen that we're not operating on a SparseVectorFieldType
395- // but just in case, return null and do not prune
396- return null ;
379+ // if we're here, we should prune if set or by default
380+ // if we don't have a pruning config, use the default
381+ pruningConfigToUse = pruningConfigToUse == null
382+ ? new TokenPruningConfig (
383+ TokenPruningConfig .DEFAULT_TOKENS_FREQ_RATIO_THRESHOLD ,
384+ TokenPruningConfig .DEFAULT_TOKENS_WEIGHT_THRESHOLD ,
385+ false
386+ ) : pruningConfigToUse ;
387+
388+ return pruningConfigToUse ;
397389 }
398390
399391 private static final ConstructingObjectParser <SparseVectorQueryBuilder , Void > PARSER = new ConstructingObjectParser <>(NAME , a -> {
0 commit comments