Skip to content

Commit

Permalink
Use LogDocMergePolicy in DiversifiedSamplerTests#testDiversifiedSampl…
Browse files Browse the repository at this point in the history
…er (elastic#107826)

Similar to tother cases, the addition of a new merge policy that reverse the order of the documents in lucene causes 
this test to fail in edge cases. To avoid randomisation we hardcode the merge policy to LogDocMergePolicy.
  • Loading branch information
iverase committed Apr 24, 2024
1 parent b5616f2 commit 6c46131
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LogDocMergePolicy;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.analysis.MockAnalyzer;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
Expand Down Expand Up @@ -85,7 +89,9 @@ private void writeBooks(RandomIndexWriter iw) throws IOException {

public void testDiversifiedSampler() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
IndexWriterConfig iwc = LuceneTestCase.newIndexWriterConfig(random(), new MockAnalyzer(random()));
iwc.setMergePolicy(new LogDocMergePolicy());
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory, iwc);
MappedFieldType genreFieldType = new KeywordFieldMapper.KeywordFieldType("genre");
writeBooks(indexWriter);
indexWriter.close();
Expand Down

0 comments on commit 6c46131

Please sign in to comment.