lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r756669 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/spans/TermSpans.java src/test/org/apache/lucene/search/spans/TestBasics.java
Date Fri, 20 Mar 2009 17:31:44 GMT
Author: buschmi
Date: Fri Mar 20 17:31:43 2009
New Revision: 756669

URL: http://svn.apache.org/viewvc?rev=756669&view=rev
Log:
LUCENE-1327: Fix TermSpans#skipTo() to behave as specified in javadocs

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/TermSpans.java
    lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=756669&r1=756668&r2=756669&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Mar 20 17:31:43 2009
@@ -94,6 +94,9 @@
 6. LUCENE-1186: Add Analyzer.close() to free internal ThreadLocal
    resources.  (Christian Kohlschütter via Mike McCandless)
 
+7. LUCENE-1327: Fix TermSpans#skipTo() to behave as specified in javadocs
+   of Terms#skipTo(). (Michael Busch)
+
 New features
 
  1. LUCENE-1411: Added expert API to open an IndexWriter on a prior

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/TermSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/TermSpans.java?rev=756669&r1=756668&r2=756669&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/TermSpans.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/TermSpans.java Fri Mar 20 17:31:43
2009
@@ -59,11 +59,6 @@
   }
 
   public boolean skipTo(int target) throws IOException {
-    // are we already at the correct position?
-    if (doc >= target) {
-      return true;
-    }
-
     if (!positions.skipTo(target)) {
       doc = Integer.MAX_VALUE;
       return false;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java?rev=756669&r1=756668&r2=756669&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java Fri Mar 20 17:31:43
2009
@@ -17,19 +17,24 @@
  * limitations under the License.
  */
 
-import org.apache.lucene.util.LuceneTestCase;
-
 import java.io.IOException;
 
-import org.apache.lucene.util.English;
 import org.apache.lucene.analysis.SimpleAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.CheckHits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.PhraseQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.QueryUtils;
+import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.store.RAMDirectory;
-
-import org.apache.lucene.search.*;
+import org.apache.lucene.util.English;
+import org.apache.lucene.util.LuceneTestCase;
 
 /**
  * Tests basic search capabilities.
@@ -339,7 +344,46 @@
        706, 707, 726, 727, 736, 737, 746, 747, 
        756, 757, 766, 767, 776, 777, 786, 787, 796, 797});
   }
+  
+  public void testSpansSkipTo() throws Exception {
+	  SpanTermQuery t1 = new SpanTermQuery(new Term("field", "seventy"));
+	  SpanTermQuery t2 = new SpanTermQuery(new Term("field", "seventy"));
+	  Spans s1 = t1.getSpans(searcher.getIndexReader());
+	  Spans s2 = t2.getSpans(searcher.getIndexReader());
+	  
+	  assertTrue(s1.next());
+	  assertTrue(s2.next());
+	  
+	  boolean hasMore = true;
+	  
+	  do {
+		  hasMore = skipToAccoringToJavaDocs(s1, s1.doc());
+		  assertEquals(hasMore, s2.skipTo(s2.doc()));
+		  assertEquals(s1.doc(), s2.doc());
+	  } while (hasMore);
+  }
+
+  /** Skips to the first match beyond the current, whose document number is
+   * greater than or equal to <i>target</i>. <p>Returns true iff there
is such
+   * a match.  <p>Behaves as if written: <pre>
+   *   boolean skipTo(int target) {
+   *     do {
+   *       if (!next())
+   *       return false;
+   *     } while (target > doc());
+   *     return true;
+   *   }
+   * </pre>
+   */
+  private boolean skipToAccoringToJavaDocs(Spans s, int target)
+      throws Exception {
+    do {
+      if (!s.next())
+        return false;
+    } while (target > s.doc());
+    return true;
 
+  }
 
   private void checkHits(Query query, int[] results) throws IOException {
     CheckHits.checkHits(query, "field", searcher, results);



Mime
View raw message