diff -r bd916a40ede0 lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java --- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java Sun Sep 12 13:22:00 2010 -0400 @@ -21,6 +21,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.TreeMap; +import java.util.HashMap; +import java.util.Map; import java.util.Comparator; import org.apache.lucene.index.DocsEnum; @@ -55,6 +57,7 @@ final private FieldInfos fieldInfos; private final SegmentInfo si; final TreeMap fields = new TreeMap(); + final Map preTerms = new HashMap(); private final Directory dir; private final int readBufferSize; private Directory cfsReader; @@ -91,6 +94,7 @@ final FieldInfo fieldInfo = fieldInfos.fieldInfo(i); if (fieldInfo.isIndexed) { fields.put(fieldInfo.name, fieldInfo); + preTerms.put(fieldInfo.name, new PreTerms(fieldInfo)); if (!fieldInfo.omitTermFreqAndPositions) { anyProx = true; } @@ -139,12 +143,7 @@ @Override public Terms terms(String field) { - FieldInfo fi = fieldInfos.fieldInfo(field); - if (fi != null) { - return new PreTerms(fi); - } else { - return null; - } + return preTerms.get(field); } synchronized private TermInfosReader getTermsDict() { diff -r bd916a40ede0 lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java --- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java Sun Sep 12 13:22:00 2010 -0400 @@ -62,13 +62,14 @@ } private static class CloneableTerm extends DoubleBarrelLRUCache.CloneableKey { - private Term term; + Term term; public CloneableTerm(Term t) { this.term = t; } public boolean equals(Object other) { - return this.term.equals(other); + CloneableTerm t = (CloneableTerm) other; + return this.term.equals(t.term); } public int hashCode() { diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java --- a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java Sun Sep 12 13:22:00 2010 -0400 @@ -20,7 +20,8 @@ import java.io.IOException; import java.util.Random; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCaseJ4; +import org.apache.lucene.util._TestUtil; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -28,8 +29,12 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; -public class BaseTestRangeFilter extends LuceneTestCase { +public class BaseTestRangeFilter extends LuceneTestCaseJ4 { public static final boolean F = false; public static final boolean T = true; @@ -40,7 +45,7 @@ * one which can't have negative random integers, for testing collated ranges, * and the other which can have negative random integers, for all other tests. */ - class TestIndex { + static class TestIndex { int maxR; int minR; boolean allowNegativeRandomInts; @@ -51,19 +56,19 @@ this.maxR = maxR; this.allowNegativeRandomInts = allowNegativeRandomInts; try { - index = newDirectory(); + index = newDirectory(random); } catch (IOException e) { throw new RuntimeException(e); } } } - IndexReader signedIndexReader; - IndexReader unsignedIndexReader; + static IndexReader signedIndexReader; + static IndexReader unsignedIndexReader; - TestIndex signedIndexDir; - TestIndex unsignedIndexDir; + static TestIndex signedIndexDir; + static TestIndex unsignedIndexDir; - int minId = 0; - int maxId = 10000; + static int minId = 0; + static int maxId = 10000; static final int intLength = Integer.toString(Integer.MAX_VALUE).length(); @@ -86,33 +91,44 @@ return b.toString(); } - - protected void setUp() throws Exception { - super.setUp(); + + @BeforeClass + public static void beforeClassBaseTestRangeFilter() throws Exception { + Random random = newStaticRandom(BaseTestRangeFilter.class); signedIndexDir = new TestIndex(random, Integer.MAX_VALUE, Integer.MIN_VALUE, true); unsignedIndexDir = new TestIndex(random, Integer.MAX_VALUE, 0, false); signedIndexReader = build(random, signedIndexDir); unsignedIndexReader = build(random, unsignedIndexDir); } - protected void tearDown() throws Exception { + @AfterClass + public static void afterClassBaseTestRangeFilter() throws Exception { signedIndexReader.close(); unsignedIndexReader.close(); signedIndexDir.index.close(); unsignedIndexDir.index.close(); - super.tearDown(); + signedIndexReader = null; + unsignedIndexReader = null; + signedIndexDir = null; + unsignedIndexDir = null; } - private IndexReader build(Random random, TestIndex index) throws IOException { + private static IndexReader build(Random random, TestIndex index) throws IOException { /* build an index */ RandomIndexWriter writer = new RandomIndexWriter(random, index.index, - newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()) - .setOpenMode(OpenMode.CREATE)); + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); + + Document doc = new Document(); + Field idField = newField(random, "id", "", Field.Store.YES, Field.Index.NOT_ANALYZED); + Field randField = newField(random, "rand", "", Field.Store.YES, Field.Index.NOT_ANALYZED); + Field bodyField = newField(random, "body", "", Field.Store.YES, Field.Index.NOT_ANALYZED); + doc.add(idField); + doc.add(randField); + doc.add(bodyField); for (int d = minId; d <= maxId; d++) { - Document doc = new Document(); - doc.add(newField("id", pad(d), Field.Store.YES, - Field.Index.NOT_ANALYZED)); + idField.setValue(pad(d)); int r = index.allowNegativeRandomInts ? random.nextInt() : random .nextInt(Integer.MAX_VALUE); if (index.maxR < r) { @@ -121,10 +137,8 @@ if (r < index.minR) { index.minR = r; } - doc.add(newField("rand", pad(r), Field.Store.YES, - Field.Index.NOT_ANALYZED)); - doc.add(newField("body", "body", Field.Store.YES, - Field.Index.NOT_ANALYZED)); + randField.setValue(pad(r)); + bodyField.setValue("body"); writer.addDocument(doc); } @@ -133,6 +147,7 @@ return ir; } + @Test public void testPad() { int[] tests = new int[] {-9999999, -99560, -100, -3, -1, 0, 3, 9, 10, 1000, diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestBoolean2.java --- a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestBoolean2.java Sun Sep 12 13:22:00 2010 -0400 @@ -31,30 +31,36 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCaseJ4; +import org.apache.lucene.util._TestUtil; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; /** Test BooleanQuery2 against BooleanQuery by overriding the standard query parser. * This also tests the scoring order of BooleanQuery. */ -public class TestBoolean2 extends LuceneTestCase { - private IndexSearcher searcher; - private IndexSearcher bigSearcher; - private IndexReader reader; +public class TestBoolean2 extends LuceneTestCaseJ4 { + private static IndexSearcher searcher; + private static IndexSearcher bigSearcher; + private static IndexReader reader; private static int NUM_EXTRA_DOCS = 6000; public static final String field = "field"; - private Directory directory; - private Directory dir2; - private int mulFactor; + private static Directory directory; + private static Directory dir2; + private static int mulFactor; - @Override - protected void setUp() throws Exception { - super.setUp(); - directory = newDirectory(); + @BeforeClass + public static void beforeClass() throws Exception { + Random random = newStaticRandom(TestBoolean2.class); + directory = newDirectory(random); RandomIndexWriter writer= new RandomIndexWriter(random, directory); for (int i = 0; i < docFields.length; i++) { Document doc = new Document(); - doc.add(newField(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED)); + doc.add(newField(random, field, docFields[i], Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(doc); } writer.close(); @@ -75,14 +81,16 @@ mulFactor *= 2; } while(docCount < 3000); - RandomIndexWriter w = new RandomIndexWriter(random, dir2); + RandomIndexWriter w = new RandomIndexWriter(random, dir2, + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); - doc.add(newField("field2", "xxx", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(newField(random, "field2", "xxx", Field.Store.NO, Field.Index.ANALYZED)); for(int i=0;i hits[1].score); q1 = csrq("data", "A", "A", T, T, MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE); // matches document #0 @@ -222,8 +235,8 @@ bq.add(q2, BooleanClause.Occur.SHOULD); hits = search.search(bq, null, 1000).scoreDocs; - assertEquals(1, hits[0].doc); - assertEquals(0, hits[1].doc); + Assert.assertEquals(1, hits[0].doc); + Assert.assertEquals(0, hits[1].doc); assertTrue(hits[0].score > hits[1].score); q1 = csrq("data", "A", "A", T, T); // matches document #0 @@ -234,11 +247,12 @@ bq.add(q2, BooleanClause.Occur.SHOULD); hits = search.search(bq, null, 1000).scoreDocs; - assertEquals(0, hits[0].doc); - assertEquals(1, hits[1].doc); + Assert.assertEquals(0, hits[0].doc); + Assert.assertEquals(1, hits[1].doc); assertTrue(hits[0].score > hits[1].score); } + @Test public void testBooleanOrderUnAffected() throws IOException { // NOTE: uses index build in *this* setUp @@ -269,6 +283,7 @@ } + @Test public void testRangeQueryId() throws IOException { // NOTE: uses index build in *super* setUp @@ -396,6 +411,7 @@ assertEquals("med,med,T,T", 1, result.length); } + @Test public void testRangeQueryIdCollating() throws IOException { // NOTE: uses index build in *super* setUp @@ -479,6 +495,7 @@ assertEquals("med,med,T,T,c", 1, result.length); } + @Test public void testRangeQueryRand() throws IOException { // NOTE: uses index build in *super* setUp @@ -541,6 +558,7 @@ } + @Test public void testRangeQueryRandCollating() throws IOException { // NOTE: uses index build in *super* setUp @@ -605,6 +623,7 @@ assertEquals("max,nul,T,T,c", 1, result.length); } + @Test public void testFarsi() throws Exception { /* build an index */ @@ -645,6 +664,7 @@ farsiIndex.close(); } + @Test public void testDanish() throws Exception { /* build an index */ diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java --- a/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java Sun Sep 12 13:22:00 2010 -0400 @@ -21,6 +21,7 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericField; @@ -28,6 +29,7 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; public class TestMultiValuedNumericRangeQuery extends LuceneTestCase { @@ -38,7 +40,9 @@ */ public void testMultiValuedNRQ() throws Exception { Directory directory = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, directory); + RandomIndexWriter writer = new RandomIndexWriter(random, directory, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); DecimalFormat format = new DecimalFormat("00000000000", new DecimalFormatSymbols(Locale.US)); diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java --- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java Sun Sep 12 13:22:00 2010 -0400 @@ -31,6 +31,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCaseJ4; import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util._TestUtil; import org.junit.Test; import org.junit.AfterClass; @@ -54,7 +55,9 @@ public static void beforeClass() throws Exception { random = newStaticRandom(TestNumericRangeQuery32.class); directory = newDirectory(random); - RandomIndexWriter writer = new RandomIndexWriter(random, directory); + RandomIndexWriter writer = new RandomIndexWriter(random, directory, + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); NumericField field8 = new NumericField("field8", 8, Field.Store.YES, true), diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java --- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java Sun Sep 12 13:22:00 2010 -0400 @@ -30,6 +30,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCaseJ4; import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util._TestUtil; import org.junit.Test; import org.junit.AfterClass; @@ -53,7 +54,9 @@ public static void beforeClass() throws Exception { random = newStaticRandom(TestNumericRangeQuery64.class); directory = newDirectory(random); - RandomIndexWriter writer = new RandomIndexWriter(random, directory); + RandomIndexWriter writer = new RandomIndexWriter(random, directory, + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); NumericField field8 = new NumericField("field8", 8, Field.Store.YES, true), diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java --- a/lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java Sun Sep 12 13:22:00 2010 -0400 @@ -27,6 +27,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; @@ -45,13 +46,18 @@ protected void setUp() throws Exception { super.setUp(); dir = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, dir, new MockAnalyzer(MockTokenizer.KEYWORD, false)); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.KEYWORD, false)) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); Field field = newField("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED); doc.add(field); - int num = 2000 * RANDOM_MULTIPLIER; + // we generate aweful prefixes: good for testing. + // but for preflex codec, the test can be very slow, so use less iterations. + String codec = CodecProvider.getDefaultCodec(); + int num = codec.equals("PreFlex") ? 200 * RANDOM_MULTIPLIER : 2000 * RANDOM_MULTIPLIER; for (int i = 0; i < num; i++) { field.setValue(_TestUtil.randomUnicodeString(random, 10)); writer.addDocument(doc); diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java --- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java Sun Sep 12 13:22:00 2010 -0400 @@ -22,6 +22,7 @@ import java.text.NumberFormat; import java.util.Locale; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; @@ -29,6 +30,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; /** * Create an index with terms from 0000-9999. @@ -44,7 +46,9 @@ protected void setUp() throws Exception { super.setUp(); dir = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, dir); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); Field field = newField("field", "", Field.Store.NO, Field.Index.ANALYZED); diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java --- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java Sun Sep 12 13:22:00 2010 -0400 @@ -30,6 +30,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; @@ -53,7 +54,9 @@ protected void setUp() throws Exception { super.setUp(); dir = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, dir, new MockAnalyzer(MockTokenizer.KEYWORD, false)); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.KEYWORD, false)) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); Field field = newField("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED); @@ -129,8 +132,10 @@ /** test a bunch of random regular expressions */ public void testRegexps() throws Exception { - - int num = 1000 * RANDOM_MULTIPLIER; + // we generate aweful regexps: good for testing. + // but for preflex codec, the test can be very slow, so use less iterations. + String codec = CodecProvider.getDefaultCodec(); + int num = codec.equals("PreFlex") ? 100 * RANDOM_MULTIPLIER : 1000 * RANDOM_MULTIPLIER; for (int i = 0; i < num; i++) { String reg = AutomatonTestUtil.randomRegexp(random).toString(); assertSame(reg); diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.java --- a/lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.java Sun Sep 12 13:22:00 2010 -0400 @@ -27,6 +27,9 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.store.Directory; +import org.junit.Test; + +import static org.junit.Assert.*; /** * A basic 'positive' Unit test class for the TermRangeFilter class. @@ -39,6 +42,7 @@ */ public class TestTermRangeFilter extends BaseTestRangeFilter { + @Test public void testRangeFilterId() throws IOException { IndexReader reader = signedIndexReader; @@ -141,6 +145,7 @@ } + @Test public void testRangeFilterIdCollating() throws IOException { IndexReader reader = signedIndexReader; @@ -242,6 +247,7 @@ assertEquals("med,med,T,T", 1, numHits); } + @Test public void testRangeFilterRand() throws IOException { IndexReader reader = signedIndexReader; @@ -318,6 +324,7 @@ } + @Test public void testRangeFilterRandCollating() throws IOException { // using the unsigned index because collation seems to ignore hyphens @@ -395,6 +402,7 @@ assertEquals("max,nul,T,T", 1, numHits); } + @Test public void testFarsi() throws Exception { /* build an index */ @@ -435,6 +443,7 @@ farsiIndex.close(); } + @Test public void testDanish() throws Exception { /* build an index */ diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java --- a/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java Sun Sep 12 13:22:00 2010 -0400 @@ -22,6 +22,7 @@ import java.text.NumberFormat; import java.util.Locale; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; @@ -29,6 +30,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; /** * Create an index with terms from 0000-9999. @@ -44,7 +46,9 @@ protected void setUp() throws Exception { super.setUp(); dir = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, dir); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); Field field = newField("field", "", Field.Store.NO, Field.Index.ANALYZED); diff -r bd916a40ede0 lucene/src/test/org/apache/lucene/search/spans/TestBasics.java --- a/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java Sun Sep 12 12:41:46 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java Sun Sep 12 13:22:00 2010 -0400 @@ -18,6 +18,7 @@ */ import java.io.IOException; +import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -37,7 +38,13 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.util.English; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCaseJ4; +import org.apache.lucene.util._TestUtil; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; /** * Tests basic search capabilities. @@ -51,21 +58,22 @@ * testing of the indexing and search code. * */ -public class TestBasics extends LuceneTestCase { - private IndexSearcher searcher; - private IndexReader reader; - private Directory directory; +public class TestBasics extends LuceneTestCaseJ4 { + private static IndexSearcher searcher; + private static IndexReader reader; + private static Directory directory; - @Override - protected void setUp() throws Exception { - super.setUp(); - directory = newDirectory(); + @BeforeClass + public static void beforeClass() throws Exception { + Random random = newStaticRandom(TestBasics.class); + directory = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, directory, - new MockAnalyzer(MockTokenizer.SIMPLE, true)); + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); //writer.infoStream = System.out; for (int i = 0; i < 1000; i++) { Document doc = new Document(); - doc.add(newField("field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED)); + doc.add(newField(random, "field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc); } reader = writer.getReader(); @@ -73,15 +81,17 @@ writer.close(); } - @Override - protected void tearDown() throws Exception { + @AfterClass + public static void afterClass() throws Exception { searcher.close(); reader.close(); directory.close(); - super.tearDown(); + searcher = null; + reader = null; + directory = null; } - + @Test public void testTerm() throws Exception { Query query = new TermQuery(new Term("field", "seventy")); checkHits(query, new int[] @@ -94,11 +104,13 @@ 876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979}); } + @Test public void testTerm2() throws Exception { Query query = new TermQuery(new Term("field", "seventish")); checkHits(query, new int[] {}); } + @Test public void testPhrase() throws Exception { PhraseQuery query = new PhraseQuery(); query.add(new Term("field", "seventy")); @@ -107,6 +119,7 @@ {77, 177, 277, 377, 477, 577, 677, 777, 877, 977}); } + @Test public void testPhrase2() throws Exception { PhraseQuery query = new PhraseQuery(); query.add(new Term("field", "seventish")); @@ -114,6 +127,7 @@ checkHits(query, new int[] {}); } + @Test public void testBoolean() throws Exception { BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term("field", "seventy")), BooleanClause.Occur.MUST); @@ -123,6 +137,7 @@ 776, 778, 779, 877, 977}); } + @Test public void testBoolean2() throws Exception { BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term("field", "sevento")), BooleanClause.Occur.MUST); @@ -130,6 +145,7 @@ checkHits(query, new int[] {}); } + @Test public void testSpanNearExact() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "seven")); @@ -146,6 +162,7 @@ QueryUtils.checkUnequal(term1,term2); } + @Test public void testSpanNearUnordered() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "nine")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "six")); @@ -157,6 +174,7 @@ 906, 926, 936, 946, 956, 966, 976, 986, 996}); } + @Test public void testSpanNearOrdered() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "nine")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "six")); @@ -166,6 +184,7 @@ {906, 926, 936, 946, 956, 966, 976, 986, 996}); } + @Test public void testSpanNot() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -181,6 +200,7 @@ assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } + @Test public void testSpanWithMultipleNotSingle() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -199,6 +219,7 @@ assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } + @Test public void testSpanWithMultipleNotMany() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -218,7 +239,8 @@ assertTrue(searcher.explain(query, 801).getValue() > 0.0f); assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } - + + @Test public void testNpeInSpanNearWithSpanNot() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -238,7 +260,7 @@ assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } - + @Test public void testNpeInSpanNearInSpanFirstInSpanNot() throws Exception { int n = 5; SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred")); @@ -255,6 +277,7 @@ } + @Test public void testSpanFirst() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "five")); SpanFirstQuery query = new SpanFirstQuery(term1, 1); @@ -274,6 +297,7 @@ } + @Test public void testSpanOr() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "thirty")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "three")); @@ -294,6 +318,7 @@ assertTrue(searcher.explain(query, 947).getValue() > 0.0f); } + @Test public void testSpanExactNested() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "three")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "hundred")); @@ -312,6 +337,7 @@ assertTrue(searcher.explain(query, 333).getValue() > 0.0f); } + @Test public void testSpanNearOr() throws Exception { SpanTermQuery t1 = new SpanTermQuery(new Term("field","six")); @@ -333,6 +359,7 @@ 756, 757, 766, 767, 776, 777, 786, 787, 796, 797}); } + @Test public void testSpanComplex1() throws Exception { SpanTermQuery t1 = new SpanTermQuery(new Term("field","six")); @@ -359,6 +386,7 @@ 756, 757, 766, 767, 776, 777, 786, 787, 796, 797}); } + @Test public void testSpansSkipTo() throws Exception { SpanTermQuery t1 = new SpanTermQuery(new Term("field", "seventy")); SpanTermQuery t2 = new SpanTermQuery(new Term("field", "seventy"));