Apache Lucene open-source search software
LUCENE-2578: cutover function query tests to RandomIndexWriter
Michael McCandless94040be77e48
diff --git a/lucene/src/test/org/apache/lucene/search/QueryUtils.java b/lucene/src/test/org/apache/lucene/search/QueryUtils.javaindex 2bbebde0ab9..6063be2301d 100644--- a/lucene/src/test/org/apache/lucene/search/QueryUtils.java+++ b/lucene/src/test/org/apache/lucene/search/QueryUtils.java@@ -378,7 +378,7 @@ public class QueryUtils {// check that first skip on just created scorers always goes to the right docprivate static void checkFirstSkipTo(final Query q, final IndexSearcher s) throws IOException {//System.out.println("checkFirstSkipTo: "+q);- final float maxDiff = 1e-5f;+ final float maxDiff = 1e-3f;final int lastDoc[] = {-1};final IndexReader lastReader[] = {null};diff --git a/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java b/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.javaindex 34a12fcb107..311039cec1a 100755--- a/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java+++ b/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java@@ -22,11 +22,13 @@ import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.Fieldable;-import org.apache.lucene.index.IndexWriter;+import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.store.Directory;import org.apache.lucene.store.RAMDirectory;import org.apache.lucene.util.LuceneTestCaseJ4;+import org.apache.lucene.util._TestUtil;+import java.util.Random;import org.junit.After;import org.junit.Before;import org.junit.Ignore;@@ -95,7 +97,12 @@ public class FunctionTestSetup extends LuceneTestCaseJ4 {// prepare a small index with just a few documents.dir = new RAMDirectory();anlzr = new MockAnalyzer();- IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, anlzr));+ Random r = newRandom();+ IndexWriterConfig iwc = newIndexWriterConfig(r, TEST_VERSION_CURRENT, anlzr);+ if (doMultiSegment) {+ iwc.setMaxBufferedDocs(_TestUtil.nextInt(r, 2, 7));+ }+ RandomIndexWriter iw = new RandomIndexWriter(r, dir, iwc);// add docs not exactly in natural ID order, to verify we do check the order of docs by scoresint remaining = N_DOCS;boolean done[] = new boolean[N_DOCS];@@ -107,15 +114,15 @@ public class FunctionTestSetup extends LuceneTestCaseJ4 {addDoc(iw, i);done[i] = true;i = (i + 4) % N_DOCS;- if (doMultiSegment && remaining % 3 == 0) {- iw.commit();- }remaining --;}+ if (!doMultiSegment) {+ iw.optimize();+ }iw.close();}- private void addDoc(IndexWriter iw, int i) throws Exception {+ private void addDoc(RandomIndexWriter iw, int i) throws Exception {Document d = new Document();Fieldable f;int scoreAndID = i + 1;