lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1475920 - /lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java
Date Thu, 25 Apr 2013 19:27:06 GMT
Author: mikemccand
Date: Thu Apr 25 19:27:05 2013
New Revision: 1475920

URL: http://svn.apache.org/r1475920
Log:
fix test bug

Modified:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java?rev=1475920&r1=1475919&r2=1475920&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java
Thu Apr 25 19:27:05 2013
@@ -51,8 +51,6 @@ public class TestFilteredSearch extends 
     searchFiltered(writer, directory, filter, enforceSingleSegment);
     // run the test on more than one segment
     enforceSingleSegment = false;
-    // reset - it is stateful
-    filter.reset();
     writer.close();
     writer = new IndexWriter(directory, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(10).setMergePolicy(newLogMergePolicy()));
     // we index 60 docs - this will create 6 segments
@@ -61,37 +59,30 @@ public class TestFilteredSearch extends 
     directory.close();
   }
 
-  public void searchFiltered(IndexWriter writer, Directory directory, Filter filter, boolean
fullMerge) {
-    try {
-      for (int i = 0; i < 60; i++) {//Simple docs
-        Document doc = new Document();
-        doc.add(newStringField(FIELD, Integer.toString(i), Field.Store.YES));
-        writer.addDocument(doc);
-      }
-      if (fullMerge) {
-        writer.forceMerge(1);
-      }
-      writer.close();
+  public void searchFiltered(IndexWriter writer, Directory directory, Filter filter, boolean
fullMerge) throws IOException {
+    for (int i = 0; i < 60; i++) {//Simple docs
+      Document doc = new Document();
+      doc.add(newStringField(FIELD, Integer.toString(i), Field.Store.YES));
+      writer.addDocument(doc);
+    }
+    if (fullMerge) {
+      writer.forceMerge(1);
+    }
+    writer.close();
 
-      BooleanQuery booleanQuery = new BooleanQuery();
-      booleanQuery.add(new TermQuery(new Term(FIELD, "36")), BooleanClause.Occur.SHOULD);
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(new TermQuery(new Term(FIELD, "36")), BooleanClause.Occur.SHOULD);
      
      
-      IndexReader reader = DirectoryReader.open(directory);
-      IndexSearcher indexSearcher = newSearcher(reader);
-      ScoreDoc[] hits = indexSearcher.search(booleanQuery, filter, 1000).scoreDocs;
-      assertEquals("Number of matched documents", 1, hits.length);
-      reader.close();
-    }
-    catch (IOException e) {
-      fail(e.getMessage());
-    }
-    
+    IndexReader reader = DirectoryReader.open(directory);
+    IndexSearcher indexSearcher = newSearcher(reader);
+    ScoreDoc[] hits = indexSearcher.search(booleanQuery, filter, 1000).scoreDocs;
+    assertEquals("Number of matched documents", 1, hits.length);
+    reader.close();
   }
  
   public static final class SimpleDocIdSetFilter extends Filter {
     private final int[] docs;
-    private int index;
     
     public SimpleDocIdSetFilter(int[] docs) {
       this.docs = docs;
@@ -103,20 +94,14 @@ public class TestFilteredSearch extends 
       final FixedBitSet set = new FixedBitSet(context.reader().maxDoc());
       int docBase = context.docBase;
       final int limit = docBase+context.reader().maxDoc();
-      for (;index < docs.length; index++) {
+      for (int index=0;index < docs.length; index++) {
         final int docId = docs[index];
-        if(docId > limit)
-          break;
-        if (docId >= docBase) {
+        if (docId >= docBase && docId < limit) {
           set.set(docId-docBase);
         }
       }
       return set.cardinality() == 0 ? null:set;
     }
-    
-    public void reset(){
-      index = 0;
-    }
   }
 
 }



Mime
View raw message