@@ -49,26 +49,14 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
49
49
50
50
@ Override
51
51
protected IntervalQueryBuilder doCreateTestQueryBuilder () {
52
- return new IntervalQueryBuilder (STRING_FIELD_NAME , createRandomSource ());
53
- }
54
-
55
- @ Override
56
- public void testUnknownField () throws IOException {
57
- super .testUnknownField ();
52
+ return new IntervalQueryBuilder (STRING_FIELD_NAME , createRandomSource (0 ));
58
53
}
59
54
60
55
private static final String [] filters = new String []{
61
56
"containing" , "contained_by" , "not_containing" , "not_contained_by" ,
62
57
"overlapping" , "not_overlapping" , "before" , "after"
63
58
};
64
59
65
- private IntervalsSourceProvider .IntervalFilter createRandomFilter () {
66
- if (randomInt (20 ) > 18 ) {
67
- return new IntervalsSourceProvider .IntervalFilter (createRandomSource (), randomFrom (filters ));
68
- }
69
- return null ;
70
- }
71
-
72
60
private static final String MASKED_FIELD = "masked_field" ;
73
61
private static final String NO_POSITIONS_FIELD = "no_positions_field" ;
74
62
@@ -88,42 +76,56 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
88
76
new CompressedXContent (Strings .toString (mapping )), MapperService .MergeReason .MAPPING_UPDATE );
89
77
}
90
78
91
- private IntervalsSourceProvider createRandomSource () {
92
- String useField = rarely () ? MASKED_FIELD : null ;
79
+ private IntervalsSourceProvider createRandomSource (int depth ) {
80
+ if (depth > 3 ) {
81
+ return createRandomMatch (depth + 1 );
82
+ }
93
83
switch (randomInt (20 )) {
94
84
case 0 :
95
85
case 1 :
96
86
int orCount = randomInt (4 ) + 1 ;
97
87
List <IntervalsSourceProvider > orSources = new ArrayList <>();
98
88
for (int i = 0 ; i < orCount ; i ++) {
99
- orSources .add (createRandomSource ());
89
+ orSources .add (createRandomSource (depth + 1 ));
100
90
}
101
- return new IntervalsSourceProvider .Disjunction (orSources , createRandomFilter ());
91
+ return new IntervalsSourceProvider .Disjunction (orSources , createRandomFilter (depth + 1 ));
102
92
case 2 :
103
93
case 3 :
104
94
int count = randomInt (5 ) + 1 ;
105
95
List <IntervalsSourceProvider > subSources = new ArrayList <>();
106
96
for (int i = 0 ; i < count ; i ++) {
107
- subSources .add (createRandomSource ());
97
+ subSources .add (createRandomSource (depth + 1 ));
108
98
}
109
99
boolean ordered = randomBoolean ();
110
100
int maxGaps = randomInt (5 ) - 1 ;
111
- IntervalsSourceProvider .IntervalFilter filter = createRandomFilter ();
101
+ IntervalsSourceProvider .IntervalFilter filter = createRandomFilter (depth + 1 );
112
102
return new IntervalsSourceProvider .Combine (subSources , ordered , maxGaps , filter );
113
103
default :
114
- int wordCount = randomInt (4 ) + 1 ;
115
- List <String > words = new ArrayList <>();
116
- for (int i = 0 ; i < wordCount ; i ++) {
117
- words .add (randomRealisticUnicodeOfLengthBetween (4 , 20 ));
118
- }
119
- String text = String .join (" " , words );
120
- boolean mOrdered = randomBoolean ();
121
- int maxMGaps = randomInt (5 ) - 1 ;
122
- String analyzer = randomFrom ("simple" , "keyword" , "whitespace" );
123
- return new IntervalsSourceProvider .Match (text , maxMGaps , mOrdered , analyzer , createRandomFilter (), useField );
104
+ return createRandomMatch (depth + 1 );
124
105
}
125
106
}
126
107
108
+ private IntervalsSourceProvider .IntervalFilter createRandomFilter (int depth ) {
109
+ if (depth < 3 && randomInt (20 ) > 18 ) {
110
+ return new IntervalsSourceProvider .IntervalFilter (createRandomSource (depth + 1 ), randomFrom (filters ));
111
+ }
112
+ return null ;
113
+ }
114
+
115
+ private IntervalsSourceProvider createRandomMatch (int depth ) {
116
+ String useField = rarely () ? MASKED_FIELD : null ;
117
+ int wordCount = randomInt (4 ) + 1 ;
118
+ List <String > words = new ArrayList <>();
119
+ for (int i = 0 ; i < wordCount ; i ++) {
120
+ words .add (randomRealisticUnicodeOfLengthBetween (4 , 20 ));
121
+ }
122
+ String text = String .join (" " , words );
123
+ boolean mOrdered = randomBoolean ();
124
+ int maxMGaps = randomInt (5 ) - 1 ;
125
+ String analyzer = randomFrom ("simple" , "keyword" , "whitespace" );
126
+ return new IntervalsSourceProvider .Match (text , maxMGaps , mOrdered , analyzer , createRandomFilter (depth + 1 ), useField );
127
+ }
128
+
127
129
@ Override
128
130
protected void doAssertLuceneQuery (IntervalQueryBuilder queryBuilder , Query query , SearchContext context ) throws IOException {
129
131
assertThat (query , instanceOf (IntervalQuery .class ));
@@ -382,6 +384,5 @@ public <FactoryType> FactoryType compile(Script script, ScriptContext<FactoryTyp
382
384
assertEquals (expected , q );
383
385
384
386
}
385
-
386
-
387
+
387
388
}
0 commit comments