lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r899342 - in /lucene/java/branches/lucene_2_9: ./ contrib/ src/java/org/apache/lucene/search/ src/java/org/apache/lucene/util/ src/test/org/apache/lucene/analysis/ src/test/org/apache/lucene/document/ src/test/org/apache/lucene/index/ src/t...
Date Thu, 14 Jan 2010 18:20:14 GMT
Author: mikemccand
Date: Thu Jan 14 18:20:14 2010
New Revision: 899342

URL: http://svn.apache.org/viewvc?rev=899342&view=rev
Log:
LUCENE-2114: improve javadocs for Filter wrt multiple segments

Modified:
    lucene/java/branches/lucene_2_9/   (props changed)
    lucene/java/branches/lucene_2_9/CHANGES.txt   (contents, props changed)
    lucene/java/branches/lucene_2_9/contrib/   (props changed)
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/Filter.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java 
 (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestDateTools.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestNumberTools.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFilteredSearch.java
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java
  (props changed)

Propchange: lucene/java/branches/lucene_2_9/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1,3 +1,3 @@
 /lucene/java/branches/lucene_2_4:748824
 /lucene/java/branches/lucene_3_0:886275
-/lucene/java/trunk:824125,826029,826385,830871,833095,833297,833886,881819,882672,883554,884870,886257,887532,891189,891363,897672
+/lucene/java/trunk:824125,826029,826385,830871,833095,833297,833886,881819,882672,883554,884870,886257,887347,887532,891189,891363,897672

Modified: lucene/java/branches/lucene_2_9/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=899342&r1=899341&r2=899342&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_9/CHANGES.txt Thu Jan 14 18:20:14 2010
@@ -43,6 +43,18 @@
  * LUCENE-2086: When resolving deleted terms, do so in term sort order
    for better performance (Bogdan Ghidireac via Mike McCandless)
 
+Test Cases
+
+ * LUCENE-2114: Change TestFilteredSearch to test on multi-segment
+   index as well. (Simon Willnauer via Mike McCandless)
+
+Documentation
+
+ * LUCENE-2114: Improve javadocs of Filter to call out that the
+   provided reader is per-segment (Simon Willnauer via Mike
+   McCandless)
+
+
 ======================= Release 2.9.1 2009-11-06 =======================
 
 Changes in backwards compatibility policy

Propchange: lucene/java/branches/lucene_2_9/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/CHANGES.txt:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/CHANGES.txt:881819,886257,887347,887532,891189,891363,897672

Propchange: lucene/java/branches/lucene_2_9/contrib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/contrib:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/contrib:881819,886257,887347,887532,891189,891363,897672

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/Filter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/Filter.java?rev=899342&r1=899341&r2=899342&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/Filter.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/Filter.java Thu Jan
14 18:20:14 2010
@@ -22,8 +22,9 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.util.DocIdBitSet;
 
-/** Abstract base class providing a mechanism to use a subset of an index
- *  for restriction or permission of index search results.
+/** 
+ *  Abstract base class for restricting which documents may
+ *  be returned during searching.
  *  <p>
  *  <b>Note:</b> In Lucene 3.0 {@link #bits(IndexReader)} will be removed
  *  and {@link #getDocIdSet(IndexReader)} will be defined as abstract.
@@ -31,9 +32,15 @@
  *  in order to work with Lucene 3.0.
  */
 public abstract class Filter implements java.io.Serializable {
+  
   /**
    * @return A BitSet with true for documents which should be permitted in
    * search results, and false for those that should not.
+   *
+   * <p><b>NOTE:</b> See {@link #getDocIdSet(IndexReader)} for
+   * handling of multi-segment indexes (which applies to
+   * this method as well).
+
    * @deprecated Use {@link #getDocIdSet(IndexReader)} instead.
    */
   public BitSet bits(IndexReader reader) throws IOException {
@@ -41,6 +48,20 @@
   }
 
   /**
+   * Creates a {@link DocIdSet} enumerating the documents that should be
+   * permitted in search results. <b>NOTE:</b> null can be
+   * returned if no documents are accepted by this Filter.
+   * <p>
+   * Note: This method will be called once per segment in
+   * the index during searching.  The returned {@link DocIdSet}
+   * must refer to document IDs for that segment, not for
+   * the top-level reader.
+   * 
+   * @param reader a {@link IndexReader} instance opened on the index currently
+   *         searched on. Note, it is likely that the provided reader does not
+   *         represent the whole underlying index i.e. if the index has more than
+   *         one segment the given reader only represents a single segment.
+   *          
    * @return a DocIdSet that provides the documents which should be permitted or
    *         prohibited in search results. <b>NOTE:</b> null can be returned
if
    *         no documents will be accepted by this Filter.

Propchange: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:881819,886257,887347,887532,891189,891363,897672

Propchange: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1,3 +1,3 @@
 /lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/util/AttributeSource.java:748824
 /lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/util/AttributeSource.java:886275
-/lucene/java/trunk/src/java/org/apache/lucene/util/AttributeSource.java:824125,826029,826385,830871,833095,833297,833886,881819,882672,883554,884870,886257,887532,891189,891363,894348,897672
+/lucene/java/trunk/src/java/org/apache/lucene/util/AttributeSource.java:824125,826029,826385,830871,833095,833297,833886,881819,882672,883554,884870,886257,887347,887532,891189,891363,894348,897672

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1,3 +1,3 @@
 /lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:748824
 /lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:886275
-/lucene/java/trunk/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:818920,824125,826029,826385,830871,833095,833297,833886,881819,882672,883554,884870,887532,891189,891363,897672
+/lucene/java/trunk/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:818920,824125,826029,826385,830871,833095,833297,833886,881819,882672,883554,884870,887347,887532,891189,891363,897672

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:881819,886257,887347,887532,891189,891363,897672

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestDateTools.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java:881819,886257,887347,887532,891189,891363,897672

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestNumberTools.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/src/test/org/apache/lucene/document/TestNumberTools.java:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/src/test/org/apache/lucene/document/TestNumberTools.java:881819,886257,887347,887532,891189,891363,897672

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:881819,886257,887347,887532,891189,891363,897672

Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFilteredSearch.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFilteredSearch.java?rev=899342&r1=899341&r2=899342&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFilteredSearch.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFilteredSearch.java
Thu Jan 14 18:20:14 2010
@@ -24,9 +24,12 @@
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.OpenBitSet;
 
@@ -42,19 +45,32 @@
 
   private static final String FIELD = "category";
   
-  public void testFilteredSearch() {
+  public void testFilteredSearch() throws CorruptIndexException, LockObtainFailedException,
IOException {
+    boolean enforceSingleSegment = true;
     RAMDirectory directory = new RAMDirectory();
     int[] filterBits = {1, 36};
-    Filter filter = new SimpleDocIdSetFilter(filterBits);
-    
+    SimpleDocIdSetFilter filter = new SimpleDocIdSetFilter(filterBits);
+    IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+    searchFiltered(writer, directory, filter, enforceSingleSegment);
+    // run the test on more than one segment
+    enforceSingleSegment = false;
+    // reset - it is stateful
+    filter.reset();
+    writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+    // we index 60 docs - this will create 6 segments
+    writer.setMaxBufferedDocs(10);
+    searchFiltered(writer, directory, filter, enforceSingleSegment);
+  }
 
+  public void searchFiltered(IndexWriter writer, Directory directory, Filter filter, boolean
optimize) {
     try {
-      IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
       for (int i = 0; i < 60; i++) {//Simple docs
         Document doc = new Document();
         doc.add(new Field(FIELD, Integer.toString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
         writer.addDocument(doc);
       }
+      if(optimize)
+        writer.optimize();
       writer.close();
 
       BooleanQuery booleanQuery = new BooleanQuery();
@@ -69,23 +85,32 @@
     catch (IOException e) {
       fail(e.getMessage());
     }
-
+    
   }
-  
-
+ 
   public static final class SimpleDocIdSetFilter extends Filter {
-    private OpenBitSet bits;
-
+    private int docBase;
+    private final int[] docs;
+    private int index;
     public SimpleDocIdSetFilter(int[] docs) {
-      bits = new OpenBitSet();
-      for(int i = 0; i < docs.length; i++){
-    	  bits.set(docs[i]);
-      }
-      
+      this.docs = docs;
     }
-
     public DocIdSet getDocIdSet(IndexReader reader) {
-      return bits;
+      final OpenBitSet set = new OpenBitSet();
+      final int limit = docBase+reader.maxDoc();
+      for (;index < docs.length; index++) {
+        final int docId = docs[index];
+        if(docId > limit)
+          break;
+        set.set(docId-docBase);
+      }
+      docBase = limit;
+      return set.isEmpty()?null:set;
+    }
+    
+    public void reset(){
+      index = 0;
+      docBase = 0;
     }
   }
 

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 18:20:14 2010
@@ -1 +1 @@
-/lucene/java/trunk/src/test/org/apache/lucene/util/TestAttributeSource.java:881819,886257,887532,891189,891363,897672
+/lucene/java/trunk/src/test/org/apache/lucene/util/TestAttributeSource.java:881819,886257,887347,887532,891189,891363,897672



Mime
View raw message