25
25
import org .apache .lucene .search .ConstantScoreQuery ;
26
26
import org .apache .lucene .search .TermQuery ;
27
27
import org .apache .lucene .store .Directory ;
28
- import org .apache .lucene .tests .analysis .MockAnalyzer ;
29
28
import org .apache .lucene .tests .index .RandomIndexWriter ;
30
29
import org .apache .lucene .util .BytesRef ;
31
30
import org .elasticsearch .common .lucene .search .Queries ;
@@ -137,14 +136,9 @@ protected ScriptService getMockScriptService() {
137
136
return new ScriptService (Settings .EMPTY , engines , ScriptModule .CORE_CONTEXTS , () -> 1L );
138
137
}
139
138
140
- private static RandomIndexWriter newRandomIndexWriter (Directory directory ) throws IOException {
141
- final IndexWriterConfig conf = newIndexWriterConfig (new MockAnalyzer (random ())).setMergePolicy (new LogDocMergePolicy ());
142
- return new RandomIndexWriter (random (), directory , conf );
143
- }
144
-
145
139
public void testNoDocs () throws IOException {
146
140
try (Directory directory = newDirectory ()) {
147
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
141
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
148
142
// intentionally not writing any docs
149
143
}
150
144
try (DirectoryReader indexReader = wrapInMockESDirectoryReader (DirectoryReader .open (directory ))) {
@@ -171,7 +165,7 @@ public void testSingleNestingMax() throws IOException {
171
165
int expectedNestedDocs = 0 ;
172
166
double expectedMaxValue = Double .NEGATIVE_INFINITY ;
173
167
try (Directory directory = newDirectory ()) {
174
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
168
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
175
169
for (int i = 0 ; i < numRootDocs ; i ++) {
176
170
List <Iterable <IndexableField >> documents = new ArrayList <>();
177
171
int numNestedDocs = randomIntBetween (0 , 20 );
@@ -220,7 +214,7 @@ public void testDoubleNestingMax() throws IOException {
220
214
int expectedNestedDocs = 0 ;
221
215
double expectedMaxValue = Double .NEGATIVE_INFINITY ;
222
216
try (Directory directory = newDirectory ()) {
223
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
217
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
224
218
for (int i = 0 ; i < numRootDocs ; i ++) {
225
219
List <Iterable <IndexableField >> documents = new ArrayList <>();
226
220
int numNestedDocs = randomIntBetween (0 , 20 );
@@ -270,7 +264,7 @@ public void testOrphanedDocs() throws IOException {
270
264
int expectedNestedDocs = 0 ;
271
265
double expectedSum = 0 ;
272
266
try (Directory directory = newDirectory ()) {
273
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
267
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
274
268
for (int i = 0 ; i < numRootDocs ; i ++) {
275
269
List <Iterable <IndexableField >> documents = new ArrayList <>();
276
270
int numNestedDocs = randomIntBetween (0 , 20 );
@@ -394,7 +388,7 @@ public void testResetRootDocId() throws Exception {
394
388
395
389
public void testNestedOrdering () throws IOException {
396
390
try (Directory directory = newDirectory ()) {
397
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
391
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
398
392
iw .addDocuments (generateBook ("1" , new String [] { "a" }, new int [] { 12 , 13 , 14 }));
399
393
iw .addDocuments (generateBook ("2" , new String [] { "b" }, new int [] { 5 , 50 }));
400
394
iw .addDocuments (generateBook ("3" , new String [] { "c" }, new int [] { 39 , 19 }));
@@ -521,7 +515,7 @@ public void testNestedOrdering_random() throws IOException {
521
515
books .add (Tuple .tuple (Strings .format ("%03d" , i ), chapters ));
522
516
}
523
517
try (Directory directory = newDirectory ()) {
524
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
518
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
525
519
int id = 0 ;
526
520
for (Tuple <String , int []> book : books ) {
527
521
iw .addDocuments (generateBook (Strings .format ("%03d" , id ), new String [] { book .v1 () }, book .v2 ()));
@@ -571,7 +565,7 @@ public void testNestedOrdering_random() throws IOException {
571
565
572
566
public void testPreGetChildLeafCollectors () throws IOException {
573
567
try (Directory directory = newDirectory ()) {
574
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
568
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
575
569
List <Iterable <IndexableField >> documents = new ArrayList <>();
576
570
LuceneDocument document = new LuceneDocument ();
577
571
document .add (new StringField (IdFieldMapper .NAME , Uid .encodeId ("1" ), Field .Store .NO ));
@@ -689,7 +683,7 @@ public void testFieldAlias() throws IOException {
689
683
MappedFieldType fieldType = new NumberFieldMapper .NumberFieldType (VALUE_FIELD_NAME , NumberFieldMapper .NumberType .LONG );
690
684
691
685
try (Directory directory = newDirectory ()) {
692
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
686
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
693
687
for (int i = 0 ; i < numRootDocs ; i ++) {
694
688
List <Iterable <IndexableField >> documents = new ArrayList <>();
695
689
int numNestedDocs = randomIntBetween (0 , 20 );
@@ -730,7 +724,7 @@ public void testNestedWithPipeline() throws IOException {
730
724
int expectedNestedDocs = 0 ;
731
725
double expectedMaxValue = Double .NEGATIVE_INFINITY ;
732
726
try (Directory directory = newDirectory ()) {
733
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
727
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
734
728
for (int i = 0 ; i < numRootDocs ; i ++) {
735
729
List <Iterable <IndexableField >> documents = new ArrayList <>();
736
730
expectedMaxValue = Math .max (expectedMaxValue , generateMaxDocs (documents , 1 , i , NESTED_OBJECT , VALUE_FIELD_NAME ));
@@ -796,7 +790,7 @@ public void testNestedUnderTerms() throws IOException {
796
790
)
797
791
);
798
792
try (Directory directory = newDirectory ()) {
799
- try (RandomIndexWriter iw = newRandomIndexWriter (directory )) {
793
+ try (RandomIndexWriter iw = newRandomIndexWriterWithLogDocMergePolicy (directory )) {
800
794
buildResellerData (numProducts , numResellers ).accept (iw );
801
795
}
802
796
try (DirectoryReader indexReader = wrapInMockESDirectoryReader (DirectoryReader .open (directory ))) {
0 commit comments