lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r966819 [11/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/TestCustomSearcherSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java Thu Jul 22 19:34:35 2010
@@ -24,17 +24,13 @@ import java.util.Map;
 import java.util.Random;
 import java.util.TreeMap;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.DateTools;
 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;
@@ -43,231 +39,236 @@ import org.apache.lucene.util._TestUtil;
 
 /**
  * Unit test for sorting code.
- *
+ * 
  */
 
-public class TestCustomSearcherSort
-extends LuceneTestCase
-implements Serializable {
-
-    private Directory index = null;
-    private Query query = null;
-    // reduced from 20000 to 2000 to speed up test...
-    private final static int INDEX_SIZE = 2000*_TestUtil.getRandomMultiplier();
-
-  public TestCustomSearcherSort (String name) {
-    super (name);
-  }
-
-  public static void main (String[] argv) {
-      TestRunner.run (suite());
-  }
-
-  public static Test suite() {
-    return new TestSuite (TestCustomSearcherSort.class);
-  }
-
-
-  // create an index for testing
-  private Directory getIndex()
-  throws IOException {
-          RAMDirectory indexStore = new RAMDirectory ();
-          IndexWriter writer = new IndexWriter (indexStore, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
-          RandomGen random = new RandomGen(newRandom());
-          for (int i=0; i<INDEX_SIZE; ++i) { // don't decrease; if to low the problem doesn't show up
-          Document doc = new Document();
-              if((i%5)!=0) { // some documents must not have an entry in the first sort field
-                  doc.add (new Field("publicationDate_", random.getLuceneDate(), Field.Store.YES, Field.Index.NOT_ANALYZED));
-              }
-              if((i%7)==0) { // some documents to match the query (see below) 
-                  doc.add (new Field("content", "test", Field.Store.YES, Field.Index.ANALYZED));
-              }
-              // every document has a defined 'mandant' field
-              doc.add(new Field("mandant", Integer.toString(i%3), Field.Store.YES, Field.Index.NOT_ANALYZED));
-              writer.addDocument (doc);
-          }
-          writer.optimize ();
-          writer.close ();
-      return indexStore;
-  }
-
+public class TestCustomSearcherSort extends LuceneTestCase implements
+    Serializable {
+  
+  private Directory index = null;
+  private IndexReader reader;
+  private Query query = null;
+  // reduced from 20000 to 2000 to speed up test...
+  private final static int INDEX_SIZE = 2000 * _TestUtil.getRandomMultiplier();
+  
   /**
-   * Create index and query for test cases. 
+   * Create index and query for test cases.
    */
   @Override
   protected void setUp() throws Exception {
-          super.setUp();
-          index = getIndex();
-          query = new TermQuery( new Term("content", "test"));
+    super.setUp();
+    Random rand = newRandom();
+    index = new RAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(rand, index, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomGen random = new RandomGen(rand);
+    for (int i = 0; i < INDEX_SIZE; ++i) { // don't decrease; if to low the
+                                           // problem doesn't show up
+      Document doc = new Document();
+      if ((i % 5) != 0) { // some documents must not have an entry in the first
+                          // sort field
+        doc.add(new Field("publicationDate_", random.getLuceneDate(),
+            Field.Store.YES, Field.Index.NOT_ANALYZED));
+      }
+      if ((i % 7) == 0) { // some documents to match the query (see below)
+        doc.add(new Field("content", "test", Field.Store.YES,
+            Field.Index.ANALYZED));
+      }
+      // every document has a defined 'mandant' field
+      doc.add(new Field("mandant", Integer.toString(i % 3), Field.Store.YES,
+          Field.Index.NOT_ANALYZED));
+      writer.addDocument(doc);
+    }
+    reader = writer.getReader();
+    writer.close();
+    query = new TermQuery(new Term("content", "test"));
   }
-
+  
+  @Override
+  protected void tearDown() throws Exception {
+    reader.close();
+    index.close();
+    super.tearDown();
+  }
+  
   /**
-   * Run the test using two CustomSearcher instances. 
+   * Run the test using two CustomSearcher instances.
    */
   public void testFieldSortCustomSearcher() throws Exception {
     // log("Run testFieldSortCustomSearcher");
     // define the sort criteria
-      Sort custSort = new Sort(
-              new SortField("publicationDate_", SortField.STRING), 
-              SortField.FIELD_SCORE
-      );
-      Searcher searcher = new CustomSearcher (index, 2);
-      // search and check hits
+    Sort custSort = new Sort(
+        new SortField("publicationDate_", SortField.STRING),
+        SortField.FIELD_SCORE);
+    Searcher searcher = new CustomSearcher(reader, 2);
+    // search and check hits
     matchHits(searcher, custSort);
   }
+  
   /**
-   * Run the test using one CustomSearcher wrapped by a MultiSearcher. 
+   * Run the test using one CustomSearcher wrapped by a MultiSearcher.
    */
   public void testFieldSortSingleSearcher() throws Exception {
     // log("Run testFieldSortSingleSearcher");
     // define the sort criteria
-      Sort custSort = new Sort(
-              new SortField("publicationDate_", SortField.STRING), 
-              SortField.FIELD_SCORE
-      );
-      Searcher searcher = new MultiSearcher(new Searcher[] { new CustomSearcher(
-        index, 2) });
-      // search and check hits
+    Sort custSort = new Sort(
+        new SortField("publicationDate_", SortField.STRING),
+        SortField.FIELD_SCORE);
+    Searcher searcher = new MultiSearcher(new Searcher[] {new CustomSearcher(
+        reader, 2)});
+    // search and check hits
     matchHits(searcher, custSort);
   }
+  
   /**
-   * Run the test using two CustomSearcher instances. 
+   * Run the test using two CustomSearcher instances.
    */
   public void testFieldSortMultiCustomSearcher() throws Exception {
     // log("Run testFieldSortMultiCustomSearcher");
     // define the sort criteria
-      Sort custSort = new Sort(
-              new SortField("publicationDate_", SortField.STRING), 
-              SortField.FIELD_SCORE
-      );
-      Searcher searcher = 
-          new MultiSearcher(new Searchable[] {
-                  new CustomSearcher (index, 0),
-                  new CustomSearcher (index, 2)});
-      // search and check hits
+    Sort custSort = new Sort(
+        new SortField("publicationDate_", SortField.STRING),
+        SortField.FIELD_SCORE);
+    Searcher searcher = new MultiSearcher(new Searchable[] {
+        new CustomSearcher(reader, 0), new CustomSearcher(reader, 2)});
+    // search and check hits
     matchHits(searcher, custSort);
   }
-
-
+  
   // make sure the documents returned by the search match the expected list
-  private void matchHits (Searcher searcher, Sort sort)
-  throws IOException {
-      // make a query without sorting first
+  private void matchHits(Searcher searcher, Sort sort) throws IOException {
+    // make a query without sorting first
     ScoreDoc[] hitsByRank = searcher.search(query, null, Integer.MAX_VALUE).scoreDocs;
     checkHits(hitsByRank, "Sort by rank: "); // check for duplicates
-        Map<Integer,Integer> resultMap = new TreeMap<Integer,Integer>();
-        // store hits in TreeMap - TreeMap does not allow duplicates; existing entries are silently overwritten
-        for(int hitid=0;hitid<hitsByRank.length; ++hitid) {
-            resultMap.put(
-                    Integer.valueOf(hitsByRank[hitid].doc),  // Key:   Lucene Document ID
-                    Integer.valueOf(hitid));				// Value: Hits-Objekt Index
-        }
-        
-        // now make a query using the sort criteria
-    ScoreDoc[] resultSort = searcher.search (query, null, Integer.MAX_VALUE, sort).scoreDocs;
+    Map<Integer,Integer> resultMap = new TreeMap<Integer,Integer>();
+    // store hits in TreeMap - TreeMap does not allow duplicates; existing
+    // entries are silently overwritten
+    for (int hitid = 0; hitid < hitsByRank.length; ++hitid) {
+      resultMap.put(Integer.valueOf(hitsByRank[hitid].doc), // Key: Lucene
+                                                            // Document ID
+          Integer.valueOf(hitid)); // Value: Hits-Objekt Index
+    }
+    
+    // now make a query using the sort criteria
+    ScoreDoc[] resultSort = searcher.search(query, null, Integer.MAX_VALUE,
+        sort).scoreDocs;
     checkHits(resultSort, "Sort by custom criteria: "); // check for duplicates
     
-        // besides the sorting both sets of hits must be identical
-        for(int hitid=0;hitid<resultSort.length; ++hitid) {
-            Integer idHitDate = Integer.valueOf(resultSort[hitid].doc); // document ID from sorted search
-            if(!resultMap.containsKey(idHitDate)) {
-                log("ID "+idHitDate+" not found. Possibliy a duplicate.");
-            }
-            assertTrue(resultMap.containsKey(idHitDate)); // same ID must be in the Map from the rank-sorted search
-            // every hit must appear once in both result sets --> remove it from the Map.
-            // At the end the Map must be empty!
-            resultMap.remove(idHitDate);
-        }
-        if(resultMap.size()==0) {
-            // log("All hits matched");
-        } else {
-        log("Couldn't match "+resultMap.size()+" hits.");
-        }
-        assertEquals(resultMap.size(), 0);
+    // besides the sorting both sets of hits must be identical
+    for (int hitid = 0; hitid < resultSort.length; ++hitid) {
+      Integer idHitDate = Integer.valueOf(resultSort[hitid].doc); // document ID
+                                                                  // from sorted
+                                                                  // search
+      if (!resultMap.containsKey(idHitDate)) {
+        log("ID " + idHitDate + " not found. Possibliy a duplicate.");
+      }
+      assertTrue(resultMap.containsKey(idHitDate)); // same ID must be in the
+                                                    // Map from the rank-sorted
+                                                    // search
+      // every hit must appear once in both result sets --> remove it from the
+      // Map.
+      // At the end the Map must be empty!
+      resultMap.remove(idHitDate);
+    }
+    if (resultMap.size() == 0) {
+      // log("All hits matched");
+    } else {
+      log("Couldn't match " + resultMap.size() + " hits.");
+    }
+    assertEquals(resultMap.size(), 0);
   }
-
+  
   /**
    * Check the hits for duplicates.
+   * 
    * @param hits
    */
-    private void checkHits(ScoreDoc[] hits, String prefix) {
-        if(hits!=null) {
-            Map<Integer,Integer> idMap = new TreeMap<Integer,Integer>();
-            for(int docnum=0;docnum<hits.length;++docnum) {
-                Integer luceneId = null;
-
-                luceneId = Integer.valueOf(hits[docnum].doc);
-                if(idMap.containsKey(luceneId)) {
-                    StringBuilder message = new StringBuilder(prefix);
-                    message.append("Duplicate key for hit index = ");
-                    message.append(docnum);
-                    message.append(", previous index = ");
-                    message.append((idMap.get(luceneId)).toString());
-                    message.append(", Lucene ID = ");
-                    message.append(luceneId);
-                    log(message.toString());
-                } else { 
-                    idMap.put(luceneId, Integer.valueOf(docnum));
-                }
-            }
+  private void checkHits(ScoreDoc[] hits, String prefix) {
+    if (hits != null) {
+      Map<Integer,Integer> idMap = new TreeMap<Integer,Integer>();
+      for (int docnum = 0; docnum < hits.length; ++docnum) {
+        Integer luceneId = null;
+        
+        luceneId = Integer.valueOf(hits[docnum].doc);
+        if (idMap.containsKey(luceneId)) {
+          StringBuilder message = new StringBuilder(prefix);
+          message.append("Duplicate key for hit index = ");
+          message.append(docnum);
+          message.append(", previous index = ");
+          message.append((idMap.get(luceneId)).toString());
+          message.append(", Lucene ID = ");
+          message.append(luceneId);
+          log(message.toString());
+        } else {
+          idMap.put(luceneId, Integer.valueOf(docnum));
         }
+      }
     }
+  }
+  
+  // Simply write to console - choosen to be independant of log4j etc
+  private void log(String message) {
+    if (VERBOSE) System.out.println(message);
+  }
+  
+  public class CustomSearcher extends IndexSearcher {
+    private int switcher;
     
-    // Simply write to console - choosen to be independant of log4j etc 
-    private void log(String message) {
-        if (VERBOSE) System.out.println(message);
+    /**
+     * @param r
+     */
+    public CustomSearcher(IndexReader r, int switcher) {
+      super(r);
+      this.switcher = switcher;
     }
     
-    public class CustomSearcher extends IndexSearcher {
-        private int switcher;
-        /**
-         * @param directory
-         * @throws IOException
-         */
-        public CustomSearcher(Directory directory, int switcher) throws IOException {
-            super(directory, true);
-            this.switcher = switcher;
-        }
-        /**
-         * @param r
-         */
-        public CustomSearcher(IndexReader r, int switcher) {
-            super(r);
-            this.switcher = switcher;
-        }
-        /* (non-Javadoc)
-         * @see org.apache.lucene.search.Searchable#search(org.apache.lucene.search.Query, org.apache.lucene.search.Filter, int, org.apache.lucene.search.Sort)
-         */
-        @Override
-        public TopFieldDocs search(Query query, Filter filter, int nDocs,
-                Sort sort) throws IOException {
-            BooleanQuery bq = new BooleanQuery();
-            bq.add(query, BooleanClause.Occur.MUST);
-            bq.add(new TermQuery(new Term("mandant", Integer.toString(switcher))), BooleanClause.Occur.MUST);
-            return super.search(bq, filter, nDocs, sort);
-        }
-        /* (non-Javadoc)
-         * @see org.apache.lucene.search.Searchable#search(org.apache.lucene.search.Query, org.apache.lucene.search.Filter, int)
-         */
-        @Override
-        public TopDocs search(Query query, Filter filter, int nDocs)
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.lucene.search.Searchable#search(org.apache.lucene.search.Query
+     * , org.apache.lucene.search.Filter, int, org.apache.lucene.search.Sort)
+     */
+    @Override
+    public TopFieldDocs search(Query query, Filter filter, int nDocs, Sort sort)
         throws IOException {
-            BooleanQuery bq = new BooleanQuery();
-            bq.add(query, BooleanClause.Occur.MUST);
-            bq.add(new TermQuery(new Term("mandant", Integer.toString(switcher))), BooleanClause.Occur.MUST);
-            return super.search(bq, filter, nDocs);
-        }
+      BooleanQuery bq = new BooleanQuery();
+      bq.add(query, BooleanClause.Occur.MUST);
+      bq.add(new TermQuery(new Term("mandant", Integer.toString(switcher))),
+          BooleanClause.Occur.MUST);
+      return super.search(bq, filter, nDocs, sort);
     }
-    private class RandomGen {
-      RandomGen(Random random) {
-        this.random = random;
-      }
-      private Random random;
-      private Calendar base = new GregorianCalendar(1980, 1, 1);
-
-      // Just to generate some different Lucene Date strings
-      private String getLuceneDate() {
-        return DateTools.timeToString(base.getTimeInMillis() + random.nextInt() - Integer.MIN_VALUE, DateTools.Resolution.DAY);
-      }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.lucene.search.Searchable#search(org.apache.lucene.search.Query
+     * , org.apache.lucene.search.Filter, int)
+     */
+    @Override
+    public TopDocs search(Query query, Filter filter, int nDocs)
+        throws IOException {
+      BooleanQuery bq = new BooleanQuery();
+      bq.add(query, BooleanClause.Occur.MUST);
+      bq.add(new TermQuery(new Term("mandant", Integer.toString(switcher))),
+          BooleanClause.Occur.MUST);
+      return super.search(bq, filter, nDocs);
     }
+  }
+  
+  private class RandomGen {
+    RandomGen(Random random) {
+      this.random = random;
+    }
+    
+    private Random random;
+    private Calendar base = new GregorianCalendar(1980, 1, 1);
+    
+    // Just to generate some different Lucene Date strings
+    private String getLuceneDate() {
+      return DateTools.timeToString(base.getTimeInMillis() + random.nextInt()
+          - Integer.MIN_VALUE, DateTools.Resolution.DAY);
+    }
+  }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateFilter.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateFilter.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateFilter.java Thu Jul 22 19:34:35 2010
@@ -22,142 +22,157 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.document.DateTools;
 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 java.io.IOException;
 
- /**
-  * DateFilter JUnit tests.
-  *
-  *
-  * @version $Revision$
-  */
+/**
+ * DateFilter JUnit tests.
+ * 
+ * 
+ * @version $Revision$
+ */
 public class TestDateFilter extends LuceneTestCase {
   public TestDateFilter(String name) {
     super(name);
   }
-
-    /**
-     *
-     */
-  public static void testBefore() throws IOException {
+  
+  /**
+   *
+   */
+  public void testBefore() throws IOException {
     // create an index
     RAMDirectory indexStore = new RAMDirectory();
-    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()));
+    
     long now = System.currentTimeMillis();
-
- 	Document doc = new Document();
- 	// add time that is in the past
- 	doc.add(new Field("datefield", DateTools.timeToString(now - 1000, DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NOT_ANALYZED));
- 	doc.add(new Field("body", "Today is a very sunny day in New York City", Field.Store.YES, Field.Index.ANALYZED));
-  	writer.addDocument(doc);
- 	writer.optimize();
-	writer.close();
-
-	IndexSearcher searcher = new IndexSearcher(indexStore, true);
-
-	// filter that should preserve matches
-	//DateFilter df1 = DateFilter.Before("datefield", now);
-    TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND),
-                                      DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), false, true);
-	// filter that should discard matches
-	//DateFilter df2 = DateFilter.Before("datefield", now - 999999);
-    TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.timeToString(0, DateTools.Resolution.MILLISECOND),
-                                      DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), true, false);
-
+    
+    Document doc = new Document();
+    // add time that is in the past
+    doc.add(new Field("datefield", DateTools.timeToString(now - 1000,
+        DateTools.Resolution.MILLISECOND), Field.Store.YES,
+        Field.Index.NOT_ANALYZED));
+    doc.add(new Field("body", "Today is a very sunny day in New York City",
+        Field.Store.YES, Field.Index.ANALYZED));
+    writer.addDocument(doc);
+    
+    IndexReader reader = writer.getReader();
+    writer.close();
+    IndexSearcher searcher = new IndexSearcher(reader);
+    
+    // filter that should preserve matches
+    // DateFilter df1 = DateFilter.Before("datefield", now);
+    TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools
+        .timeToString(now - 2000, DateTools.Resolution.MILLISECOND), DateTools
+        .timeToString(now, DateTools.Resolution.MILLISECOND), false, true);
+    // filter that should discard matches
+    // DateFilter df2 = DateFilter.Before("datefield", now - 999999);
+    TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools
+        .timeToString(0, DateTools.Resolution.MILLISECOND), DateTools
+        .timeToString(now - 2000, DateTools.Resolution.MILLISECOND), true,
+        false);
+    
     // search something that doesn't exist with DateFilter
-	Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
-
-	// search for something that does exists
-	Query query2 = new TermQuery(new Term("body", "sunny"));
-
-  ScoreDoc[] result;
-
-	// ensure that queries return expected results without DateFilter first
-  result = searcher.search(query1, null, 1000).scoreDocs;
-  assertEquals(0, result.length);
-
-  result = searcher.search(query2, null, 1000).scoreDocs;
-  assertEquals(1, result.length);
-
-
-	// run queries with DateFilter
-  result = searcher.search(query1, df1, 1000).scoreDocs;
-  assertEquals(0, result.length);
-
-  result = searcher.search(query1, df2, 1000).scoreDocs;
-  assertEquals(0, result.length);
-
-   result = searcher.search(query2, df1, 1000).scoreDocs;
-   assertEquals(1, result.length);
-
-  result = searcher.search(query2, df2, 1000).scoreDocs;
-  assertEquals(0, result.length);
-    }
-
-    /**
-     *
-     */
-    public static void testAfter()
-	throws IOException
-    {
-	// create an index
-        RAMDirectory indexStore = new RAMDirectory();
-        IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
-
- 	long now = System.currentTimeMillis();
-
- 	Document doc = new Document();
- 	// add time that is in the future
- 	doc.add(new Field("datefield", DateTools.timeToString(now + 888888, DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NOT_ANALYZED));
- 	doc.add(new Field("body", "Today is a very sunny day in New York City", Field.Store.YES, Field.Index.ANALYZED));
-  	writer.addDocument(doc);
- 	writer.optimize();
-	writer.close();
-
-	IndexSearcher searcher = new IndexSearcher(indexStore, true);
-
-	// filter that should preserve matches
-	//DateFilter df1 = DateFilter.After("datefield", now);
-    TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.timeToString(now, DateTools.Resolution.MILLISECOND),
-                                      DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), true, false);
-	// filter that should discard matches
-	//DateFilter df2 = DateFilter.After("datefield", now + 999999);
-    TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND),
-                                          DateTools.timeToString(now + 999999999, DateTools.Resolution.MILLISECOND), false, true);
-
+    Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
+    
+    // search for something that does exists
+    Query query2 = new TermQuery(new Term("body", "sunny"));
+    
+    ScoreDoc[] result;
+    
+    // ensure that queries return expected results without DateFilter first
+    result = searcher.search(query1, null, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    result = searcher.search(query2, null, 1000).scoreDocs;
+    assertEquals(1, result.length);
+    
+    // run queries with DateFilter
+    result = searcher.search(query1, df1, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    result = searcher.search(query1, df2, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    result = searcher.search(query2, df1, 1000).scoreDocs;
+    assertEquals(1, result.length);
+    
+    result = searcher.search(query2, df2, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    reader.close();
+    indexStore.close();
+  }
+  
+  /**
+   *
+   */
+  public void testAfter() throws IOException {
+    // create an index
+    RAMDirectory indexStore = new RAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    
+    long now = System.currentTimeMillis();
+    
+    Document doc = new Document();
+    // add time that is in the future
+    doc.add(new Field("datefield", DateTools.timeToString(now + 888888,
+        DateTools.Resolution.MILLISECOND), Field.Store.YES,
+        Field.Index.NOT_ANALYZED));
+    doc.add(new Field("body", "Today is a very sunny day in New York City",
+        Field.Store.YES, Field.Index.ANALYZED));
+    writer.addDocument(doc);
+    
+    IndexReader reader = writer.getReader();
+    writer.close();
+    IndexSearcher searcher = new IndexSearcher(reader);
+    
+    // filter that should preserve matches
+    // DateFilter df1 = DateFilter.After("datefield", now);
+    TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools
+        .timeToString(now, DateTools.Resolution.MILLISECOND), DateTools
+        .timeToString(now + 999999, DateTools.Resolution.MILLISECOND), true,
+        false);
+    // filter that should discard matches
+    // DateFilter df2 = DateFilter.After("datefield", now + 999999);
+    TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools
+        .timeToString(now + 999999, DateTools.Resolution.MILLISECOND),
+        DateTools.timeToString(now + 999999999,
+            DateTools.Resolution.MILLISECOND), false, true);
+    
     // search something that doesn't exist with DateFilter
-	Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
-
-	// search for something that does exists
-	Query query2 = new TermQuery(new Term("body", "sunny"));
-
-  ScoreDoc[] result;
-
-	// ensure that queries return expected results without DateFilter first
-  result = searcher.search(query1, null, 1000).scoreDocs;
-  assertEquals(0, result.length);
-
-  result = searcher.search(query2, null, 1000).scoreDocs;
-  assertEquals(1, result.length);
-
-
-	// run queries with DateFilter
-  result = searcher.search(query1, df1, 1000).scoreDocs;
-  assertEquals(0, result.length);
-
-  result = searcher.search(query1, df2, 1000).scoreDocs;
-  assertEquals(0, result.length);
-
-   result = searcher.search(query2, df1, 1000).scoreDocs;
-   assertEquals(1, result.length);
-
-  result = searcher.search(query2, df2, 1000).scoreDocs;
-  assertEquals(0, result.length);
-    }
+    Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
+    
+    // search for something that does exists
+    Query query2 = new TermQuery(new Term("body", "sunny"));
+    
+    ScoreDoc[] result;
+    
+    // ensure that queries return expected results without DateFilter first
+    result = searcher.search(query1, null, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    result = searcher.search(query2, null, 1000).scoreDocs;
+    assertEquals(1, result.length);
+    
+    // run queries with DateFilter
+    result = searcher.search(query1, df1, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    result = searcher.search(query1, df2, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    
+    result = searcher.search(query2, df1, 1000).scoreDocs;
+    assertEquals(1, result.length);
+    
+    result = searcher.search(query2, df2, 1000).scoreDocs;
+    assertEquals(0, result.length);
+    reader.close();
+    indexStore.close();
+  }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateSort.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateSort.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDateSort.java Thu Jul 22 19:34:35 2010
@@ -25,8 +25,9 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.document.DateTools;
 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.queryParser.QueryParser;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
@@ -44,14 +45,16 @@ public class TestDateSort extends Lucene
   private static final String TEXT_FIELD = "text";
   private static final String DATE_TIME_FIELD = "dateTime";
 
-  private static Directory directory;
+  private Directory directory;
+  private IndexReader reader;
 
   @Override
   protected void setUp() throws Exception {
     super.setUp();
     // Create an index writer.
     directory = new RAMDirectory();
-    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()));
 
     // oldest doc:
     // Add the first document.  text = "Document 1"  dateTime = Oct 10 03:25:22 EDT 2007
@@ -66,12 +69,19 @@ public class TestDateSort extends Lucene
     // Add the fifth document.  text = "Document 5"  dateTime = Oct 12 13:25:43 EDT 2007
     writer.addDocument(createDocument("Document 5", 1192209943000L));
 
-    writer.optimize();
+    reader = writer.getReader();
     writer.close();
   }
 
+  @Override
+  protected void tearDown() throws Exception {
+    reader.close();
+    directory.close();
+    super.tearDown();
+  }
+
   public void testReverseDateSort() throws Exception {
-    IndexSearcher searcher = new IndexSearcher(directory, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
 
     Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.STRING, true));
 

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java Thu Jul 22 19:34:35 2010
@@ -1,6 +1,5 @@
 package org.apache.lucene.search;
 
-
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -23,8 +22,8 @@ import org.apache.lucene.analysis.MockAn
 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;
@@ -34,456 +33,459 @@ import java.io.IOException;
 
 /**
  * Test of the DisjunctionMaxQuery.
- *
+ * 
  */
-public class TestDisjunctionMaxQuery extends LuceneTestCase{
-
-    /** threshold for comparing floats */
-    public static final float SCORE_COMP_THRESH = 0.0000f;
-
-    /**
-     * Similarity to eliminate tf, idf and lengthNorm effects to
-     * isolate test case.
-     *
-     * <p>
-     * same as TestRankingSimilarity in TestRanking.zip from
-     * http://issues.apache.org/jira/browse/LUCENE-323
-     * </p>
-     */
-    private static class TestSimilarity extends DefaultSimilarity {
-
-        public TestSimilarity() {
-        }
-        @Override
-        public float tf(float freq) {
-            if (freq > 0.0f) return 1.0f;
-            else return 0.0f;
-        }
-        @Override
-        public float lengthNorm(String fieldName, int numTerms) {
-            return 1.0f;
-        }
-        @Override
-        public float idf(int docFreq, int numDocs) {
-            return 1.0f;
-        }
+public class TestDisjunctionMaxQuery extends LuceneTestCase {
+  
+  /** threshold for comparing floats */
+  public static final float SCORE_COMP_THRESH = 0.0000f;
+  
+  /**
+   * Similarity to eliminate tf, idf and lengthNorm effects to isolate test
+   * case.
+   * 
+   * <p>
+   * same as TestRankingSimilarity in TestRanking.zip from
+   * http://issues.apache.org/jira/browse/LUCENE-323
+   * </p>
+   */
+  private static class TestSimilarity extends DefaultSimilarity {
+    
+    public TestSimilarity() {}
+    
+    @Override
+    public float tf(float freq) {
+      if (freq > 0.0f) return 1.0f;
+      else return 0.0f;
     }
-
-    public Similarity sim = new TestSimilarity();
-    public Directory index;
-    public IndexReader r;
-    public IndexSearcher s;
-
+    
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        index = new RAMDirectory();
-        IndexWriter writer = new IndexWriter(index, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setSimilarity(sim));
-
-        // hed is the most important field, dek is secondary
-
-        // d1 is an "ok" match for:  albino elephant
-        {
-            Document d1 = new Document();
-            d1.add(new Field("id", "d1", Field.Store.YES, Field.Index.NOT_ANALYZED));//Field.Keyword("id", "d1"));
-            d1.add(new Field("hed", "elephant", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("hed", "elephant"));
-            d1.add(new Field("dek", "elephant", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("dek", "elephant"));
-            writer.addDocument(d1);
-        }
-
-        // d2 is a "good" match for:  albino elephant
-        {
-            Document d2 = new Document();
-            d2.add(new Field("id", "d2", Field.Store.YES, Field.Index.NOT_ANALYZED));//Field.Keyword("id", "d2"));
-            d2.add(new Field("hed", "elephant", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("hed", "elephant"));
-            d2.add(new Field("dek", "albino", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("dek", "albino"));
-            d2.add(new Field("dek", "elephant", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("dek", "elephant"));
-            writer.addDocument(d2);
-        }
-
-        // d3 is a "better" match for:  albino elephant
-        {
-            Document d3 = new Document();
-            d3.add(new Field("id", "d3", Field.Store.YES, Field.Index.NOT_ANALYZED));//Field.Keyword("id", "d3"));
-            d3.add(new Field("hed", "albino", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("hed", "albino"));
-            d3.add(new Field("hed", "elephant", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("hed", "elephant"));
-            writer.addDocument(d3);
-        }
-
-        // d4 is the "best" match for:  albino elephant
-        {
-            Document d4 = new Document();
-            d4.add(new Field("id", "d4", Field.Store.YES, Field.Index.NOT_ANALYZED));//Field.Keyword("id", "d4"));
-            d4.add(new Field("hed", "albino", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("hed", "albino"));
-            d4.add(new Field("hed", "elephant", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("hed", "elephant"));
-            d4.add(new Field("dek", "albino", Field.Store.YES, Field.Index.ANALYZED));//Field.Text("dek", "albino"));
-            writer.addDocument(d4);
-        }
-
-        writer.close();
-
-        r = IndexReader.open(index, true);
-        s = new IndexSearcher(r);
-        s.setSimilarity(sim);
+    public float lengthNorm(String fieldName, int numTerms) {
+      return 1.0f;
     }
-
+    
+    @Override
+    public float idf(int docFreq, int numDocs) {
+      return 1.0f;
+    }
+  }
+  
+  public Similarity sim = new TestSimilarity();
+  public Directory index;
+  public IndexReader r;
+  public IndexSearcher s;
+  
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    
+    index = new RAMDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(newRandom(), index,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
+            .setSimilarity(sim));
+    
+    // hed is the most important field, dek is secondary
+    
+    // d1 is an "ok" match for: albino elephant
+    {
+      Document d1 = new Document();
+      d1.add(new Field("id", "d1", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
+                                                                               // "d1"));
+      d1
+          .add(new Field("hed", "elephant", Field.Store.YES,
+              Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
+      d1
+          .add(new Field("dek", "elephant", Field.Store.YES,
+              Field.Index.ANALYZED));// Field.Text("dek", "elephant"));
+      writer.addDocument(d1);
+    }
+    
+    // d2 is a "good" match for: albino elephant
+    {
+      Document d2 = new Document();
+      d2.add(new Field("id", "d2", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
+                                                                               // "d2"));
+      d2
+          .add(new Field("hed", "elephant", Field.Store.YES,
+              Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
+      d2.add(new Field("dek", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("dek",
+                                                                                // "albino"));
+      d2
+          .add(new Field("dek", "elephant", Field.Store.YES,
+              Field.Index.ANALYZED));// Field.Text("dek", "elephant"));
+      writer.addDocument(d2);
+    }
+    
+    // d3 is a "better" match for: albino elephant
+    {
+      Document d3 = new Document();
+      d3.add(new Field("id", "d3", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
+                                                                               // "d3"));
+      d3.add(new Field("hed", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("hed",
+                                                                                // "albino"));
+      d3
+          .add(new Field("hed", "elephant", Field.Store.YES,
+              Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
+      writer.addDocument(d3);
+    }
+    
+    // d4 is the "best" match for: albino elephant
+    {
+      Document d4 = new Document();
+      d4.add(new Field("id", "d4", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
+                                                                               // "d4"));
+      d4.add(new Field("hed", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("hed",
+                                                                                // "albino"));
+      d4
+          .add(new Field("hed", "elephant", Field.Store.YES,
+              Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
+      d4.add(new Field("dek", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("dek",
+                                                                                // "albino"));
+      writer.addDocument(d4);
+    }
+    
+    r = writer.getReader();
+    writer.close();
+    s = new IndexSearcher(r);
+    s.setSimilarity(sim);
+  }
+  
+  @Override
+  protected void tearDown() throws Exception {
+    s.close();
+    r.close();
+    index.close();
+    super.tearDown();
+  }
+  
   public void testSkipToFirsttimeMiss() throws IOException {
     final DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f);
-    dq.add(tq("id","d1"));
-    dq.add(tq("dek","DOES_NOT_EXIST"));
-
-    QueryUtils.check(dq,s);
-
+    dq.add(tq("id", "d1"));
+    dq.add(tq("dek", "DOES_NOT_EXIST"));
+    
+    QueryUtils.check(dq, s);
+    
     final Weight dw = dq.weight(s);
     final Scorer ds = dw.scorer(r, true, false);
     final boolean skipOk = ds.advance(3) != DocIdSetIterator.NO_MORE_DOCS;
     if (skipOk) {
-      fail("firsttime skipTo found a match? ... " + r.document(ds.docID()).get("id"));
+      fail("firsttime skipTo found a match? ... "
+          + r.document(ds.docID()).get("id"));
     }
   }
-
+  
   public void testSkipToFirsttimeHit() throws IOException {
     final DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f);
-    dq.add(tq("dek","albino"));
-    dq.add(tq("dek","DOES_NOT_EXIST"));
-
-    QueryUtils.check(dq,s);
-
+    dq.add(tq("dek", "albino"));
+    dq.add(tq("dek", "DOES_NOT_EXIST"));
+    
+    QueryUtils.check(dq, s);
+    
     final Weight dw = dq.weight(s);
     final Scorer ds = dw.scorer(r, true, false);
-    assertTrue("firsttime skipTo found no match", ds.advance(3) != DocIdSetIterator.NO_MORE_DOCS);
+    assertTrue("firsttime skipTo found no match",
+        ds.advance(3) != DocIdSetIterator.NO_MORE_DOCS);
     assertEquals("found wrong docid", "d4", r.document(ds.docID()).get("id"));
   }
-
+  
   public void testSimpleEqualScores1() throws Exception {
-
+    
     DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.0f);
-    q.add(tq("hed","albino"));
-    q.add(tq("hed","elephant"));
-    QueryUtils.check(q,s);
-
+    q.add(tq("hed", "albino"));
+    q.add(tq("hed", "elephant"));
+    QueryUtils.check(q, s);
+    
     ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
+    
     try {
-      assertEquals("all docs should match " + q.toString(),
-          4, h.length);
-
+      assertEquals("all docs should match " + q.toString(), 4, h.length);
+      
       float score = h[0].score;
       for (int i = 1; i < h.length; i++) {
-        assertEquals("score #" + i + " is not the same",
-            score, h[i].score, SCORE_COMP_THRESH);
+        assertEquals("score #" + i + " is not the same", score, h[i].score,
+            SCORE_COMP_THRESH);
       }
     } catch (Error e) {
-      printHits("testSimpleEqualScores1",h,s);
+      printHits("testSimpleEqualScores1", h, s);
       throw e;
     }
-
+    
   }
-
-    public void testSimpleEqualScores2() throws Exception {
-
-        DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.0f);
-        q.add(tq("dek","albino"));
-        q.add(tq("dek","elephant"));
-        QueryUtils.check(q,s);
-
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-            assertEquals("3 docs should match " + q.toString(),
-                         3, h.length);
-            float score = h[0].score;
-            for (int i = 1; i < h.length; i++) {
-                assertEquals("score #" + i + " is not the same",
-                             score, h[i].score, SCORE_COMP_THRESH);
-            }
-        } catch (Error e) {
-            printHits("testSimpleEqualScores2",h, s);
-            throw e;
-        }
-
+  
+  public void testSimpleEqualScores2() throws Exception {
+    
+    DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.0f);
+    q.add(tq("dek", "albino"));
+    q.add(tq("dek", "elephant"));
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      assertEquals("3 docs should match " + q.toString(), 3, h.length);
+      float score = h[0].score;
+      for (int i = 1; i < h.length; i++) {
+        assertEquals("score #" + i + " is not the same", score, h[i].score,
+            SCORE_COMP_THRESH);
+      }
+    } catch (Error e) {
+      printHits("testSimpleEqualScores2", h, s);
+      throw e;
     }
-
-    public void testSimpleEqualScores3() throws Exception {
-
-        DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.0f);
-        q.add(tq("hed","albino"));
-        q.add(tq("hed","elephant"));
-        q.add(tq("dek","albino"));
-        q.add(tq("dek","elephant"));
-        QueryUtils.check(q,s);
-
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-            assertEquals("all docs should match " + q.toString(),
-                         4, h.length);
-            float score = h[0].score;
-            for (int i = 1; i < h.length; i++) {
-                assertEquals("score #" + i + " is not the same",
-                             score, h[i].score, SCORE_COMP_THRESH);
-            }
-        } catch (Error e) {
-            printHits("testSimpleEqualScores3",h, s);
-            throw e;
-        }
-
+    
+  }
+  
+  public void testSimpleEqualScores3() throws Exception {
+    
+    DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.0f);
+    q.add(tq("hed", "albino"));
+    q.add(tq("hed", "elephant"));
+    q.add(tq("dek", "albino"));
+    q.add(tq("dek", "elephant"));
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      assertEquals("all docs should match " + q.toString(), 4, h.length);
+      float score = h[0].score;
+      for (int i = 1; i < h.length; i++) {
+        assertEquals("score #" + i + " is not the same", score, h[i].score,
+            SCORE_COMP_THRESH);
+      }
+    } catch (Error e) {
+      printHits("testSimpleEqualScores3", h, s);
+      throw e;
     }
-
-    public void testSimpleTiebreaker() throws Exception {
-
-        DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.01f);
-        q.add(tq("dek","albino"));
-        q.add(tq("dek","elephant"));
-        QueryUtils.check(q,s);
-
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-            assertEquals("3 docs should match " + q.toString(),
-                         3, h.length);
-            assertEquals("wrong first",  "d2", s.doc(h[0].doc).get("id"));
-            float score0 = h[0].score;
-            float score1 = h[1].score;
-            float score2 = h[2].score;
-            assertTrue("d2 does not have better score then others: " +
-                       score0 + " >? " + score1,
-                       score0 > score1);
-            assertEquals("d4 and d1 don't have equal scores",
-                         score1, score2, SCORE_COMP_THRESH);
-        } catch (Error e) {
-            printHits("testSimpleTiebreaker",h, s);
-            throw e;
-        }
+    
+  }
+  
+  public void testSimpleTiebreaker() throws Exception {
+    
+    DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.01f);
+    q.add(tq("dek", "albino"));
+    q.add(tq("dek", "elephant"));
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      assertEquals("3 docs should match " + q.toString(), 3, h.length);
+      assertEquals("wrong first", "d2", s.doc(h[0].doc).get("id"));
+      float score0 = h[0].score;
+      float score1 = h[1].score;
+      float score2 = h[2].score;
+      assertTrue("d2 does not have better score then others: " + score0
+          + " >? " + score1, score0 > score1);
+      assertEquals("d4 and d1 don't have equal scores", score1, score2,
+          SCORE_COMP_THRESH);
+    } catch (Error e) {
+      printHits("testSimpleTiebreaker", h, s);
+      throw e;
     }
-
-    public void testBooleanRequiredEqualScores() throws Exception {
-
-        BooleanQuery q = new BooleanQuery();
-        {
-            DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
-            q1.add(tq("hed","albino"));
-            q1.add(tq("dek","albino"));
-            q.add(q1,BooleanClause.Occur.MUST);//true,false);
-            QueryUtils.check(q1,s);
-
-        }
-        {
-            DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
-            q2.add(tq("hed","elephant"));
-            q2.add(tq("dek","elephant"));
-            q.add(q2, BooleanClause.Occur.MUST);//true,false);
-           QueryUtils.check(q2,s);
-        }
-
-        QueryUtils.check(q,s);
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-            assertEquals("3 docs should match " + q.toString(),
-                         3, h.length);
-            float score = h[0].score;
-            for (int i = 1; i < h.length; i++) {
-                assertEquals("score #" + i + " is not the same",
-                             score, h[i].score, SCORE_COMP_THRESH);
-            }
-        } catch (Error e) {
-            printHits("testBooleanRequiredEqualScores1",h, s);
-            throw e;
-        }
+  }
+  
+  public void testBooleanRequiredEqualScores() throws Exception {
+    
+    BooleanQuery q = new BooleanQuery();
+    {
+      DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
+      q1.add(tq("hed", "albino"));
+      q1.add(tq("dek", "albino"));
+      q.add(q1, BooleanClause.Occur.MUST);// true,false);
+      QueryUtils.check(q1, s);
+      
+    }
+    {
+      DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
+      q2.add(tq("hed", "elephant"));
+      q2.add(tq("dek", "elephant"));
+      q.add(q2, BooleanClause.Occur.MUST);// true,false);
+      QueryUtils.check(q2, s);
+    }
+    
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      assertEquals("3 docs should match " + q.toString(), 3, h.length);
+      float score = h[0].score;
+      for (int i = 1; i < h.length; i++) {
+        assertEquals("score #" + i + " is not the same", score, h[i].score,
+            SCORE_COMP_THRESH);
+      }
+    } catch (Error e) {
+      printHits("testBooleanRequiredEqualScores1", h, s);
+      throw e;
     }
-
-
-    public void testBooleanOptionalNoTiebreaker() throws Exception {
-
-        BooleanQuery q = new BooleanQuery();
-        {
-            DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
-            q1.add(tq("hed","albino"));
-            q1.add(tq("dek","albino"));
-            q.add(q1, BooleanClause.Occur.SHOULD);//false,false);
-        }
-        {
-            DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
-            q2.add(tq("hed","elephant"));
-            q2.add(tq("dek","elephant"));
-            q.add(q2, BooleanClause.Occur.SHOULD);//false,false);
-        }
-        QueryUtils.check(q,s);
-
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-            assertEquals("4 docs should match " + q.toString(),
-                         4, h.length);
-            float score = h[0].score;
-            for (int i = 1; i < h.length-1; i++) { /* note: -1 */
-                assertEquals("score #" + i + " is not the same",
-                             score, h[i].score, SCORE_COMP_THRESH);
-            }
-            assertEquals("wrong last", "d1", s.doc(h[h.length-1].doc).get("id"));
-            float score1 = h[h.length-1].score;
-            assertTrue("d1 does not have worse score then others: " +
-                       score + " >? " + score1,
-                       score > score1);
-        } catch (Error e) {
-            printHits("testBooleanOptionalNoTiebreaker",h, s);
-            throw e;
-        }
+  }
+  
+  public void testBooleanOptionalNoTiebreaker() throws Exception {
+    
+    BooleanQuery q = new BooleanQuery();
+    {
+      DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
+      q1.add(tq("hed", "albino"));
+      q1.add(tq("dek", "albino"));
+      q.add(q1, BooleanClause.Occur.SHOULD);// false,false);
+    }
+    {
+      DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
+      q2.add(tq("hed", "elephant"));
+      q2.add(tq("dek", "elephant"));
+      q.add(q2, BooleanClause.Occur.SHOULD);// false,false);
     }
-
-
-    public void testBooleanOptionalWithTiebreaker() throws Exception {
-
-        BooleanQuery q = new BooleanQuery();
-        {
-            DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
-            q1.add(tq("hed","albino"));
-            q1.add(tq("dek","albino"));
-            q.add(q1, BooleanClause.Occur.SHOULD);//false,false);
-        }
-        {
-            DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
-            q2.add(tq("hed","elephant"));
-            q2.add(tq("dek","elephant"));
-            q.add(q2, BooleanClause.Occur.SHOULD);//false,false);
-        }
-        QueryUtils.check(q,s);
-
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-
-            assertEquals("4 docs should match " + q.toString(),
-                         4, h.length);
-
-            float score0 = h[0].score;
-            float score1 = h[1].score;
-            float score2 = h[2].score;
-            float score3 = h[3].score;
-
-            String doc0 = s.doc(h[0].doc).get("id");
-            String doc1 = s.doc(h[1].doc).get("id");
-            String doc2 = s.doc(h[2].doc).get("id");
-            String doc3 = s.doc(h[3].doc).get("id");            
-
-            assertTrue("doc0 should be d2 or d4: " + doc0,
-                       doc0.equals("d2") || doc0.equals("d4"));
-            assertTrue("doc1 should be d2 or d4: " + doc0,
-                       doc1.equals("d2") || doc1.equals("d4"));
-            assertEquals("score0 and score1 should match",
-                         score0, score1, SCORE_COMP_THRESH);
-            assertEquals("wrong third", "d3", doc2);
-            assertTrue("d3 does not have worse score then d2 and d4: " +
-                       score1 + " >? " + score2,
-                       score1 > score2);
-
-            assertEquals("wrong fourth", "d1", doc3);
-            assertTrue("d1 does not have worse score then d3: " +
-                       score2 + " >? " + score3,
-                       score2 > score3);
-
-        } catch (Error e) {
-            printHits("testBooleanOptionalWithTiebreaker",h, s);
-            throw e;
-        }
-
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      assertEquals("4 docs should match " + q.toString(), 4, h.length);
+      float score = h[0].score;
+      for (int i = 1; i < h.length - 1; i++) { /* note: -1 */
+        assertEquals("score #" + i + " is not the same", score, h[i].score,
+            SCORE_COMP_THRESH);
+      }
+      assertEquals("wrong last", "d1", s.doc(h[h.length - 1].doc).get("id"));
+      float score1 = h[h.length - 1].score;
+      assertTrue("d1 does not have worse score then others: " + score + " >? "
+          + score1, score > score1);
+    } catch (Error e) {
+      printHits("testBooleanOptionalNoTiebreaker", h, s);
+      throw e;
     }
-
-
-    public void testBooleanOptionalWithTiebreakerAndBoost() throws Exception {
-
-        BooleanQuery q = new BooleanQuery();
-        {
-            DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
-            q1.add(tq("hed","albino", 1.5f));
-            q1.add(tq("dek","albino"));
-            q.add(q1, BooleanClause.Occur.SHOULD);//false,false);
-        }
-        {
-            DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
-            q2.add(tq("hed","elephant", 1.5f));
-            q2.add(tq("dek","elephant"));
-            q.add(q2, BooleanClause.Occur.SHOULD);//false,false);
-        }
-        QueryUtils.check(q,s);
-
-
-        ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
-
-        try {
-
-            assertEquals("4 docs should match " + q.toString(),
-                         4, h.length);
-
-            float score0 = h[0].score;
-            float score1 = h[1].score;
-            float score2 = h[2].score;
-            float score3 = h[3].score;
-
-            String doc0 = s.doc(h[0].doc).get("id");
-            String doc1 = s.doc(h[1].doc).get("id");
-            String doc2 = s.doc(h[2].doc).get("id");
-            String doc3 = s.doc(h[3].doc).get("id");            
-
-            assertEquals("doc0 should be d4: ", "d4", doc0);
-            assertEquals("doc1 should be d3: ", "d3", doc1);
-            assertEquals("doc2 should be d2: ", "d2", doc2);
-            assertEquals("doc3 should be d1: ", "d1", doc3);
-
-            assertTrue("d4 does not have a better score then d3: " +
-                       score0 + " >? " + score1,
-                       score0 > score1);
-            assertTrue("d3 does not have a better score then d2: " +
-                       score1 + " >? " + score2,
-                       score1 > score2);
-            assertTrue("d3 does not have a better score then d1: " +
-                       score2 + " >? " + score3,
-                       score2 > score3);
-
-        } catch (Error e) {
-            printHits("testBooleanOptionalWithTiebreakerAndBoost",h, s);
-            throw e;
-        }
+  }
+  
+  public void testBooleanOptionalWithTiebreaker() throws Exception {
+    
+    BooleanQuery q = new BooleanQuery();
+    {
+      DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
+      q1.add(tq("hed", "albino"));
+      q1.add(tq("dek", "albino"));
+      q.add(q1, BooleanClause.Occur.SHOULD);// false,false);
+    }
+    {
+      DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
+      q2.add(tq("hed", "elephant"));
+      q2.add(tq("dek", "elephant"));
+      q.add(q2, BooleanClause.Occur.SHOULD);// false,false);
     }
-
-
-
-
-
-
-
-    /** macro */
-    protected Query tq(String f, String t) {
-        return new TermQuery(new Term(f, t));
-    }
-    /** macro */
-    protected Query tq(String f, String t, float b) {
-        Query q = tq(f,t);
-        q.setBoost(b);
-        return q;
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      
+      assertEquals("4 docs should match " + q.toString(), 4, h.length);
+      
+      float score0 = h[0].score;
+      float score1 = h[1].score;
+      float score2 = h[2].score;
+      float score3 = h[3].score;
+      
+      String doc0 = s.doc(h[0].doc).get("id");
+      String doc1 = s.doc(h[1].doc).get("id");
+      String doc2 = s.doc(h[2].doc).get("id");
+      String doc3 = s.doc(h[3].doc).get("id");
+      
+      assertTrue("doc0 should be d2 or d4: " + doc0, doc0.equals("d2")
+          || doc0.equals("d4"));
+      assertTrue("doc1 should be d2 or d4: " + doc0, doc1.equals("d2")
+          || doc1.equals("d4"));
+      assertEquals("score0 and score1 should match", score0, score1,
+          SCORE_COMP_THRESH);
+      assertEquals("wrong third", "d3", doc2);
+      assertTrue("d3 does not have worse score then d2 and d4: " + score1
+          + " >? " + score2, score1 > score2);
+      
+      assertEquals("wrong fourth", "d1", doc3);
+      assertTrue("d1 does not have worse score then d3: " + score2 + " >? "
+          + score3, score2 > score3);
+      
+    } catch (Error e) {
+      printHits("testBooleanOptionalWithTiebreaker", h, s);
+      throw e;
     }
-
-
-    protected void printHits(String test, ScoreDoc[] h, Searcher searcher) throws Exception {
-
-        System.err.println("------- " + test + " -------");
-
-        DecimalFormat f = new DecimalFormat("0.000000000");
-
-        for (int i = 0; i < h.length; i++) {
-            Document d = searcher.doc(h[i].doc);
-            float score = h[i].score;
-            System.err.println("#" + i + ": " + f.format(score) + " - " +
-                               d.get("id"));
-        }
+    
+  }
+  
+  public void testBooleanOptionalWithTiebreakerAndBoost() throws Exception {
+    
+    BooleanQuery q = new BooleanQuery();
+    {
+      DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
+      q1.add(tq("hed", "albino", 1.5f));
+      q1.add(tq("dek", "albino"));
+      q.add(q1, BooleanClause.Occur.SHOULD);// false,false);
+    }
+    {
+      DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
+      q2.add(tq("hed", "elephant", 1.5f));
+      q2.add(tq("dek", "elephant"));
+      q.add(q2, BooleanClause.Occur.SHOULD);// false,false);
     }
-
+    QueryUtils.check(q, s);
+    
+    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
+    
+    try {
+      
+      assertEquals("4 docs should match " + q.toString(), 4, h.length);
+      
+      float score0 = h[0].score;
+      float score1 = h[1].score;
+      float score2 = h[2].score;
+      float score3 = h[3].score;
+      
+      String doc0 = s.doc(h[0].doc).get("id");
+      String doc1 = s.doc(h[1].doc).get("id");
+      String doc2 = s.doc(h[2].doc).get("id");
+      String doc3 = s.doc(h[3].doc).get("id");
+      
+      assertEquals("doc0 should be d4: ", "d4", doc0);
+      assertEquals("doc1 should be d3: ", "d3", doc1);
+      assertEquals("doc2 should be d2: ", "d2", doc2);
+      assertEquals("doc3 should be d1: ", "d1", doc3);
+      
+      assertTrue("d4 does not have a better score then d3: " + score0 + " >? "
+          + score1, score0 > score1);
+      assertTrue("d3 does not have a better score then d2: " + score1 + " >? "
+          + score2, score1 > score2);
+      assertTrue("d3 does not have a better score then d1: " + score2 + " >? "
+          + score3, score2 > score3);
+      
+    } catch (Error e) {
+      printHits("testBooleanOptionalWithTiebreakerAndBoost", h, s);
+      throw e;
+    }
+  }
+  
+  /** macro */
+  protected Query tq(String f, String t) {
+    return new TermQuery(new Term(f, t));
+  }
+  
+  /** macro */
+  protected Query tq(String f, String t, float b) {
+    Query q = tq(f, t);
+    q.setBoost(b);
+    return q;
+  }
+  
+  protected void printHits(String test, ScoreDoc[] h, Searcher searcher)
+      throws Exception {
+    
+    System.err.println("------- " + test + " -------");
+    
+    DecimalFormat f = new DecimalFormat("0.000000000");
+    
+    for (int i = 0; i < h.length; i++) {
+      Document d = searcher.doc(h[i].doc);
+      float score = h[i].score;
+      System.err
+          .println("#" + i + ": " + f.format(score) + " - " + d.get("id"));
+    }
+  }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocBoost.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocBoost.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocBoost.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocBoost.java Thu Jul 22 19:34:35 2010
@@ -23,8 +23,8 @@ import org.apache.lucene.util.LuceneTest
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.*;
 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.RAMDirectory;
 
@@ -40,8 +40,8 @@ public class TestDocBoost extends Lucene
 
   public void testDocBoost() 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()));
 
     Fieldable f1 = new Field("field", "word", Field.Store.YES, Field.Index.ANALYZED);
     Fieldable f2 = new Field("field", "word", Field.Store.YES, Field.Index.ANALYZED);
@@ -63,12 +63,13 @@ public class TestDocBoost extends Lucene
     writer.addDocument(d2);
     writer.addDocument(d3);
     writer.addDocument(d4);
-    writer.optimize();
+
+    IndexReader reader = writer.getReader();
     writer.close();
 
     final float[] scores = new float[4];
 
-    new IndexSearcher(store, true).search
+    new IndexSearcher(reader).search
       (new TermQuery(new Term("field", "word")),
        new Collector() {
          private int base = 0;
@@ -97,5 +98,8 @@ public class TestDocBoost extends Lucene
       assertTrue(scores[i] > lastScore);
       lastScore = scores[i];
     }
+    
+    reader.close();
+    store.close();
   }
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java Thu Jul 22 19:34:35 2010
@@ -30,8 +30,8 @@ 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.IndexReader;
-import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
@@ -104,14 +104,16 @@ public class TestDocIdSet extends Lucene
     // Tests that if a Filter produces a null DocIdSet, which is given to
     // IndexSearcher, everything works fine. This came up in LUCENE-1754.
     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("c", "val", Store.NO, Index.NOT_ANALYZED_NO_NORMS));
     writer.addDocument(doc);
+    IndexReader reader = writer.getReader();
     writer.close();
     
     // First verify the document is searchable.
-    IndexSearcher searcher = new IndexSearcher(dir, true);
+    IndexSearcher searcher = new IndexSearcher(reader);
     Assert.assertEquals(1, searcher.search(new MatchAllDocsQuery(), 10).totalHits);
     
     // Now search w/ a Filter which returns a null DocIdSet
@@ -124,6 +126,8 @@ public class TestDocIdSet extends Lucene
     
     Assert.assertEquals(0, searcher.search(new MatchAllDocsQuery(), f, 10).totalHits);
     searcher.close();
+    reader.close();
+    dir.close();
   }
 
 }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestExplanations.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestExplanations.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestExplanations.java Thu Jul 22 19:34:35 2010
@@ -22,8 +22,9 @@ import org.apache.lucene.queryParser.Par
 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.spans.SpanFirstQuery;
 import org.apache.lucene.search.spans.SpanNearQuery;
@@ -31,6 +32,7 @@ import org.apache.lucene.search.spans.Sp
 import org.apache.lucene.search.spans.SpanOrQuery;
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -48,7 +50,9 @@ import org.apache.lucene.util.LuceneTest
  */
 public class TestExplanations extends LuceneTestCase {
   protected IndexSearcher searcher;
-
+  protected IndexReader reader;
+  protected Directory directory;
+  
   public static final String KEY = "KEY";
   public static final String FIELD = "field";
   public static final QueryParser qp =
@@ -57,22 +61,26 @@ public class TestExplanations extends Lu
   @Override
   protected void tearDown() throws Exception {
     searcher.close();
+    reader.close();
+    directory.close();
     super.tearDown();
   }
   
   @Override
   protected void setUp() throws Exception {
     super.setUp();
-    RAMDirectory directory = new RAMDirectory();
-    IndexWriter writer= new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    directory = new RAMDirectory();
+    RandomIndexWriter writer= new RandomIndexWriter(newRandom(), directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     for (int i = 0; i < docFields.length; i++) {
       Document doc = new Document();
       doc.add(new Field(KEY, ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));
       doc.add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
       writer.addDocument(doc);
     }
+    reader = writer.getReader();
     writer.close();
-    searcher = new IndexSearcher(directory, true);
+    searcher = new IndexSearcher(reader);
   }
 
   protected String[] docFields = {

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCache.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCache.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCache.java Thu Jul 22 19:34:35 2010
@@ -22,6 +22,8 @@ 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.TermsEnum;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.store.Directory;
@@ -48,7 +50,8 @@ public class TestFieldCache extends Luce
     Random r = newRandom();
     NUM_DOCS = 1000 * _TestUtil.getRandomMultiplier();
     RAMDirectory directory = new RAMDirectory();
-    IndexWriter writer= new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(500));
+    RandomIndexWriter writer= new RandomIndexWriter(r, directory, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     long theLong = Long.MAX_VALUE;
     double theDouble = Double.MAX_VALUE;
     byte theByte = Byte.MAX_VALUE;
@@ -167,6 +170,20 @@ public class TestFieldCache extends Luce
       final String s = term == null ? null : term.utf8ToString();
       assertTrue("for doc " + i + ": " + s + " does not equal: " + unicodeStrings[i], unicodeStrings[i] == null || unicodeStrings[i].equals(s));
     }
+
+    int nTerms = termsIndex.numOrd();
+    // System.out.println("nTerms="+nTerms);
+
+    TermsEnum tenum = termsIndex.getTermsEnum();
+    BytesRef val = new BytesRef();
+    for (int i=1; i<nTerms; i++) {
+      BytesRef val1 = tenum.next();
+      BytesRef val2 = termsIndex.lookup(i,val);
+      // System.out.println("i="+i);
+      assertEquals(val2, val1);
+    }
+
+
     // test bad field
     termsIndex = cache.getTermsIndex(reader, "bogusfield");
 

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java Thu Jul 22 19:34:35 2010
@@ -40,16 +40,9 @@ import org.apache.lucene.store.RAMDirect
  */
 public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
 
-  public TestFieldCacheRangeFilter(String name) {
-    super(name);
-  }
-  public TestFieldCacheRangeFilter() {
-    super();
-  }
-
   public void testRangeFilterId() throws IOException {
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int medId = ((maxId - minId) / 2);
@@ -133,11 +126,11 @@ public class TestFieldCacheRangeFilter e
 
   public void testFieldCacheRangeFilterRand() throws IOException {
 
-    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();
         
@@ -196,7 +189,7 @@ public class TestFieldCacheRangeFilter e
 
   public void testFieldCacheRangeFilterShorts() throws IOException {
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int numDocs = reader.numDocs();
@@ -285,7 +278,7 @@ public class TestFieldCacheRangeFilter e
   
   public void testFieldCacheRangeFilterInts() throws IOException {
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int numDocs = reader.numDocs();
@@ -375,7 +368,7 @@ public class TestFieldCacheRangeFilter e
   
   public void testFieldCacheRangeFilterLongs() throws IOException {
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int numDocs = reader.numDocs();
@@ -467,7 +460,7 @@ public class TestFieldCacheRangeFilter e
   
   public void testFieldCacheRangeFilterFloats() throws IOException {
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int numDocs = reader.numDocs();
@@ -495,7 +488,7 @@ public class TestFieldCacheRangeFilter e
   
   public void testFieldCacheRangeFilterDoubles() throws IOException {
 
-    IndexReader reader = IndexReader.open(signedIndex.index, true);
+    IndexReader reader = signedIndexReader;
     IndexSearcher search = new IndexSearcher(reader);
 
     int numDocs = reader.numDocs();

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java Thu Jul 22 19:34:35 2010
@@ -23,8 +23,8 @@ import org.apache.lucene.analysis.MockAn
 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.store.MockRAMDirectory;
 
 import java.util.ArrayList;
@@ -39,16 +39,17 @@ public class TestFieldCacheTermsFilter e
   public void testMissingTerms() throws Exception {
     String fieldName = "field1";
     MockRAMDirectory rd = new MockRAMDirectory();
-    IndexWriter w = new IndexWriter(rd, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
+    RandomIndexWriter w = new RandomIndexWriter(newRandom(), rd, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
     for (int i = 0; i < 100; i++) {
       Document doc = new Document();
       int term = i * 10; //terms are units of 10;
       doc.add(new Field(fieldName, "" + term, Field.Store.YES, Field.Index.NOT_ANALYZED));
       w.addDocument(doc);
     }
+    IndexReader reader = w.getReader();
     w.close();
 
-    IndexReader reader = IndexReader.open(rd, true);
     IndexSearcher searcher = new IndexSearcher(reader);
     int numDocs = reader.numDocs();
     ScoreDoc[] results;

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java Thu Jul 22 19:34:35 2010
@@ -20,9 +20,9 @@ package org.apache.lucene.search;
 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.BooleanClause.Occur;
 import org.apache.lucene.store.RAMDirectory;
@@ -41,6 +41,7 @@ import java.util.BitSet;
 public class TestFilteredQuery extends LuceneTestCase {
 
   private IndexSearcher searcher;
+  private IndexReader reader;
   private RAMDirectory directory;
   private Query query;
   private Filter filter;
@@ -49,7 +50,8 @@ public class TestFilteredQuery extends L
   protected void setUp() throws Exception {
     super.setUp();
     directory = new RAMDirectory();
-    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()));
 
     Document doc = new Document();
     doc.add (new Field("field", "one two three four five", Field.Store.YES, Field.Index.ANALYZED));
@@ -71,10 +73,10 @@ public class TestFilteredQuery extends L
     doc.add (new Field("sorter", "c", 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 TermQuery (new Term ("field", "three"));
     filter = newStaticFilterB();
   }
@@ -95,6 +97,7 @@ public class TestFilteredQuery extends L
   @Override
   protected void tearDown() throws Exception {
     searcher.close();
+    reader.close();
     directory.close();
     super.tearDown();
   }

Modified: lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java?rev=966819&r1=966818&r2=966819&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java (original)
+++ lucene/dev/branches/realtime_search/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java Thu Jul 22 19:34:35 2010
@@ -25,8 +25,8 @@ import org.apache.lucene.analysis.MockAn
 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.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
@@ -42,7 +42,8 @@ public class TestFuzzyQuery extends Luce
 
   public void testFuzziness() throws Exception {
     RAMDirectory directory = new RAMDirectory();
-    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()));
     addDoc("aaaaa", writer);
     addDoc("aaaab", writer);
     addDoc("aaabb", writer);
@@ -50,9 +51,10 @@ public class TestFuzzyQuery extends Luce
     addDoc("abbbb", writer);
     addDoc("bbbbb", writer);
     addDoc("ddddd", writer);
-    writer.optimize();
+
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
     writer.close();
-    IndexSearcher searcher = new IndexSearcher(directory, true);
 
     FuzzyQuery query = new FuzzyQuery(new Term("field", "aaaaa"), FuzzyQuery.defaultMinSimilarity, 0);   
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
@@ -188,17 +190,20 @@ public class TestFuzzyQuery extends Luce
     assertEquals(0, hits.length);
 
     searcher.close();
+    reader.close();
     directory.close();
   }
 
   public void testFuzzinessLong() throws Exception {
     RAMDirectory directory = new RAMDirectory();
-    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()));
     addDoc("aaaaaaa", writer);
     addDoc("segment", writer);
-    writer.optimize();
+
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
     writer.close();
-    IndexSearcher searcher = new IndexSearcher(directory, true);
 
     FuzzyQuery query;
     // not similar enough:
@@ -276,17 +281,20 @@ public class TestFuzzyQuery extends Luce
     }
 
     searcher.close();
+    reader.close();
     directory.close();
   }
   
   public void testTokenLengthOpt() throws IOException {
     RAMDirectory directory = new RAMDirectory();
-    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()));
     addDoc("12345678911", writer);
     addDoc("segment", writer);
-    writer.optimize();
+
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
     writer.close();
-    IndexSearcher searcher = new IndexSearcher(directory, true);
 
     Query query;
     // term not over 10 chars, so optimization shortcuts
@@ -308,20 +316,25 @@ public class TestFuzzyQuery extends Luce
     query = new FuzzyQuery(new Term("field", "sdfsdfsdfsdf"), 0.9f);
     hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(0, hits.length);
+    
+    searcher.close();
+    reader.close();
+    directory.close();
   }
   
   /** Test the TopTermsBoostOnlyBooleanQueryRewrite rewrite method. */
   public void testBoostOnlyRewrite() throws Exception {
     RAMDirectory directory = new RAMDirectory();
-    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()));
     addDoc("Lucene", writer);
     addDoc("Lucene", writer);
     addDoc("Lucenne", writer);
-    writer.optimize();
+
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
     writer.close();
-    IndexSearcher searcher = new IndexSearcher(directory, true);
-    IndexReader reader = searcher.getIndexReader();
+    
     FuzzyQuery query = new FuzzyQuery(new Term("field", "Lucene"));
     query.setRewriteMethod(new MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite());
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
@@ -332,6 +345,7 @@ public class TestFuzzyQuery extends Luce
     assertEquals("Lucenne", reader.document(hits[2].doc).get("field"));
     searcher.close();
     reader.close();
+    directory.close();
   }
   
   public void testGiga() throws Exception {
@@ -339,8 +353,8 @@ public class TestFuzzyQuery extends Luce
     MockAnalyzer analyzer = new MockAnalyzer();
 
     Directory index = new MockRAMDirectory();
-    IndexWriter w = new IndexWriter(index, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, analyzer));
+    RandomIndexWriter w = new RandomIndexWriter(newRandom(), index, 
+        new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
 
     addDoc("Lucene in Action", w);
     addDoc("Lucene for Dummies", w);
@@ -369,18 +383,14 @@ public class TestFuzzyQuery extends Luce
     ScoreDoc[] hits = searcher.search(q, 10).scoreDocs;
     assertEquals(1, hits.length);
     assertEquals("Giga byte", searcher.doc(hits[0].doc).get("field"));
+    searcher.close();
     r.close();
+    index.close();
   }
 
-  private void addDoc(String text, IndexWriter writer) throws IOException {
+  private void addDoc(String text, RandomIndexWriter writer) throws IOException {
     Document doc = new Document();
     doc.add(new Field("field", text, Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
   }
-  
-  @Deprecated
-  public void testBackwardsLayer() {
-    assertTrue(new FuzzyQuery(new Term("dummy", "dummy")).hasNewAPI);
-  }
-
 }



Mime
View raw message