2323import org .elasticsearch .common .Strings ;
2424import org .elasticsearch .common .compress .CompressedXContent ;
2525import org .elasticsearch .core .CheckedConsumer ;
26- import org .elasticsearch .core .CheckedRunnable ;
27- import org .elasticsearch .core .CheckedSupplier ;
2826import org .elasticsearch .core .Nullable ;
2927import org .elasticsearch .index .IndexVersion ;
3028import org .elasticsearch .index .IndexVersions ;
4947import java .io .IOException ;
5048import java .util .Arrays ;
5149import java .util .Collection ;
52- import java .util .Collections ;
5350import java .util .LinkedHashMap ;
5451import java .util .List ;
5552import java .util .Map ;
56- import java .util .Optional ;
5753
5854import static org .elasticsearch .index .IndexVersions .SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT ;
5955import static org .elasticsearch .index .IndexVersions .UPGRADE_TO_LUCENE_10_0_0 ;
@@ -92,7 +88,7 @@ protected void minimalFieldMappingPreviousIndexVersion(XContentBuilder b) throws
9288 b .startObject ("meta" );
9389 b .endObject ();
9490
95- b .field ("index_options" , (Object )null );
91+ b .field ("index_options" , (Object ) null );
9692 }
9793
9894 protected void minimalMappingWithExplicitDefaults (XContentBuilder b ) throws IOException {
@@ -230,7 +226,8 @@ public void testDefaults() throws Exception {
230226 assertTrue (freq1 < freq2 );
231227 }
232228
233- private void buildDocForSparseVectorFieldMapping (XContentBuilder b , CheckedConsumer <XContentBuilder , IOException > supplier ) throws IOException {
229+ private void buildDocForSparseVectorFieldMapping (XContentBuilder b , CheckedConsumer <XContentBuilder , IOException > supplier )
230+ throws IOException {
234231 b .startObject ("_doc" );
235232 {
236233 b .startArray ("dynamic_date_formats" );
@@ -740,12 +737,7 @@ public void testTypeQueryFinalizationWithIndexExplicit() throws Exception {
740737 MapperService mapperService = createMapperService (version , fieldMapping (this ::minimalMapping ));
741738
742739 // query should be pruned via explicit index options
743- performTypeQueryFinalizationTest (
744- mapperService ,
745- null ,
746- null ,
747- true
748- );
740+ performTypeQueryFinalizationTest (mapperService , null , null , true );
749741 }
750742
751743 public void testTypeQueryFinalizationWithIndexExplicitDoNotPrune () throws Exception {
@@ -761,25 +753,15 @@ public void testTypeQueryFinalizationQueryOverridesPruning() throws Exception {
761753 MapperService mapperService = createMapperService (version , fieldMapping (this ::mappingWithIndexOptionsPruneFalse ));
762754
763755 // query should still be pruned due to query builder setting it
764- performTypeQueryFinalizationTest (
765- mapperService ,
766- true ,
767- new TokenPruningConfig (),
768- true
769- );
756+ performTypeQueryFinalizationTest (mapperService , true , new TokenPruningConfig (), true );
770757 }
771758
772759 public void testTypeQueryFinalizationQueryOverridesPruningOff () throws Exception {
773760 IndexVersion version = IndexVersion .current ();
774761 MapperService mapperService = createMapperService (version , fieldMapping (this ::mappingWithIndexOptionsPruneFalse ));
775762
776763 // query should not pruned due to query builder setting it
777- performTypeQueryFinalizationTest (
778- mapperService ,
779- false ,
780- null ,
781- false
782- );
764+ performTypeQueryFinalizationTest (mapperService , false , null , false );
783765 }
784766
785767 private void performTypeQueryFinalizationTest (
@@ -789,8 +771,9 @@ private void performTypeQueryFinalizationTest(
789771 boolean queryShouldBePruned
790772 ) throws IOException {
791773 withSearchExecutionContext (mapperService , (context ) -> {
792- SparseVectorFieldMapper .SparseVectorFieldType ft = (SparseVectorFieldMapper .SparseVectorFieldType ) mapperService
793- .fieldType ("field" );
774+ SparseVectorFieldMapper .SparseVectorFieldType ft = (SparseVectorFieldMapper .SparseVectorFieldType ) mapperService .fieldType (
775+ "field"
776+ );
794777 Query finalizedQuery = ft .finalizeSparseVectorQuery (context , "field" , QUERY_VECTORS , queryPrune , queryTokenPruningConfig );
795778
796779 if (queryShouldBePruned ) {
@@ -851,20 +834,13 @@ private void runTestTypeQueryFinalization(
851834 // we should _not_ prune if any of the following:
852835 // - the query explicitly overrides the options and `prune` is set to false
853836 // - the query does not override the pruning options and:
854- // - either we are using a previous index version
855- // - or the index_options explicitly sets `prune` to false
856- boolean resultShouldNotBePruned = (
857- (queryOverridesPruning && queryOverrideExplicitFalse ) ||
858- (queryOverridesPruning == false && (usePreviousIndex || explicitIndexOptionsDoNotPrune ))
859- );
837+ // - either we are using a previous index version
838+ // - or the index_options explicitly sets `prune` to false
839+ boolean resultShouldNotBePruned = ((queryOverridesPruning && queryOverrideExplicitFalse )
840+ || (queryOverridesPruning == false && (usePreviousIndex || explicitIndexOptionsDoNotPrune )));
860841
861842 try {
862- performTypeQueryFinalizationTest (
863- mapperService ,
864- shouldQueryPrune ,
865- queryPruningConfig ,
866- resultShouldNotBePruned == false
867- );
843+ performTypeQueryFinalizationTest (mapperService , shouldQueryPrune , queryPruningConfig , resultShouldNotBePruned == false );
868844 } catch (AssertionError e ) {
869845 String message = "performTypeQueryFinalizationTest failed using parameters: "
870846 + "usePreviousIndex: "
@@ -884,16 +860,12 @@ private void runTestTypeQueryFinalization(
884860
885861 private IndexVersion getIndexVersionForTest (boolean usePreviousIndex ) {
886862 return usePreviousIndex
887- ? IndexVersionUtils .randomVersionBetween (
888- random (),
889- UPGRADE_TO_LUCENE_10_0_0 ,
890- IndexVersionUtils .getPreviousVersion (SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT )
891- )
892- : IndexVersionUtils .randomVersionBetween (
893- random (),
894- SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT ,
895- IndexVersion .current ()
896- );
863+ ? IndexVersionUtils .randomVersionBetween (
864+ random (),
865+ UPGRADE_TO_LUCENE_10_0_0 ,
866+ IndexVersionUtils .getPreviousVersion (SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT )
867+ )
868+ : IndexVersionUtils .randomVersionBetween (random (), SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT , IndexVersion .current ());
897869 }
898870
899871 private SparseVectorFieldMapper .IndexOptions getIndexOptionsQueryFinalization (
0 commit comments