lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r966819 [12/20] - in /lucene/dev/branches/realtime_search: ./ lucene/ lucene/backwards/ lucene/contrib/ lucene/contrib/benchmark/conf/ lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ lucene/contrib/benchmark/src/...
Date Thu, 22 Jul 2010 19:34:52 GMT
Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java Thu Jul 22 19:34:35 2010
@@ -20,12 +20,15 @@ package org.apache.lucene.search;
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Random;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
@@ -55,6 +58,13 @@ import org.apache.lucene.util.LuceneTest
 public class TestFuzzyQuery2 extends LuceneTestCase {
   /** epsilon for score comparisons */
   static final float epsilon = 0.00001f;
+  private Random random;
+  
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    random = newRandom();
+  }
 
   public void testFromTestData() throws Exception {
     // TODO: randomize!
@@ -78,8 +88,8 @@ public class TestFuzzyQuery2 extends Luc
     int terms = (int) Math.pow(2, bits);
     
     RAMDirectory dir = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new MockAnalyzer(MockTokenizer.KEYWORD, false),
-        IndexWriter.MaxFieldLength.UNLIMITED);
+    RandomIndexWriter writer = new RandomIndexWriter(random, dir, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.KEYWORD, false)));
     
     Document doc = new Document();
     Field field = new Field("field", "", Field.Store.NO, Field.Index.ANALYZED);
@@ -88,12 +98,11 @@ public class TestFuzzyQuery2 extends Luc
     for (int i = 0; i < terms; i++) {
       field.setValue(mapInt(codePointTable, i));
       writer.addDocument(doc);
-    }
+    }   
     
-    writer.optimize();
-    writer.close();   
-    
-    IndexSearcher searcher = new IndexSearcher(dir);
+    IndexReader r = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(r);
+    writer.close();
     String line;
     while ((line = reader.readLine()) != null) {
       String params[] = line.split(",");
@@ -113,6 +122,7 @@ public class TestFuzzyQuery2 extends Luc
       }
     }
     searcher.close();
+    r.close();
     dir.close();
   }
   

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java Thu Jul 22 19:34:35 2010
@@ -18,234 +18,263 @@ package org.apache.lucene.search;
  */
 
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermEnum;
+import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.MultiFields;
+import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.Version;
 
 import java.io.IOException;
-import java.util.HashSet;
 import java.util.LinkedList;
-import java.util.Collections;
 
 /**
  * This class tests the MultiPhraseQuery class.
- *
- *
+ * 
+ * 
  */
-public class TestMultiPhraseQuery extends LuceneTestCase
-{
-    public TestMultiPhraseQuery(String name) {
-        super(name);
-    }
-
-    public void testPhrasePrefix() throws IOException {
-        MockRAMDirectory indexStore = new MockRAMDirectory();
-        IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
-        add("blueberry pie", writer);
-        add("blueberry strudel", writer);
-        add("blueberry pizza", writer);
-        add("blueberry chewing gum", writer);
-        add("bluebird pizza", writer);
-        add("bluebird foobar pizza", writer);
-        add("piccadilly circus", writer);
-        writer.optimize();
-        writer.close();
-
-        IndexSearcher searcher = new IndexSearcher(indexStore, true);
-
-        // search for "blueberry pi*":
-        MultiPhraseQuery query1 = new MultiPhraseQuery();
-        // search for "strawberry pi*":
-        MultiPhraseQuery query2 = new MultiPhraseQuery();
-        query1.add(new Term("body", "blueberry"));
-        query2.add(new Term("body", "strawberry"));
-
-        LinkedList<Term> termsWithPrefix = new LinkedList<Term>();
-        IndexReader ir = IndexReader.open(indexStore, true);
-
-        // this TermEnum gives "piccadilly", "pie" and "pizza".
-        String prefix = "pi";
-        TermEnum te = ir.terms(new Term("body", prefix));
-        do {
-            if (te.term().text().startsWith(prefix))
-            {
-                termsWithPrefix.add(te.term());
-            }
-        } while (te.next());
-
-        query1.add(termsWithPrefix.toArray(new Term[0]));
-        assertEquals("body:\"blueberry (piccadilly pie pizza)\"", query1.toString());
-        query2.add(termsWithPrefix.toArray(new Term[0]));
-        assertEquals("body:\"strawberry (piccadilly pie pizza)\"", query2.toString());
-
-        ScoreDoc[] result;
-        result = searcher.search(query1, null, 1000).scoreDocs;
-        assertEquals(2, result.length);
-        result = searcher.search(query2, null, 1000).scoreDocs;
-        assertEquals(0, result.length);
-
-        // search for "blue* pizza":
-        MultiPhraseQuery query3 = new MultiPhraseQuery();
-        termsWithPrefix.clear();
-        prefix = "blue";
-        te = ir.terms(new Term("body", prefix));
-        do {
-            if (te.term().text().startsWith(prefix))
-            {
-                termsWithPrefix.add(te.term());
-            }
-        } while (te.next());
-        ir.close();
-        query3.add(termsWithPrefix.toArray(new Term[0]));
-        query3.add(new Term("body", "pizza"));
-
-        result = searcher.search(query3, null, 1000).scoreDocs;
-        assertEquals(2, result.length); // blueberry pizza, bluebird pizza
-        assertEquals("body:\"(blueberry bluebird) pizza\"", query3.toString());
-
-        // test slop:
-        query3.setSlop(1);
-        result = searcher.search(query3, null, 1000).scoreDocs;
-        assertEquals(3, result.length); // blueberry pizza, bluebird pizza, bluebird foobar pizza
-
-        MultiPhraseQuery query4 = new MultiPhraseQuery();
-        try {
-          query4.add(new Term("field1", "foo"));
-          query4.add(new Term("field2", "foobar"));
-          fail();
-        } catch(IllegalArgumentException e) {
-          // okay, all terms must belong to the same field
-        }
-        
-        searcher.close();
-        indexStore.close();
-
-    }
+public class TestMultiPhraseQuery extends LuceneTestCase {
+  public TestMultiPhraseQuery(String name) {
+    super(name);
+  }
+  
+  public void testPhrasePrefix() throws IOException {
+    MockRAMDirectory indexStore = new MockRAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    add("blueberry pie", writer);
+    add("blueberry strudel", writer);
+    add("blueberry pizza", writer);
+    add("blueberry chewing gum", writer);
+    add("bluebird pizza", writer);
+    add("bluebird foobar pizza", writer);
+    add("piccadilly circus", writer);
+    
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
+    
+    // search for "blueberry pi*":
+    MultiPhraseQuery query1 = new MultiPhraseQuery();
+    // search for "strawberry pi*":
+    MultiPhraseQuery query2 = new MultiPhraseQuery();
+    query1.add(new Term("body", "blueberry"));
+    query2.add(new Term("body", "strawberry"));
+    
+    LinkedList<Term> termsWithPrefix = new LinkedList<Term>();
     
-    private void add(String s, IndexWriter writer) throws IOException {
-      Document doc = new Document();
-      doc.add(new Field("body", s, Field.Store.YES, Field.Index.ANALYZED));
-      writer.addDocument(doc);
+    // this TermEnum gives "piccadilly", "pie" and "pizza".
+    String prefix = "pi";
+    TermsEnum te = MultiFields.getFields(reader).terms("body").iterator();
+    te.seek(new BytesRef(prefix));
+    do {
+      String s = te.term().utf8ToString();
+      if (s.startsWith(prefix)) {
+        termsWithPrefix.add(new Term("body", s));
+      } else {
+        break;
+      }
+    } while (te.next() != null);
+    
+    query1.add(termsWithPrefix.toArray(new Term[0]));
+    assertEquals("body:\"blueberry (piccadilly pie pizza)\"", query1.toString());
+    query2.add(termsWithPrefix.toArray(new Term[0]));
+    assertEquals("body:\"strawberry (piccadilly pie pizza)\"", query2
+        .toString());
+    
+    ScoreDoc[] result;
+    result = searcher.search(query1, null, 1000).scoreDocs;
+    assertEquals(2, result.length);
+    result = searcher.search(query2, null, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    // search for "blue* pizza":
+    MultiPhraseQuery query3 = new MultiPhraseQuery();
+    termsWithPrefix.clear();
+    prefix = "blue";
+    te.seek(new BytesRef(prefix));
+    
+    do {
+      if (te.term().utf8ToString().startsWith(prefix)) {
+        termsWithPrefix.add(new Term("body", te.term().utf8ToString()));
+      }
+    } while (te.next() != null);
+    
+    query3.add(termsWithPrefix.toArray(new Term[0]));
+    query3.add(new Term("body", "pizza"));
+    
+    result = searcher.search(query3, null, 1000).scoreDocs;
+    assertEquals(2, result.length); // blueberry pizza, bluebird pizza
+    assertEquals("body:\"(blueberry bluebird) pizza\"", query3.toString());
+    
+    // test slop:
+    query3.setSlop(1);
+    result = searcher.search(query3, null, 1000).scoreDocs;
+    
+    // just make sure no exc:
+    searcher.explain(query3, 0);
+    
+    assertEquals(3, result.length); // blueberry pizza, bluebird pizza, bluebird
+                                    // foobar pizza
+    
+    MultiPhraseQuery query4 = new MultiPhraseQuery();
+    try {
+      query4.add(new Term("field1", "foo"));
+      query4.add(new Term("field2", "foobar"));
+      fail();
+    } catch (IllegalArgumentException e) {
+      // okay, all terms must belong to the same field
     }
     
-    public void testBooleanQueryContainingSingleTermPrefixQuery() throws IOException {
-      // this tests against bug 33161 (now fixed)
-      // In order to cause the bug, the outer query must have more than one term 
-      // and all terms required.
-      // The contained PhraseMultiQuery must contain exactly one term array.
-
-      MockRAMDirectory indexStore = new MockRAMDirectory();
-      IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
-      add("blueberry pie", writer);
-      add("blueberry chewing gum", writer);
-      add("blue raspberry pie", writer);
-      writer.optimize();
-      writer.close();
-
-      IndexSearcher searcher = new IndexSearcher(indexStore, true);
-      // This query will be equivalent to +body:pie +body:"blue*"
-      BooleanQuery q = new BooleanQuery();
-      q.add(new TermQuery(new Term("body", "pie")), BooleanClause.Occur.MUST);
-
-      MultiPhraseQuery trouble = new MultiPhraseQuery();
-      trouble.add(new Term[] {
-          new Term("body", "blueberry"),
-          new Term("body", "blue")
-      });
-      q.add(trouble, BooleanClause.Occur.MUST);
-
-      // exception will be thrown here without fix
-      ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
-
-      assertEquals("Wrong number of hits", 2, hits.length);
-      searcher.close();
-      indexStore.close();
+    writer.close();
+    searcher.close();
+    reader.close();
+    indexStore.close();
+    
   }
+  
+  private void add(String s, RandomIndexWriter writer) throws IOException {
+    Document doc = new Document();
+    doc.add(new Field("body", s, Field.Store.YES, Field.Index.ANALYZED));
+    writer.addDocument(doc);
+  }
+  
+  public void testBooleanQueryContainingSingleTermPrefixQuery()
+      throws IOException {
+    // this tests against bug 33161 (now fixed)
+    // In order to cause the bug, the outer query must have more than one term
+    // and all terms required.
+    // The contained PhraseMultiQuery must contain exactly one term array.
     
+    MockRAMDirectory indexStore = new MockRAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    add("blueberry pie", writer);
+    add("blueberry chewing gum", writer);
+    add("blue raspberry pie", writer);
+    
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
+    // This query will be equivalent to +body:pie +body:"blue*"
+    BooleanQuery q = new BooleanQuery();
+    q.add(new TermQuery(new Term("body", "pie")), BooleanClause.Occur.MUST);
+    
+    MultiPhraseQuery trouble = new MultiPhraseQuery();
+    trouble.add(new Term[] {new Term("body", "blueberry"),
+        new Term("body", "blue")});
+    q.add(trouble, BooleanClause.Occur.MUST);
+    
+    // exception will be thrown here without fix
+    ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
+    
+    assertEquals("Wrong number of hits", 2, hits.length);
+    
+    // just make sure no exc:
+    searcher.explain(q, 0);
+    
+    writer.close();
+    searcher.close();
+    reader.close();
+    indexStore.close();
+  }
+  
   public void testPhrasePrefixWithBooleanQuery() throws IOException {
     MockRAMDirectory indexStore = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     add("This is a test", "object", writer);
     add("a note", "note", writer);
-    writer.close();
     
-    IndexSearcher searcher = new IndexSearcher(indexStore, true);
-
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
+    
     // This query will be equivalent to +type:note +body:"a t*"
     BooleanQuery q = new BooleanQuery();
     q.add(new TermQuery(new Term("type", "note")), BooleanClause.Occur.MUST);
-
+    
     MultiPhraseQuery trouble = new MultiPhraseQuery();
     trouble.add(new Term("body", "a"));
-    trouble.add(new Term[] { new Term("body", "test"), new Term("body", "this") });
+    trouble
+        .add(new Term[] {new Term("body", "test"), new Term("body", "this")});
     q.add(trouble, BooleanClause.Occur.MUST);
-
+    
     // exception will be thrown here without fix for #35626:
     ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
     assertEquals("Wrong number of hits", 0, hits.length);
+    writer.close();
     searcher.close();
+    reader.close();
     indexStore.close();
   }
-
+  
   public void testNoDocs() throws Exception {
     MockRAMDirectory indexStore = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(indexStore, new MockAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     add("a note", "note", writer);
-    writer.close();
-
-    IndexSearcher searcher = new IndexSearcher(indexStore, true);
-
+    
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
+    
     MultiPhraseQuery q = new MultiPhraseQuery();
     q.add(new Term("body", "a"));
-    q.add(new Term[] { new Term("body", "nope"), new Term("body", "nope") });
-    assertEquals("Wrong number of hits", 0, searcher.search(q, null, 1).totalHits);
+    q.add(new Term[] {new Term("body", "nope"), new Term("body", "nope")});
+    assertEquals("Wrong number of hits", 0,
+        searcher.search(q, null, 1).totalHits);
+    
+    // just make sure no exc:
+    searcher.explain(q, 0);
+    
+    writer.close();
     searcher.close();
+    reader.close();
     indexStore.close();
   }
   
-  public void testHashCodeAndEquals(){
+  public void testHashCodeAndEquals() {
     MultiPhraseQuery query1 = new MultiPhraseQuery();
     MultiPhraseQuery query2 = new MultiPhraseQuery();
     
     assertEquals(query1.hashCode(), query2.hashCode());
-    assertEquals(query1,query2);
+    assertEquals(query1, query2);
     
-    Term term1= new Term("someField","someText");
+    Term term1 = new Term("someField", "someText");
     
     query1.add(term1);
     query2.add(term1);
     
     assertEquals(query1.hashCode(), query2.hashCode());
-    assertEquals(query1,query2);
+    assertEquals(query1, query2);
     
-    Term term2= new Term("someField","someMoreText");
+    Term term2 = new Term("someField", "someMoreText");
     
     query1.add(term2);
     
-    assertFalse(query1.hashCode()==query2.hashCode());
+    assertFalse(query1.hashCode() == query2.hashCode());
     assertFalse(query1.equals(query2));
     
     query2.add(term2);
     
     assertEquals(query1.hashCode(), query2.hashCode());
-    assertEquals(query1,query2);
+    assertEquals(query1, query2);
   }
-
   
-  private void add(String s, String type, IndexWriter writer) throws IOException {
+  private void add(String s, String type, RandomIndexWriter writer)
+      throws IOException {
     Document doc = new Document();
     doc.add(new Field("body", s, Field.Store.YES, Field.Index.ANALYZED));
     doc.add(new Field("type", type, Field.Store.YES, Field.Index.NOT_ANALYZED));
     writer.addDocument(doc);
   }
-
+  
+  // LUCENE-2526
+  public void testEmptyToString() {
+    new MultiPhraseQuery().toString();
+  }
+  
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java Thu Jul 22 19:34:35 2010
@@ -22,8 +22,8 @@ import org.apache.lucene.analysis.MockTo
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
@@ -38,15 +38,8 @@ public class TestMultiTermConstantScore 
   /** threshold for comparing floats */
   public static final float SCORE_COMP_THRESH = 1e-6f;
 
-  public TestMultiTermConstantScore(String name) {
-    super(name);
-  }
-
-  public TestMultiTermConstantScore() {
-    super();
-  }
-
   Directory small;
+  IndexReader reader;
 
   void assertEquals(String m, float e, float a) {
     assertEquals(m, e, a, SCORE_COMP_THRESH);
@@ -59,13 +52,13 @@ public class TestMultiTermConstantScore 
   @Override
   protected void setUp() throws Exception {
     super.setUp();
-
     String[] data = new String[] { "A 1 2 3 4 5 6", "Z       4 5 6", null,
         "B   2   4 5 6", "Y     3   5 6", null, "C     3     6",
         "X       4 5 6" };
 
     small = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(small, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
+    RandomIndexWriter writer = new RandomIndexWriter(rand, small, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
 
     for (int i = 0; i < data.length; i++) {
       Document doc = new Document();
@@ -81,10 +74,17 @@ public class TestMultiTermConstantScore 
       writer.addDocument(doc);
     }
 
-    writer.optimize();
+    reader = writer.getReader();
     writer.close();
   }
 
+  @Override
+  protected void tearDown() throws Exception {
+    reader.close();
+    small.close();
+    super.tearDown();
+  }
+
   /** macro for readability */
   public static Query csrq(String f, String l, String h, boolean il, boolean ih) {
     TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih);
@@ -146,7 +146,6 @@ public class TestMultiTermConstantScore 
   public void testEqualScores() throws IOException {
     // NOTE: uses index build in *this* setUp
 
-    IndexReader reader = IndexReader.open(small, true);
     IndexSearcher search = new IndexSearcher(reader);
 
     ScoreDoc[] result;
@@ -175,7 +174,6 @@ public class TestMultiTermConstantScore 
   public void testBoost() throws IOException {
     // NOTE: uses index build in *this* setUp
 
-    IndexReader reader = IndexReader.open(small, true);
     IndexSearcher search = new IndexSearcher(reader);
 
     // test for correct application of query normalization
@@ -247,7 +245,6 @@ public class TestMultiTermConstantScore 
   public void testBooleanOrderUnAffected() throws IOException {
     // NOTE: uses index build in *this* setUp
 
-    IndexReader reader = IndexReader.open(small, true);
     IndexSearcher search = new IndexSearcher(reader);
 
     // first do a regular TermRangeQuery which uses term expansion so
@@ -278,7 +275,7 @@ public class TestMultiTermConstantScore 
   public void testRangeQueryId() throws IOException {
     // NOTE: uses index build in *super* setUp
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int medId = ((maxId - minId) / 2);
@@ -405,7 +402,7 @@ public class TestMultiTermConstantScore 
   public void testRangeQueryIdCollating() throws IOException {
     // NOTE: uses index build in *super* setUp
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int medId = ((maxId - minId) / 2);
@@ -488,11 +485,11 @@ public class TestMultiTermConstantScore 
   public void testRangeQueryRand() throws IOException {
     // NOTE: uses index build in *super* setUp
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
-    String minRP = pad(signedIndex.minR);
-    String maxRP = pad(signedIndex.maxR);
+    String minRP = pad(signedIndexDir.minR);
+    String maxRP = pad(signedIndexDir.maxR);
 
     int numDocs = reader.numDocs();
 
@@ -551,11 +548,11 @@ public class TestMultiTermConstantScore 
     // NOTE: uses index build in *super* setUp
 
     // using the unsigned index because collation seems to ignore hyphens
-    IndexReader reader = IndexReader.open(unsignedIndex.index, true);
+    IndexReader reader = unsignedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
-    String minRP = pad(unsignedIndex.minR);
-    String maxRP = pad(unsignedIndex.maxR);
+    String minRP = pad(unsignedIndexDir.minR);
+    String maxRP = pad(unsignedIndexDir.maxR);
 
     int numDocs = reader.numDocs();
 
@@ -615,8 +612,8 @@ public class TestMultiTermConstantScore 
 
     /* build an index */
     RAMDirectory farsiIndex = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(farsiIndex, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)));
+    RandomIndexWriter writer = new RandomIndexWriter(rand, farsiIndex, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)));
     Document doc = new Document();
     doc.add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES,
         Field.Index.NOT_ANALYZED));
@@ -625,10 +622,9 @@ public class TestMultiTermConstantScore 
             Field.Index.NOT_ANALYZED));
     writer.addDocument(doc);
 
-    writer.optimize();
+    IndexReader reader = writer.getReader();
     writer.close();
 
-    IndexReader reader = IndexReader.open(farsiIndex, true);
     IndexSearcher search = new IndexSearcher(reader);
 
     // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
@@ -649,14 +645,16 @@ public class TestMultiTermConstantScore 
         1000).scoreDocs;
     assertEquals("The index Term should be included.", 1, result.length);
     search.close();
+    reader.close();
+    farsiIndex.close();
   }
 
   public void testDanish() throws Exception {
 
     /* build an index */
     RAMDirectory danishIndex = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(danishIndex, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)));
+    RandomIndexWriter writer = new RandomIndexWriter(rand, danishIndex, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)));
 
     // Danish collation orders the words below in the given order
     // (example taken from TestSort.testInternationalSort() ).
@@ -669,10 +667,9 @@ public class TestMultiTermConstantScore 
                         Field.Store.YES, Field.Index.NOT_ANALYZED));
       writer.addDocument(doc);
     }
-    writer.optimize();
+    IndexReader reader = writer.getReader();
     writer.close();
 
-    IndexReader reader = IndexReader.open(danishIndex, true);
     IndexSearcher search = new IndexSearcher(reader);
 
     Collator c = Collator.getInstance(new Locale("da", "dk"));
@@ -687,5 +684,7 @@ public class TestMultiTermConstantScore 
       (csrq("content", "H\u00C5T", "MAND", F, F, c), null, 1000).scoreDocs;
     assertEquals("The index Term should not be included.", 0, result.length);
     search.close();
+    reader.close();
+    danishIndex.close();
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java Thu Jul 22 19:34:35 2010
@@ -17,6 +17,7 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.*;
@@ -175,11 +176,11 @@ class MultiThreadTermVectorsReader imple
   
   private void verifyVectors(TermFreqVector[] vectors, int num) {
     StringBuilder temp = new StringBuilder();
-    String[] terms = null;
+    BytesRef[] terms = null;
     for (int i = 0; i < vectors.length; i++) {
       terms = vectors[i].getTerms();
       for (int z = 0; z < terms.length; z++) {
-        temp.append(terms[z]);
+        temp.append(terms[z].utf8ToString());
       }
     }
     

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java Thu Jul 22 19:34:35 2010
@@ -26,8 +26,9 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumericField;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
@@ -44,7 +45,8 @@ public class TestMultiValuedNumericRange
     final Random rnd = newRandom();
 
     RAMDirectory directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(rnd, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     
     DecimalFormat format = new DecimalFormat("00000000000", new DecimalFormatSymbols(Locale.US));
     
@@ -56,10 +58,11 @@ public class TestMultiValuedNumericRange
         doc.add(new NumericField("trie", Field.Store.NO, true).setIntValue(value));
       }
       writer.addDocument(doc);
-    }  
+    }
+    IndexReader reader = writer.getReader();
     writer.close();
     
-    Searcher searcher=new IndexSearcher(directory, true);
+    Searcher searcher=new IndexSearcher(reader);
     for (int i=0; i<50*_TestUtil.getRandomMultiplier(); i++) {
       int lower=rnd.nextInt(Integer.MAX_VALUE);
       int upper=rnd.nextInt(Integer.MAX_VALUE);
@@ -73,7 +76,7 @@ public class TestMultiValuedNumericRange
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", trTopDocs.totalHits, nrTopDocs.totalHits );
     }
     searcher.close();
-
+    reader.close();
     directory.close();
   }
   

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNot.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNot.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNot.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNot.java Thu Jul 22 19:34:35 2010
@@ -19,8 +19,9 @@ package org.apache.lucene.search;
 
 import org.apache.lucene.util.LuceneTestCase;
 
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.analysis.MockAnalyzer;
@@ -39,21 +40,24 @@ public class TestNot extends LuceneTestC
 
   public void testNot() throws Exception {
     RAMDirectory store = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(store, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), store, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
 
     Document d1 = new Document();
     d1.add(new Field("field", "a b", Field.Store.YES, Field.Index.ANALYZED));
 
     writer.addDocument(d1);
-    writer.optimize();
-    writer.close();
+    IndexReader reader = writer.getReader();
 
-    Searcher searcher = new IndexSearcher(store, true);
+    Searcher searcher = new IndexSearcher(reader);
       QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer());
     Query query = parser.parse("a NOT b");
     //System.out.println(query);
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(0, hits.length);
+    writer.close();
+    searcher.close();
+    reader.close();
+    store.close();
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java Thu Jul 22 19:34:35 2010
@@ -23,8 +23,10 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumericField;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.BytesRef;
@@ -46,12 +48,15 @@ public class TestNumericRangeQuery32 ext
   private static final int noDocs = 10000*_TestUtil.getRandomMultiplier();
   
   private static RAMDirectory directory = null;
+  private static IndexReader reader = null;
   private static IndexSearcher searcher = null;
-  
+
   @BeforeClass
   public static void beforeClass() throws Exception {
     directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    Random random = newStaticRandom(TestNumericRangeQuery32.class);
+    RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     
     NumericField
       field8 = new NumericField("field8", 8, Field.Store.YES, true),
@@ -83,15 +88,17 @@ public class TestNumericRangeQuery32 ext
       writer.addDocument(doc);
     }
   
-    writer.optimize();
+    reader = writer.getReader();
+    searcher=new IndexSearcher(reader);
     writer.close();
-    searcher=new IndexSearcher(directory, true);
   }
   
   @AfterClass
   public static void afterClass() throws Exception {
     searcher.close();
     searcher = null;
+    reader.close();
+    reader = null;
     directory.close();
     directory = null;
   }
@@ -147,7 +154,7 @@ public class TestNumericRangeQuery32 ext
       assertEquals("First doc"+type, 2*distance+startOffset, Integer.parseInt(doc.get(field)) );
       doc=searcher.doc(sd[sd.length-1].doc);
       assertEquals("Last doc"+type, (1+count)*distance+startOffset, Integer.parseInt(doc.get(field)) );
-      if (i>0) {
+      if (i>0 && searcher.getIndexReader().getSequentialSubReaders().length == 1) {
         assertEquals("Distinct term number is equal for all query types", lastTerms, terms);
       }
       lastTerms = terms;
@@ -372,7 +379,7 @@ public class TestNumericRangeQuery32 ext
       termCountT += tq.getTotalNumberOfTerms();
       termCountC += cq.getTotalNumberOfTerms();
     }
-    if (precisionStep == Integer.MAX_VALUE) {
+    if (precisionStep == Integer.MAX_VALUE && searcher.getIndexReader().getSequentialSubReaders().length == 1) {
       assertEquals("Total number of terms should be equal for unlimited precStep", termCountT, termCountC);
     } else if (VERBOSE) {
       System.out.println("Average number of terms during random search on '" + field + "':");

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java Thu Jul 22 19:34:35 2010
@@ -23,8 +23,10 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumericField;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCaseJ4;
@@ -45,12 +47,15 @@ public class TestNumericRangeQuery64 ext
   private static final int noDocs = 10000*_TestUtil.getRandomMultiplier();
   
   private static RAMDirectory directory = null;
+  private static IndexReader reader = null;
   private static IndexSearcher searcher = null;
   
   @BeforeClass
   public static void beforeClass() throws Exception {
     directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    Random random = newStaticRandom(TestNumericRangeQuery64.class);
+    RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     
     NumericField
       field8 = new NumericField("field8", 8, Field.Store.YES, true),
@@ -86,15 +91,17 @@ public class TestNumericRangeQuery64 ext
       writer.addDocument(doc);
     }
   
-    writer.optimize();
+    reader = writer.getReader();
+    searcher=new IndexSearcher(reader);
     writer.close();
-    searcher=new IndexSearcher(directory, true);
   }
   
   @AfterClass
   public static void afterClass() throws Exception {
     searcher.close();
     searcher = null;
+    reader.close();
+    reader = null;
     directory.close();
     directory = null;
   }
@@ -150,7 +157,7 @@ public class TestNumericRangeQuery64 ext
       assertEquals("First doc"+type, 2*distance+startOffset, Long.parseLong(doc.get(field)) );
       doc=searcher.doc(sd[sd.length-1].doc);
       assertEquals("Last doc"+type, (1+count)*distance+startOffset, Long.parseLong(doc.get(field)) );
-      if (i>0) {
+      if (i>0 && searcher.getIndexReader().getSequentialSubReaders().length == 1) {
         assertEquals("Distinct term number is equal for all query types", lastTerms, terms);
       }
       lastTerms = terms;
@@ -391,7 +398,7 @@ public class TestNumericRangeQuery64 ext
       termCountT += tq.getTotalNumberOfTerms();
       termCountC += cq.getTotalNumberOfTerms();
     }
-    if (precisionStep == Integer.MAX_VALUE) {
+    if (precisionStep == Integer.MAX_VALUE && searcher.getIndexReader().getSequentialSubReaders().length == 1) {
       assertEquals("Total number of terms should be equal for unlimited precStep", termCountT, termCountC);
     } else if (VERBOSE) {
       System.out.println("Average number of terms during random search on '" + field + "':");
@@ -590,10 +597,4 @@ public class TestNumericRangeQuery64 ext
     );
      // difference to int range is tested in TestNumericRangeQuery32
   }
-  
-  @Test @Deprecated
-  public void testBackwardsLayer() {
-    assertTrue(NumericRangeQuery.newLongRange("dummy", null, null, true, true).hasNewAPI);
-  }
-  
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java Thu Jul 22 19:34:35 2010
@@ -21,11 +21,13 @@ import org.apache.lucene.util.LuceneTest
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermEnum;
+import org.apache.lucene.index.MultiFields;
+import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.store.RAMDirectory;
 
 import java.io.IOException;
@@ -38,63 +40,72 @@ public class TestPhrasePrefixQuery exten
   public TestPhrasePrefixQuery(String name) {
     super(name);
   }
-
-    /**
+  
+  /**
      *
      */
-    public void testPhrasePrefix()
-        throws IOException
-    {
-        RAMDirectory indexStore = new RAMDirectory();
-        IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
-        Document doc1 = new Document();
-        Document doc2 = new Document();
-        Document doc3 = new Document();
-        Document doc4 = new Document();
-        Document doc5 = new Document();
-        doc1.add(new Field("body", "blueberry pie", Field.Store.YES, Field.Index.ANALYZED));
-        doc2.add(new Field("body", "blueberry strudel", Field.Store.YES, Field.Index.ANALYZED));
-        doc3.add(new Field("body", "blueberry pizza", Field.Store.YES, Field.Index.ANALYZED));
-        doc4.add(new Field("body", "blueberry chewing gum", Field.Store.YES, Field.Index.ANALYZED));
-        doc5.add(new Field("body", "piccadilly circus", Field.Store.YES, Field.Index.ANALYZED));
-        writer.addDocument(doc1);
-        writer.addDocument(doc2);
-        writer.addDocument(doc3);
-        writer.addDocument(doc4);
-        writer.addDocument(doc5);
-        writer.optimize();
-        writer.close();
-
-        IndexSearcher searcher = new IndexSearcher(indexStore, true);
-
-        //PhrasePrefixQuery query1 = new PhrasePrefixQuery();
-        MultiPhraseQuery query1 = new MultiPhraseQuery();
-        //PhrasePrefixQuery query2 = new PhrasePrefixQuery();
-        MultiPhraseQuery query2 = new MultiPhraseQuery();
-        query1.add(new Term("body", "blueberry"));
-        query2.add(new Term("body", "strawberry"));
-
-        LinkedList<Term> termsWithPrefix = new LinkedList<Term>();
-        IndexReader ir = IndexReader.open(indexStore, true);
-
-        // this TermEnum gives "piccadilly", "pie" and "pizza".
-        String prefix = "pi";
-        TermEnum te = ir.terms(new Term("body", prefix + "*"));
-        do {
-            if (te.term().text().startsWith(prefix))
-            {
-                termsWithPrefix.add(te.term());
-            }
-        } while (te.next());
-
-        query1.add(termsWithPrefix.toArray(new Term[0]));
-        query2.add(termsWithPrefix.toArray(new Term[0]));
-
-        ScoreDoc[] result;
-        result = searcher.search(query1, null, 1000).scoreDocs;
-        assertEquals(2, result.length);
-
-        result = searcher.search(query2, null, 1000).scoreDocs;
-        assertEquals(0, result.length);
-    }
+  public void testPhrasePrefix() throws IOException {
+    RAMDirectory indexStore = new RAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    Document doc1 = new Document();
+    Document doc2 = new Document();
+    Document doc3 = new Document();
+    Document doc4 = new Document();
+    Document doc5 = new Document();
+    doc1.add(new Field("body", "blueberry pie", Field.Store.YES,
+        Field.Index.ANALYZED));
+    doc2.add(new Field("body", "blueberry strudel", Field.Store.YES,
+        Field.Index.ANALYZED));
+    doc3.add(new Field("body", "blueberry pizza", Field.Store.YES,
+        Field.Index.ANALYZED));
+    doc4.add(new Field("body", "blueberry chewing gum", Field.Store.YES,
+        Field.Index.ANALYZED));
+    doc5.add(new Field("body", "piccadilly circus", Field.Store.YES,
+        Field.Index.ANALYZED));
+    writer.addDocument(doc1);
+    writer.addDocument(doc2);
+    writer.addDocument(doc3);
+    writer.addDocument(doc4);
+    writer.addDocument(doc5);
+    IndexReader reader = writer.getReader();
+    writer.close();
+    
+    IndexSearcher searcher = new IndexSearcher(reader);
+    
+    // PhrasePrefixQuery query1 = new PhrasePrefixQuery();
+    MultiPhraseQuery query1 = new MultiPhraseQuery();
+    // PhrasePrefixQuery query2 = new PhrasePrefixQuery();
+    MultiPhraseQuery query2 = new MultiPhraseQuery();
+    query1.add(new Term("body", "blueberry"));
+    query2.add(new Term("body", "strawberry"));
+    
+    LinkedList<Term> termsWithPrefix = new LinkedList<Term>();
+    
+    // this TermEnum gives "piccadilly", "pie" and "pizza".
+    String prefix = "pi";
+    TermsEnum te = MultiFields.getFields(reader).terms("body").iterator();
+    te.seek(new BytesRef(prefix));
+    do {
+      String s = te.term().utf8ToString();
+      if (s.startsWith(prefix)) {
+        termsWithPrefix.add(new Term("body", s));
+      } else {
+        break;
+      }
+    } while (te.next() != null);
+    
+    query1.add(termsWithPrefix.toArray(new Term[0]));
+    query2.add(termsWithPrefix.toArray(new Term[0]));
+    
+    ScoreDoc[] result;
+    result = searcher.search(query1, null, 1000).scoreDocs;
+    assertEquals(2, result.length);
+    
+    result = searcher.search(query2, null, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    searcher.close();
+    reader.close();
+    indexStore.close();
+  }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java Thu Jul 22 19:34:35 2010
@@ -19,18 +19,21 @@ package org.apache.lucene.search;
 
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.analysis.*;
+import org.apache.lucene.analysis.tokenattributes.*;
 import org.apache.lucene.document.*;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.Term;
+import org.apache.lucene.index.*;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
 import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.*;
 import org.apache.lucene.util.Version;
+import org.apache.lucene.util._TestUtil;
 
 import java.io.IOException;
 import java.io.Reader;
+import java.io.StringReader;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Random;
 
 /**
  * Tests {@link PhraseQuery}.
@@ -43,12 +46,15 @@ public class TestPhraseQuery extends Luc
   public static final float SCORE_COMP_THRESH = 1e-6f;
   
   private IndexSearcher searcher;
+  private IndexReader reader;
   private PhraseQuery query;
   private RAMDirectory directory;
+  private Random random;
 
   @Override
   public void setUp() throws Exception {
     super.setUp();
+    random = newRandom();
     directory = new RAMDirectory();
     Analyzer analyzer = new Analyzer() {
       @Override
@@ -61,7 +67,8 @@ public class TestPhraseQuery extends Luc
         return 100;
       }
     };
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
+    RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
     
     Document doc = new Document();
     doc.add(new Field("field", "one two three four five", Field.Store.YES, Field.Index.ANALYZED));
@@ -79,16 +86,17 @@ public class TestPhraseQuery extends Luc
     doc.add(new Field("nonexist", "phrase exist notexist exist found", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
 
-    writer.optimize();
+    reader = writer.getReader();
     writer.close();
 
-    searcher = new IndexSearcher(directory, true);
+    searcher = new IndexSearcher(reader);
     query = new PhraseQuery();
   }
 
   @Override
   protected void tearDown() throws Exception {
     searcher.close();
+    reader.close();
     directory.close();
     super.tearDown();
   }
@@ -208,14 +216,15 @@ public class TestPhraseQuery extends Luc
   public void testPhraseQueryWithStopAnalyzer() throws Exception {
     RAMDirectory directory = new RAMDirectory();
     Analyzer stopAnalyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, false);
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
-        Version.LUCENE_24, stopAnalyzer));
+    RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(Version.LUCENE_24, stopAnalyzer));
     Document doc = new Document();
     doc.add(new Field("field", "the stop words are here", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
+    IndexReader reader = writer.getReader();
     writer.close();
 
-    IndexSearcher searcher = new IndexSearcher(directory, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
 
     // valid exact phrase query
     PhraseQuery query = new PhraseQuery();
@@ -236,11 +245,14 @@ public class TestPhraseQuery extends Luc
 
 
     searcher.close();
+    reader.close();
+    directory.close();
   }
   
   public void testPhraseQueryInConjunctionScorer() throws Exception {
     RAMDirectory directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     
     Document doc = new Document();
     doc.add(new Field("source", "marketing info", Field.Store.YES, Field.Index.ANALYZED));
@@ -251,10 +263,10 @@ public class TestPhraseQuery extends Luc
     doc.add(new Field("source", "marketing info", Field.Store.YES, Field.Index.ANALYZED)); 
     writer.addDocument(doc);
     
-    writer.optimize();
+    IndexReader reader = writer.getReader();
     writer.close();
     
-    IndexSearcher searcher = new IndexSearcher(directory, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
     
     PhraseQuery phraseQuery = new PhraseQuery();
     phraseQuery.add(new Term("source", "marketing"));
@@ -274,8 +286,10 @@ public class TestPhraseQuery extends Luc
 
     
     searcher.close();
+    reader.close();
     
-    writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
+    writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
     doc = new Document();
     doc.add(new Field("contents", "map entry woo", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
@@ -288,10 +302,10 @@ public class TestPhraseQuery extends Luc
     doc.add(new Field("contents", "map foobarword entry woo", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
 
-    writer.optimize();
+    reader = writer.getReader();
     writer.close();
     
-    searcher = new IndexSearcher(directory, true);
+    searcher = new IndexSearcher(reader);
     
     termQuery = new TermQuery(new Term("contents","woo"));
     phraseQuery = new PhraseQuery();
@@ -319,29 +333,31 @@ public class TestPhraseQuery extends Luc
 
     
     searcher.close();
+    reader.close();
     directory.close();
   }
   
   public void testSlopScoring() throws IOException {
     Directory directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
 
     Document doc = new Document();
     doc.add(new Field("field", "foo firstname lastname foo", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
     
     Document doc2 = new Document();
-    doc2.add(new Field("field", "foo firstname xxx lastname foo", Field.Store.YES, Field.Index.ANALYZED));
+    doc2.add(new Field("field", "foo firstname zzz lastname foo", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc2);
     
     Document doc3 = new Document();
-    doc3.add(new Field("field", "foo firstname xxx yyy lastname foo", Field.Store.YES, Field.Index.ANALYZED));
+    doc3.add(new Field("field", "foo firstname zzz yyy lastname foo", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc3);
     
-    writer.optimize();
+    IndexReader reader = writer.getReader();
     writer.close();
 
-    Searcher searcher = new IndexSearcher(directory, true);
+    Searcher searcher = new IndexSearcher(reader);
     PhraseQuery query = new PhraseQuery();
     query.add(new Term("field", "firstname"));
     query.add(new Term("field", "lastname"));
@@ -356,7 +372,10 @@ public class TestPhraseQuery extends Luc
     assertEquals(1, hits[1].doc);
     assertEquals(0.31, hits[2].score, 0.01);
     assertEquals(2, hits[2].doc);
-    QueryUtils.check(query,searcher);        
+    QueryUtils.check(query,searcher);
+    searcher.close();
+    reader.close();
+    directory.close();
   }
   
   public void testToString() throws Exception {
@@ -517,6 +536,9 @@ public class TestPhraseQuery extends Luc
     //System.out.println("(exact) field: one two three: "+score0);
     QueryUtils.check(query,searcher);
 
+    // just make sure no exc:
+    searcher.explain(query, 0);
+
     // search on non palyndrome, find phrase with slop 3, though no slop required here.
     query.setSlop(4); // to use sloppy scorer 
     hits = searcher.search(query, null, 1000).scoreDocs;
@@ -533,6 +555,10 @@ public class TestPhraseQuery extends Luc
     query.add(new Term("palindrome", "two"));
     query.add(new Term("palindrome", "three"));
     hits = searcher.search(query, null, 1000).scoreDocs;
+
+    // just make sure no exc:
+    searcher.explain(query, 0);
+
     assertEquals("just sloppy enough", 1, hits.length);
     //float score2 = hits[0].score;
     //System.out.println("palindrome: one two three: "+score2);
@@ -572,4 +598,94 @@ public class TestPhraseQuery extends Luc
     Query rewritten = pq.rewrite(searcher.getIndexReader());
     assertTrue(rewritten instanceof TermQuery);
   }
+
+  public void testRandomPhrases() throws Exception {
+    Directory dir = new MockRAMDirectory();
+    Analyzer analyzer = new MockAnalyzer();
+
+    RandomIndexWriter w  = new RandomIndexWriter(random, dir, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
+    List<List<String>> docs = new ArrayList<List<String>>();
+    Document d = new Document();
+    Field f = new Field("f", "", Field.Store.NO, Field.Index.ANALYZED);
+    d.add(f);
+
+    Random r = random;
+
+    int NUM_DOCS = 10*_TestUtil.getRandomMultiplier();
+    for(int i=0;i<NUM_DOCS;i++) {
+      // must be > 4096 so it spans multiple chunks
+      int termCount = _TestUtil.nextInt(r, 10000, 30000);
+
+      List<String> doc = new ArrayList<String>();
+
+      StringBuilder sb = new StringBuilder();
+      while(doc.size() < termCount) {
+        if (r.nextInt(5) == 1 || docs.size() == 0) {
+          // make new non-empty-string term
+          String term;
+          while(true) {
+            term = _TestUtil.randomUnicodeString(r);
+            if (term.length() > 0) {
+              break;
+            }
+          }
+          TokenStream ts = analyzer.reusableTokenStream("ignore", new StringReader(term));
+          CharTermAttribute termAttr = ts.addAttribute(CharTermAttribute.class);
+          while(ts.incrementToken()) {
+            String text = termAttr.toString();
+            doc.add(text);
+            sb.append(text).append(' ');
+          }
+        } else {
+          // pick existing sub-phrase
+          List<String> lastDoc = docs.get(r.nextInt(docs.size()));
+          int len = _TestUtil.nextInt(r, 1, 10);
+          int start = r.nextInt(lastDoc.size()-len);
+          for(int k=start;k<start+len;k++) {
+            String t = lastDoc.get(k);
+            doc.add(t);
+            sb.append(t).append(' ');
+          }
+        }
+      }
+      docs.add(doc);
+      f.setValue(sb.toString());
+      w.addDocument(d);
+    }
+
+    IndexReader reader = w.getReader();
+    IndexSearcher s = new IndexSearcher(reader);
+    w.close();
+
+    // now search
+    for(int i=0;i<100*_TestUtil.getRandomMultiplier();i++) {
+      int docID = r.nextInt(docs.size());
+      List<String> doc = docs.get(docID);
+      
+      final int numTerm = _TestUtil.nextInt(r, 2, 20);
+      final int start = r.nextInt(doc.size()-numTerm);
+      PhraseQuery pq = new PhraseQuery();
+      StringBuilder sb = new StringBuilder();
+      for(int t=start;t<start+numTerm;t++) {
+        pq.add(new Term("f", doc.get(t)));
+        sb.append(doc.get(t)).append(' ');
+      }
+
+      TopDocs hits = s.search(pq, NUM_DOCS);
+      boolean found = false;
+      for(int j=0;j<hits.scoreDocs.length;j++) {
+        if (hits.scoreDocs[j].doc == docID) {
+          found = true;
+          break;
+        }
+      }
+
+      assertTrue("phrase '" + sb + "' not found; start=" + start, found);
+    }
+
+    reader.close();
+    s.close();
+    dir.close();
+  }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java Thu Jul 22 19:34:35 2010
@@ -32,11 +32,12 @@ import org.apache.lucene.analysis.tokena
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.MultiFields;
+import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermPositions;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.store.Directory;
@@ -50,6 +51,7 @@ import org.apache.lucene.search.spans.Sp
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.automaton.CharacterRunAutomaton;
 import org.apache.lucene.util.automaton.RegExp;
+import org.apache.lucene.util.BytesRef;
 
 /**
  * Term position unit test.
@@ -89,23 +91,30 @@ public class TestPositionIncrement exten
       }
     };
     Directory store = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(store, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), store, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
     Document d = new Document();
     d.add(new Field("field", "bogus", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(d);
-    writer.optimize();
+    IndexReader reader = writer.getReader();
     writer.close();
     
 
-    IndexSearcher searcher = new IndexSearcher(store, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
     
-    TermPositions pos = searcher.getIndexReader().termPositions(new Term("field", "1"));
-    pos.next();
+    DocsAndPositionsEnum pos = MultiFields.getTermPositionsEnum(searcher.getIndexReader(),
+                                                                MultiFields.getDeletedDocs(searcher.getIndexReader()),
+                                                                "field",
+                                                                new BytesRef("1"));
+    pos.nextDoc();
     // first token should be at position 0
     assertEquals(0, pos.nextPosition());
     
-    pos = searcher.getIndexReader().termPositions(new Term("field", "2"));
-    pos.next();
+    pos = MultiFields.getTermPositionsEnum(searcher.getIndexReader(),
+                                           MultiFields.getDeletedDocs(searcher.getIndexReader()),
+                                           "field",
+                                           new BytesRef("2"));
+    pos.nextDoc();
     // second token should be at position 2
     assertEquals(2, pos.nextPosition());
     
@@ -221,6 +230,10 @@ public class TestPositionIncrement exten
     q = (PhraseQuery) qp.parse("\"1 stop 2\"");
     hits = searcher.search(q, null, 1000).scoreDocs;
     assertEquals(1, hits.length);
+    
+    searcher.close();
+    reader.close();
+    store.close();
   }
 
   // stoplist that accepts case-insensitive "stop"
@@ -229,8 +242,8 @@ public class TestPositionIncrement exten
   
   public void testPayloadsPos0() throws Exception {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));
     Document doc = new Document();
     doc.add(new Field("content", new StringReader(
         "a a b c d e a f g h i j a b k k")));
@@ -238,9 +251,13 @@ public class TestPositionIncrement exten
 
     IndexReader r = writer.getReader();
 
-    TermPositions tp = r.termPositions(new Term("content", "a"));
+    DocsAndPositionsEnum tp = MultiFields.getTermPositionsEnum(r,
+                                                               MultiFields.getDeletedDocs(r),
+                                                               "content",
+                                                               new BytesRef("a"));
+    
     int count = 0;
-    assertTrue(tp.next());
+    assertTrue(tp.nextDoc() != tp.NO_MORE_DOCS);
     // "a" occurs 4 times
     assertEquals(4, tp.freq());
     int expected = 0;
@@ -250,7 +267,7 @@ public class TestPositionIncrement exten
     assertEquals(6, tp.nextPosition());
 
     // only one doc has "a"
-    assertFalse(tp.next());
+    assertEquals(tp.NO_MORE_DOCS, tp.nextDoc());
 
     IndexSearcher is = new IndexSearcher(r);
   

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java Thu Jul 22 19:34:35 2010
@@ -19,8 +19,9 @@ package org.apache.lucene.search;
 
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
@@ -38,18 +39,19 @@ public class TestPrefixFilter extends Lu
                                         "/Computers/Mac/One",
                                         "/Computers/Mac/Two",
                                         "/Computers/Windows"};
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     for (int i = 0; i < categories.length; i++) {
       Document doc = new Document();
       doc.add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
       writer.addDocument(doc);
     }
-    writer.close();
+    IndexReader reader = writer.getReader();
 
     // PrefixFilter combined with ConstantScoreQuery
     PrefixFilter filter = new PrefixFilter(new Term("category", "/Computers"));
     Query query = new ConstantScoreQuery(filter);
-    IndexSearcher searcher = new IndexSearcher(directory, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(4, hits.length);
 
@@ -100,5 +102,10 @@ public class TestPrefixFilter extends Lu
     query = new ConstantScoreQuery(filter);
     hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(0, hits.length);
+    
+    writer.close();
+    searcher.close();
+    reader.close();
+    directory.close();
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java Thu Jul 22 19:34:35 2010
@@ -21,8 +21,9 @@ import org.apache.lucene.util.LuceneTest
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.RAMDirectory;
 
@@ -40,12 +41,15 @@ public class TestPrefixInBooleanQuery ex
 
   private static final String FIELD = "name";
   private RAMDirectory directory = new RAMDirectory();
+  private IndexReader reader;
+  private IndexSearcher searcher;
 
   @Override
   protected void setUp() throws Exception {
     super.setUp();
     
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
 
     for (int i = 0; i < 5137; ++i) {
       Document doc = new Document();
@@ -73,40 +77,46 @@ public class TestPrefixInBooleanQuery ex
       writer.addDocument(doc);
     }
     
+    reader = writer.getReader();
+    searcher = new IndexSearcher(reader);
     writer.close();
   }
   
+  @Override
+  public void tearDown() throws Exception {
+    searcher.close();
+    reader.close();
+    directory.close();
+    super.tearDown();
+  }
+  
   public void testPrefixQuery() throws Exception {
-    IndexSearcher indexSearcher = new IndexSearcher(directory, true);
     Query query = new PrefixQuery(new Term(FIELD, "tang"));
     assertEquals("Number of matched documents", 2,
-                 indexSearcher.search(query, null, 1000).totalHits);
+                 searcher.search(query, null, 1000).totalHits);
   }
   public void testTermQuery() throws Exception {
-    IndexSearcher indexSearcher = new IndexSearcher(directory, true);
     Query query = new TermQuery(new Term(FIELD, "tangfulin"));
     assertEquals("Number of matched documents", 2,
-                 indexSearcher.search(query, null, 1000).totalHits);
+                 searcher.search(query, null, 1000).totalHits);
   }
   public void testTermBooleanQuery() throws Exception {
-    IndexSearcher indexSearcher = new IndexSearcher(directory, true);
     BooleanQuery query = new BooleanQuery();
     query.add(new TermQuery(new Term(FIELD, "tangfulin")),
               BooleanClause.Occur.SHOULD);
     query.add(new TermQuery(new Term(FIELD, "notexistnames")),
               BooleanClause.Occur.SHOULD);
     assertEquals("Number of matched documents", 2,
-                 indexSearcher.search(query, null, 1000).totalHits);
+                 searcher.search(query, null, 1000).totalHits);
 
   }
   public void testPrefixBooleanQuery() throws Exception {
-    IndexSearcher indexSearcher = new IndexSearcher(directory, true);
     BooleanQuery query = new BooleanQuery();
     query.add(new PrefixQuery(new Term(FIELD, "tang")),
               BooleanClause.Occur.SHOULD);
     query.add(new TermQuery(new Term(FIELD, "notexistnames")),
               BooleanClause.Occur.SHOULD);
     assertEquals("Number of matched documents", 2,
-                 indexSearcher.search(query, null, 1000).totalHits);
+                 searcher.search(query, null, 1000).totalHits);
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java Thu Jul 22 19:34:35 2010
@@ -19,8 +19,9 @@ package org.apache.lucene.search;
 
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
@@ -37,16 +38,17 @@ public class TestPrefixQuery extends Luc
     String[] categories = new String[] {"/Computers",
                                         "/Computers/Mac",
                                         "/Computers/Windows"};
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     for (int i = 0; i < categories.length; i++) {
       Document doc = new Document();
       doc.add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
       writer.addDocument(doc);
     }
-    writer.close();
+    IndexReader reader = writer.getReader();
 
     PrefixQuery query = new PrefixQuery(new Term("category", "/Computers"));
-    IndexSearcher searcher = new IndexSearcher(directory, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals("All documents in /Computers category and below", 3, hits.length);
 
@@ -58,10 +60,9 @@ public class TestPrefixQuery extends Luc
     assertFalse(query.getTermsEnum(searcher.getIndexReader()) instanceof PrefixTermsEnum);
     hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals("everything", 3, hits.length);
-  }
-  
-  @Deprecated
-  public void testBackwardsLayer() {
-    assertTrue(new PrefixQuery(new Term("dummy", "dummy")).hasNewAPI);
+    writer.close();
+    searcher.close();
+    reader.close();
+    directory.close();
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryTermVector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryTermVector.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryTermVector.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryTermVector.java Thu Jul 22 19:34:35 2010
@@ -17,6 +17,7 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.analysis.MockAnalyzer;
 
@@ -28,12 +29,14 @@ public class TestQueryTermVector extends
   }
 
   public void testConstructor() {
-    String [] queryTerm = {"foo", "bar", "foo", "again", "foo", "bar", "go", "go", "go"};
+    BytesRef [] queryTerm = {new BytesRef("foo"), new BytesRef("bar"), new BytesRef("foo"), 
+        new BytesRef("again"), new BytesRef("foo"), new BytesRef("bar"), new BytesRef("go"),
+        new BytesRef("go"), new BytesRef("go")};
     //Items are sorted lexicographically
-    String [] gold = {"again", "bar", "foo", "go"};
+    BytesRef [] gold = {new BytesRef("again"), new BytesRef("bar"), new BytesRef("foo"), new BytesRef("go")};
     int [] goldFreqs = {1, 2, 3, 3};
     QueryTermVector result = new QueryTermVector(queryTerm);
-    String [] terms = result.getTerms();
+    BytesRef [] terms = result.getTerms();
     assertTrue(terms.length == 4);
     int [] freq = result.getTermFrequencies();
     assertTrue(freq.length == 4);
@@ -49,7 +52,7 @@ public class TestQueryTermVector extends
     checkGold(terms, gold, freq, goldFreqs);
   }
 
-  private void checkGold(String[] terms, String[] gold, int[] freq, int[] goldFreqs) {
+  private void checkGold(BytesRef[] terms, BytesRef[] gold, int[] freq, int[] goldFreqs) {
     for (int i = 0; i < terms.length; i++) {
       assertTrue(terms[i].equals(gold[i]));
       assertTrue(freq[i] == goldFreqs[i]);

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java Thu Jul 22 19:34:35 2010
@@ -22,8 +22,9 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Field.Index;
 import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.store.Directory;
@@ -34,10 +35,12 @@ public class TestQueryWrapperFilter exte
 
   public void testBasic() throws Exception {
     Directory dir = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     Document doc = new Document();
     doc.add(new Field("field", "value", Store.NO, Index.ANALYZED));
     writer.addDocument(doc);
+    IndexReader reader = writer.getReader();
     writer.close();
 
     TermQuery termQuery = new TermQuery(new Term("field", "value"));
@@ -45,7 +48,7 @@ public class TestQueryWrapperFilter exte
     // should not throw exception with primitive query
     QueryWrapperFilter qwf = new QueryWrapperFilter(termQuery);
 
-    IndexSearcher searcher = new IndexSearcher(dir, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
     TopDocs hits = searcher.search(new MatchAllDocsQuery(), qwf, 10);
     assertEquals(1, hits.totalHits);
     hits = searcher.search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
@@ -79,5 +82,8 @@ public class TestQueryWrapperFilter exte
     assertEquals(0, hits.totalHits);
     hits = searcher.search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
     assertEquals(0, hits.totalHits);
+    searcher.close();
+    reader.close();
+    dir.close();
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java Thu Jul 22 19:34:35 2010
@@ -23,9 +23,11 @@ import java.util.Arrays;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.automaton.Automaton;
@@ -39,25 +41,29 @@ import org.apache.lucene.util.automaton.
  */
 public class TestRegexpQuery extends LuceneTestCase {
   private IndexSearcher searcher;
+  private IndexReader reader;
+  private Directory directory;
   private final String FN = "field";
   
   public void setUp() throws Exception {
     super.setUp();
-    RAMDirectory directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new MockAnalyzer(),
-        true, IndexWriter.MaxFieldLength.LIMITED);
+    directory = new RAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     Document doc = new Document();
     doc.add(new Field(FN,
         "the quick brown fox jumps over the lazy ??? dog 493432 49344",
         Field.Store.NO, Field.Index.ANALYZED));
     writer.addDocument(doc);
-    writer.optimize();
+    reader = writer.getReader();
     writer.close();
-    searcher = new IndexSearcher(directory, true);
+    searcher = new IndexSearcher(reader);
   }
   
   public void tearDown() throws Exception {
     searcher.close();
+    reader.close();
+    directory.close();
     super.tearDown();
   }
   
@@ -120,9 +126,4 @@ public class TestRegexpQuery extends Luc
   public void testBacktracking() throws IOException {
     assertEquals(1, regexQueryNrHits("4934[314]"));
   }
-  
-  @Deprecated
-  public void testBackwardsLayer() {
-    assertTrue(new RegexpQuery(newTerm(".*")).hasNewAPI);
-  }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java Thu Jul 22 19:34:35 2010
@@ -26,8 +26,11 @@ import java.util.Random;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
@@ -39,13 +42,17 @@ import org.apache.lucene.util._TestUtil;
  */
 public class TestRegexpRandom extends LuceneTestCase {
   private Searcher searcher;
+  private IndexReader reader;
+  private Directory dir;
   private Random random;
   
   @Override
   protected void setUp() throws Exception {
     super.setUp();
-    RAMDirectory dir = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new MockAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    random = newRandom();
+    dir = new RAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random, dir,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     
     Document doc = new Document();
     Field field = new Field("field", "", Field.Store.NO, Field.Index.ANALYZED);
@@ -57,9 +64,9 @@ public class TestRegexpRandom extends Lu
       writer.addDocument(doc);
     }
     
-    writer.optimize();
+    reader = writer.getReader();
     writer.close();
-    searcher = new IndexSearcher(dir);
+    searcher = new IndexSearcher(reader);
   }
   
   private char N() {
@@ -89,11 +96,12 @@ public class TestRegexpRandom extends Lu
   @Override
   protected void tearDown() throws Exception {
     searcher.close();
+    reader.close();
+    dir.close();
     super.tearDown();
   }
   
   public void testRegexps() throws Exception {
-    random = newRandom(System.nanoTime());
     for (int i = 0; i < 100*_TestUtil.getRandomMultiplier(); i++) {
       assertPatternHits("NNNN", 1);
       assertPatternHits(".NNN", 10);

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java Thu Jul 22 19:34:35 2010
@@ -25,10 +25,12 @@ import org.apache.lucene.analysis.MockTo
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.UnicodeUtil;
@@ -44,33 +46,39 @@ import org.apache.lucene.util.automaton.
  */
 public class TestRegexpRandom2 extends LuceneTestCase {
   private IndexSearcher searcher;
+  private IndexReader reader;
+  private Directory dir;
   private Random random;
   
   @Override
   protected void setUp() throws Exception {
     super.setUp();
     random = newRandom();
-    RAMDirectory dir = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new MockAnalyzer(MockTokenizer.KEYWORD, false),
-        IndexWriter.MaxFieldLength.UNLIMITED);
+    dir = new MockRAMDirectory();
+    // TODO: fix mocktokenizer to not extend chartokenizer, so you can have an 'empty' keyword.
+    // currently, this means 'empty tokens' arent created/tested in the enumeration:
+    // <mikemccand> it's like having a big hairy scary monster in the basement but being upset that it doesn't have fangs
+    RandomIndexWriter writer = new RandomIndexWriter(random, dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
+                                                                                        new MockAnalyzer(MockTokenizer.KEYWORD, false)));
     
     Document doc = new Document();
     Field field = new Field("field", "", Field.Store.NO, Field.Index.ANALYZED);
     doc.add(field);
-    
+
     for (int i = 0; i < 2000*_TestUtil.getRandomMultiplier(); i++) {
       field.setValue(_TestUtil.randomUnicodeString(random));
       writer.addDocument(doc);
     }
-    
-    writer.optimize();
+    reader = writer.getReader();
+    searcher = new IndexSearcher(reader);
     writer.close();
-    searcher = new IndexSearcher(dir);
   }
 
   @Override
   protected void tearDown() throws Exception {
+    reader.close();
     searcher.close();
+    dir.close();
     super.tearDown();
   }
   
@@ -135,7 +143,7 @@ public class TestRegexpRandom2 extends L
     
     TopDocs smartDocs = searcher.search(smart, 25);
     TopDocs dumbDocs = searcher.search(dumb, 25);
-    
-    assertEquals("for re:" + regexp, dumbDocs.totalHits, smartDocs.totalHits);
+
+    CheckHits.checkEqual(smart, smartDocs.scoreDocs, dumbDocs.scoreDocs);
   }
 }



Mime
View raw message