lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r619676 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/IndexSearcher.java src/test/org/apache/lucene/search/TestFilteredSearch.java
Date Thu, 07 Feb 2008 22:46:38 GMT
Author: buschmi
Date: Thu Feb  7 14:46:37 2008
New Revision: 619676

URL: http://svn.apache.org/viewvc?rev=619676&view=rev
Log:
LUCENE-1169: Fixed bug in IndexSearcher.search(): searching with a filter might miss some
hits because scorer.skipTo() is called without checking if the scorer is already at the right
position.

Added:
    lucene/java/trunk/src/test/org/apache/lucene/search/TestFilteredSearch.java   (with props)
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=619676&r1=619675&r2=619676&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Feb  7 14:46:37 2008
@@ -49,6 +49,12 @@
     documents have mixed term vectors (Suresh Guvvala via Mike
     McCandless).
 	
+ 4. LUCENE-1169: Fixed bug in IndexSearcher.search(): searching with
+    a filter might miss some hits because scorer.skipTo() is called
+    without checking if the scorer is already at the right position.
+    scorer.skipTo(scorer.doc()) is not a NOOP, it behaves as 
+    scorer.next(). (Eks Dev, Michael Busch)
+	
 New features
 
  1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about
a Token through the analysis

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java?rev=619676&r1=619675&r2=619676&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java Thu Feb  7 14:46:37
2008
@@ -139,16 +139,18 @@
     }
 
     DocIdSetIterator docIdSetIterator = filter.getDocIdSet(reader).iterator(); // CHECKME:
use ConjunctionScorer here?
-    boolean more = docIdSetIterator.next();
+    
+    boolean more = docIdSetIterator.next() && scorer.skipTo(docIdSetIterator.doc());
+
     while (more) {
       int filterDocId = docIdSetIterator.doc();
-      if (! scorer.skipTo(filterDocId)) {
+      if (filterDocId > scorer.doc() && !scorer.skipTo(filterDocId)) {
         more = false;
       } else {
         int scorerDocId = scorer.doc();
         if (scorerDocId == filterDocId) { // permitted by filter
           results.collect(scorerDocId, scorer.score());
-          more = docIdSetIterator.skipTo(scorerDocId + 1);
+          more = docIdSetIterator.next();
         } else {
           more = docIdSetIterator.skipTo(scorerDocId);
         }

Added: lucene/java/trunk/src/test/org/apache/lucene/search/TestFilteredSearch.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestFilteredSearch.java?rev=619676&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestFilteredSearch.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestFilteredSearch.java Thu Feb  7
14:46:37 2008
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.search;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
+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.Term;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.OpenBitSet;
+
+
+/**
+ *
+ */
+public class TestFilteredSearch extends TestCase
+{
+
+  public TestFilteredSearch(String name) {
+    super(name);
+  }
+
+  private static final String FIELD = "category";
+  
+  public void testFilteredSearch() {
+    RAMDirectory directory = new RAMDirectory();
+    int[] filterBits = {1, 36};
+    Filter filter = new SimpleDocIdSetFilter(filterBits);
+    
+
+    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.UN_TOKENIZED));
+        writer.addDocument(doc);
+      }
+      writer.close();
+
+      BooleanQuery booleanQuery = new BooleanQuery();
+      booleanQuery.add(new TermQuery(new Term(FIELD, "36")), BooleanClause.Occur.SHOULD);
+     
+     
+      IndexSearcher indexSearcher = new IndexSearcher(directory);
+      org.apache.lucene.search.Hits hits = indexSearcher.search(booleanQuery, filter);
+      assertEquals("Number of matched documents", 1, hits.length());
+
+    }
+    catch (IOException e) {
+      fail(e.getMessage());
+    }
+
+  }
+  
+
+  public static final class SimpleDocIdSetFilter extends Filter {
+    private OpenBitSet bits;
+
+    public SimpleDocIdSetFilter(int[] docs) {
+      bits = new OpenBitSet();
+      for(int i = 0; i < docs.length; i++){
+    	  bits.set(docs[i]);
+      }
+      
+    }
+
+    public DocIdSet getDocIdSet(IndexReader reader) {
+      return bits;
+    }
+  }
+
+}

Propchange: lucene/java/trunk/src/test/org/apache/lucene/search/TestFilteredSearch.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message