@@ -703,11 +703,11 @@ private void withSearchExecutionContext(MapperService mapperService, CheckedCons
703703 public void testTypeQueryFinalizationWithRandomOptions () throws Exception {
704704 for (int i = 0 ; i < 20 ; i ++) {
705705 runTestTypeQueryFinalization (
706- randomBoolean (), // usePreviousIndex
707- randomBoolean (), // useIndexOptionsDefaults
708- randomBoolean (), // explicitIndexOptionsDoNotPrune
709- randomBoolean (), // queryOverridesPruning
710- randomBoolean () // queryOverrideExplicitFalse
706+ randomBoolean (), // useIndexVersionBeforeIndexOptions
707+ randomBoolean (), // useMapperDefaultIndexOptions
708+ randomBoolean (), // setMapperIndexOptionsPruneToFalse
709+ randomBoolean (), // queryOverridesPruningConfig
710+ randomBoolean () // queryOverridesPruneToBeFalse
711711 );
712712 }
713713 }
@@ -801,61 +801,62 @@ private void assertQueryHasClauseCount(Query query, int clauseCount) {
801801 assertThat (clauses .size (), equalTo (clauseCount ));
802802 }
803803
804+ /**
805+ * Runs a test of the query finalization based on various parameters
806+ * that provides
807+ * @param useIndexVersionBeforeIndexOptions set to true to use a previous index version before mapper index_options
808+ * @param useMapperDefaultIndexOptions set to false to use an explicit, non-default mapper index_options
809+ * @param setMapperIndexOptionsPruneToFalse set to true to use prune:false in the mapper index_options
810+ * @param queryOverridesPruningConfig set to true to designate the query will provide a pruning_config
811+ * @param queryOverridesPruneToBeFalse if true and queryOverridesPruningConfig is true, the query will provide prune:false
812+ * @throws IOException
813+ */
804814 private void runTestTypeQueryFinalization (
805- boolean usePreviousIndex ,
806- boolean useIndexOptionsDefaults ,
807- boolean explicitIndexOptionsDoNotPrune ,
808- boolean queryOverridesPruning ,
809- boolean queryOverrideExplicitFalse
815+ boolean useIndexVersionBeforeIndexOptions ,
816+ boolean useMapperDefaultIndexOptions ,
817+ boolean setMapperIndexOptionsPruneToFalse ,
818+ boolean queryOverridesPruningConfig ,
819+ boolean queryOverridesPruneToBeFalse
810820 ) throws IOException {
811- // get the index version of the test to use
812- // either a current version that supports index options, or
813- // a previous version that does now
814- IndexVersion version = getIndexVersionForTest (usePreviousIndex );
815-
816- // create our mapper service
817- // if we set explicitIndexOptionsDoNotPrune, the index_options (if present)
818- // will explicitly include "prune: false"
819- MapperService mapperService = getMapperServiceForRandomizedFinalizationTest (
820- version ,
821- useIndexOptionsDefaults ,
822- explicitIndexOptionsDoNotPrune
821+ MapperService mapperService = getMapperServiceForTest (
822+ useIndexVersionBeforeIndexOptions ,
823+ useMapperDefaultIndexOptions ,
824+ setMapperIndexOptionsPruneToFalse
823825 );
824826
825827 // check and see if the query should explicitly override the index_options
826- Boolean shouldQueryPrune = queryOverridesPruning ? (queryOverrideExplicitFalse == false ) : null ;
828+ Boolean shouldQueryPrune = queryOverridesPruningConfig ? (queryOverridesPruneToBeFalse == false ) : null ;
827829
828830 // get the pruning configuration for the query if it's overriding
829- TokenPruningConfig queryPruningConfig = queryOverridesPruning && queryOverrideExplicitFalse == false
830- ? new TokenPruningConfig ()
831- : null ;
831+ TokenPruningConfig queryPruningConfig = Boolean .TRUE .equals (shouldQueryPrune ) ? new TokenPruningConfig () : null ;
832832
833833 // our logic if the results should be pruned or not
834834 // we should _not_ prune if any of the following:
835835 // - the query explicitly overrides the options and `prune` is set to false
836836 // - the query does not override the pruning options and:
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 )));
837+ // - either we are using a previous index version
838+ // - or the index_options explicitly sets `prune` to false
839+ boolean resultShouldNotBePruned = (
840+ (queryOverridesPruningConfig && queryOverridesPruneToBeFalse ) ||
841+ (queryOverridesPruningConfig == false && (useIndexVersionBeforeIndexOptions || setMapperIndexOptionsPruneToFalse ))
842+ );
841843
842844 try {
843845 performTypeQueryFinalizationTest (mapperService , shouldQueryPrune , queryPruningConfig , resultShouldNotBePruned == false );
844846 } catch (AssertionError e ) {
845847 String message = "performTypeQueryFinalizationTest failed using parameters: "
846- + "usePreviousIndex : "
847- + usePreviousIndex
848- + ", useIndexOptionsDefaults : "
849- + useIndexOptionsDefaults
850- + ", explicitIndexOptionsDoNotPrune : "
851- + explicitIndexOptionsDoNotPrune
852- + ", queryOverridesPruning : "
853- + queryOverridesPruning
854- + ", queryOverrideExplicitFalse : "
855- + queryOverrideExplicitFalse ;
848+ + "useIndexVersionBeforeIndexOptions : "
849+ + useIndexVersionBeforeIndexOptions
850+ + ", useMapperDefaultIndexOptions : "
851+ + useMapperDefaultIndexOptions
852+ + ", setMapperIndexOptionsPruneToFalse : "
853+ + setMapperIndexOptionsPruneToFalse
854+ + ", queryOverridesPruningConfig : "
855+ + queryOverridesPruningConfig
856+ + ", queryOverridesPruneToBeFalse : "
857+ + queryOverridesPruneToBeFalse ;
856858 throw new AssertionError (message , e );
857859 }
858-
859860 }
860861
861862 private IndexVersion getIndexVersionForTest (boolean usePreviousIndex ) {
@@ -868,38 +869,29 @@ private IndexVersion getIndexVersionForTest(boolean usePreviousIndex) {
868869 : IndexVersionUtils .randomVersionBetween (random (), SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT , IndexVersion .current ());
869870 }
870871
871- private SparseVectorFieldMapper . IndexOptions getIndexOptionsQueryFinalization (
872+ private MapperService getMapperServiceForTest (
872873 boolean usePreviousIndex ,
873874 boolean useIndexOptionsDefaults ,
874- boolean explicitIndexOptionsDoNotPrune
875- ) {
876- if (usePreviousIndex ) {
877- return null ;
878- }
879-
880- if (useIndexOptionsDefaults && explicitIndexOptionsDoNotPrune == false ) {
881- return null ;
882- }
883-
884- return explicitIndexOptionsDoNotPrune
885- ? new SparseVectorFieldMapper .IndexOptions (false , null )
886- : new SparseVectorFieldMapper .IndexOptions (true , new TokenPruningConfig ());
887- }
875+ boolean explicitIndexOptionsDoNotPrune ) throws IOException
876+ {
877+ // get the index version of the test to use
878+ // either a current version that supports index options, or a previous version that does not
879+ IndexVersion indexVersion = getIndexVersionForTest (usePreviousIndex );
888880
889- private MapperService getMapperServiceForRandomizedFinalizationTest (
890- IndexVersion indexVersion ,
891- boolean useIndexOptionsDefaults ,
892- boolean explicitIndexOptionsDoNotPrune
893- ) throws IOException {
894- if (useIndexOptionsDefaults && explicitIndexOptionsDoNotPrune == false ) {
881+ // if it's using the old index, we always use the minimal mapping without index_options
882+ if (usePreviousIndex ) {
895883 return createMapperService (indexVersion , fieldMapping (this ::minimalMapping ));
896884 }
897885
886+ // if we set explicitIndexOptionsDoNotPrune, the index_options (if present) will explicitly include "prune: false"
898887 if (explicitIndexOptionsDoNotPrune ) {
899888 return createMapperService (indexVersion , fieldMapping (this ::mappingWithIndexOptionsPruneFalse ));
900889 }
901890
902- return createMapperService (indexVersion , fieldMapping (this ::minimalMapping ));
891+ // either return the default (minimal) mapping or one with an explicit pruning_config
892+ return useIndexOptionsDefaults
893+ ? createMapperService (indexVersion , fieldMapping (this ::minimalMapping ))
894+ : createMapperService (indexVersion , fieldMapping (this ::minimalMappingWithExplicitIndexOptions ));
903895 }
904896
905897 private static List <WeightedToken > QUERY_VECTORS = List .of (
0 commit comments