lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r800925 - in /lucene/java/trunk: ./ contrib/regex/src/java/org/apache/lucene/search/regex/ src/java/org/apache/lucene/search/payloads/ src/java/org/apache/lucene/search/spans/ src/test/org/apache/lucene/search/ src/test/org/apache/lucene/se...
Date Tue, 04 Aug 2009 19:10:03 GMT
Author: markrmiller
Date: Tue Aug  4 19:10:02 2009
New Revision: 800925

URL: http://svn.apache.org/viewvc?rev=800925&view=rev
Log:
LUCENE-1748: LUCENE-1001 introduced PayloadSpans, but this was a back compat break and caused
custom SpanQuery implementations to fail at runtime in a variety of ways. This issue attempts
to remedy things by causing a compile time break on custom SpanQuery implementations and removing
the PayloadSpans class, with its functionality now moved to Spans.

Removed:
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/PayloadSpans.java
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/common-build.xml
    lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/Spans.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/TermSpans.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestPositionIncrement.java
    lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
    lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Aug  4 19:10:02 2009
@@ -84,6 +84,13 @@
     be passed upon instantiation. As a result, IndexWriter was removed
     as a method argument from all MergePolicy methods. (Shai Erera via
     Mike McCandless)
+    
+ 6. LUCENE-1748: LUCENE-1001 introduced PayloadSpans, but this was a back
+    compat break and caused custom SpanQuery implementations to fail at runtime
+    in a variety of ways. This issue attempts to remedy things by causing
+    a compile time break on custom SpanQuery implementations and removing 
+    the PayloadSpans class, with its functionality now moved to Spans.
+    (Hugh Cayless, Mark Miller)
  
 Changes in runtime behavior
 
@@ -363,6 +370,13 @@
     new QueryParser framework in Lucene 3.0, that is currently located
     in contrib. (see New Features 35.) 
     (Luis Alves and Adriano Campos via Michael Busch)
+    
+36. LUCENE-1748: LUCENE-1001 introduced PayloadSpans, but this was a back
+    compat break and caused custom SpanQuery implementations to fail at runtime
+    in a variety of ways. This issue attempts to remedy things by causing
+    a compile time break on custom SpanQuery implementations and removing 
+    the PayloadSpans class, with its functionality now moved to Spans.
+    (Hugh Cayless, Mark Miller)
 
 Bug fixes
 

Modified: lucene/java/trunk/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/common-build.xml?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/common-build.xml (original)
+++ lucene/java/trunk/common-build.xml Tue Aug  4 19:10:02 2009
@@ -42,7 +42,7 @@
   <property name="Name" value="Lucene"/>
   <property name="dev.version" value="2.9-dev"/>
   <property name="version" value="${dev.version}"/>
-  <property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090801"/>
+  <property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090804"/>
   <property name="spec.version" value="${version}"/>	
   <property name="year" value="2000-${current.year}"/>
   <property name="final.name" value="lucene-${name}-${version}"/>

Modified: lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
(original)
+++ lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
Tue Aug  4 19:10:02 2009
@@ -27,7 +27,6 @@
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.search.spans.Spans;
-import org.apache.lucene.search.spans.PayloadSpans;
 import org.apache.lucene.util.ToStringUtils;
 
 import java.io.IOException;
@@ -77,10 +76,6 @@
     throw new UnsupportedOperationException("Query should have been rewritten");
   }
 
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException {
-    throw new UnsupportedOperationException("Query should have been rewritten");
-  }
-
   public String getField() {
     return term.field();
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java Tue
Aug  4 19:10:02 2009
@@ -1,6 +1,5 @@
 package org.apache.lucene.search.payloads;
 
-import org.apache.lucene.search.BooleanClause;
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -26,6 +25,7 @@
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.FilteredQuery;
@@ -33,11 +33,11 @@
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.spans.PayloadSpans;
 import org.apache.lucene.search.spans.SpanNearQuery;
 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.search.spans.Spans;
 
 /**
  * Experimental class to get set of payloads for most standard Lucene queries.
@@ -173,7 +173,7 @@
 
   private void getPayloads(Collection payloads, SpanQuery query)
       throws IOException {
-    PayloadSpans spans = query.getPayloadSpans(reader);
+    Spans spans = query.getSpans(reader);
 
     while (spans.next() == true) {
       if (spans.isPayloadAvailable()) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java Tue
Aug  4 19:10:02 2009
@@ -93,9 +93,6 @@
   public Spans getSpans(IndexReader reader) throws IOException {
     return maskedQuery.getSpans(reader);
   }
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException {
-    return maskedQuery.getPayloadSpans(reader);
-  }
 
   /** @deprecated use {@link #extractTerms(Set)} instead. */
   public Collection getTerms() {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java Tue Aug
 4 19:10:02 2009
@@ -24,7 +24,6 @@
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Collection;
@@ -48,13 +47,13 @@
  * <pre>t1 t2 .. t3      </pre>
  * <pre>      t1 .. t2 t3</pre>
  */
-class NearSpansOrdered implements PayloadSpans {
+class NearSpansOrdered implements Spans {
   private final int allowedSlop;
   private boolean firstTime = true;
   private boolean more = false;
 
   /** The spans in the same order as the SpanNearQuery */
-  private final PayloadSpans[] subSpans;
+  private final Spans[] subSpans;
 
   /** Indicates that all subSpans have same doc() */
   private boolean inSameDoc = false;
@@ -64,7 +63,7 @@
   private int matchEnd = -1;
   private List/*<byte[]>*/ matchPayload;
 
-  private final PayloadSpans[] subSpansByDoc;
+  private final Spans[] subSpansByDoc;
   private final Comparator spanDocComparator = new Comparator() {
     public int compare(Object o1, Object o2) {
       return ((Spans)o1).doc() - ((Spans)o2).doc();
@@ -87,11 +86,11 @@
     this.collectPayloads = collectPayloads;
     allowedSlop = spanNearQuery.getSlop();
     SpanQuery[] clauses = spanNearQuery.getClauses();
-    subSpans = new PayloadSpans[clauses.length];
+    subSpans = new Spans[clauses.length];
     matchPayload = new LinkedList();
-    subSpansByDoc = new PayloadSpans[clauses.length];
+    subSpansByDoc = new Spans[clauses.length];
     for (int i = 0; i < clauses.length; i++) {
-      subSpans[i] = clauses[i].getPayloadSpans(reader);
+      subSpans[i] = clauses[i].getSpans(reader);
       subSpansByDoc[i] = subSpans[i]; // used in toSameDoc()
     }
     query = spanNearQuery; // kept for toString() only.
@@ -260,7 +259,7 @@
     int lastStart = matchStart;
     int lastEnd = matchEnd;
     for (int i = subSpans.length - 2; i >= 0; i--) {
-      PayloadSpans prevSpans = subSpans[i];
+      Spans prevSpans = subSpans[i];
       if (collectPayloads && prevSpans.isPayloadAvailable()) {
         Collection payload = prevSpans.getPayload();
         possiblePayload = new ArrayList(payload.size());

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java Tue
Aug  4 19:10:02 2009
@@ -27,7 +27,7 @@
 import java.util.Set;
 import java.util.HashSet;
 
-class NearSpansUnordered implements PayloadSpans {
+class NearSpansUnordered implements Spans {
   private SpanNearQuery query;
 
   private List ordered = new ArrayList();         // spans in query order
@@ -62,13 +62,13 @@
 
 
   /** Wraps a Spans, and can be used to form a linked list. */
-  private class SpansCell implements PayloadSpans {
-    private PayloadSpans spans;
+  private class SpansCell implements Spans {
+    private Spans spans;
     private SpansCell next;
     private int length = -1;
     private int index;
 
-    public SpansCell(PayloadSpans spans, int index) {
+    public SpansCell(Spans spans, int index) {
       this.spans = spans;
       this.index = index;
     }
@@ -124,7 +124,7 @@
     queue = new CellQueue(clauses.length);
     for (int i = 0; i < clauses.length; i++) {
       SpansCell cell =
-        new SpansCell(clauses[i].getPayloadSpans(reader), i);
+        new SpansCell(clauses[i].getSpans(reader), i);
       ordered.add(cell);
     }
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java Tue Aug
 4 19:10:02 2009
@@ -74,13 +74,9 @@
 	    match.extractTerms(terms);
   }
 
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException {
-    return (PayloadSpans) getSpans(reader);
-  }
-
   public Spans getSpans(final IndexReader reader) throws IOException {
-    return new PayloadSpans() {
-        private PayloadSpans spans = match.getPayloadSpans(reader);
+    return new Spans() {
+        private Spans spans = match.getSpans(reader);
 
         public boolean next() throws IOException {
           while (spans.next()) {                  // scan to next match

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Tue Aug 
4 19:10:02 2009
@@ -125,18 +125,14 @@
 
   public Spans getSpans(final IndexReader reader) throws IOException {
     if (clauses.size() == 0)                      // optimize 0-clause case
-      return new SpanOrQuery(getClauses()).getPayloadSpans(reader);
+      return new SpanOrQuery(getClauses()).getSpans(reader);
 
     if (clauses.size() == 1)                      // optimize 1-clause case
-      return ((SpanQuery)clauses.get(0)).getPayloadSpans(reader);
+      return ((SpanQuery)clauses.get(0)).getSpans(reader);
 
     return inOrder
-            ? (PayloadSpans) new NearSpansOrdered(this, reader, collectPayloads)
-            : (PayloadSpans) new NearSpansUnordered(this, reader);
-  }
-
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException {
-    return (PayloadSpans) getSpans(reader);
+            ? (Spans) new NearSpansOrdered(this, reader, collectPayloads)
+            : (Spans) new NearSpansUnordered(this, reader);
   }
 
   public Query rewrite(IndexReader reader) throws IOException {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Tue Aug  4
19:10:02 2009
@@ -75,8 +75,8 @@
   }
 
   public Spans getSpans(final IndexReader reader) throws IOException {
-    return new PayloadSpans() {
-        private PayloadSpans includeSpans = include.getPayloadSpans(reader);
+    return new Spans() {
+        private Spans includeSpans = include.getSpans(reader);
         private boolean moreInclude = true;
 
         private Spans excludeSpans = exclude.getSpans(reader);
@@ -157,10 +157,6 @@
       };
   }
 
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException {
-    return (PayloadSpans) getSpans(reader);
-  }
-
   public Query rewrite(IndexReader reader) throws IOException {
     SpanNotQuery clone = null;
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Tue Aug  4
19:10:02 2009
@@ -167,22 +167,18 @@
     }
   }
 
-  public PayloadSpans getPayloadSpans(final IndexReader reader) throws IOException {
-    return (PayloadSpans)getSpans(reader);
-  }
-
   public Spans getSpans(final IndexReader reader) throws IOException {
     if (clauses.size() == 1)                      // optimize 1-clause case
-      return ((SpanQuery)clauses.get(0)).getPayloadSpans(reader);
+      return ((SpanQuery)clauses.get(0)).getSpans(reader);
 
-    return new PayloadSpans() {
+    return new Spans() {
         private SpanQueue queue = null;
 
         private boolean initSpanQueue(int target) throws IOException {
           queue = new SpanQueue(clauses.size());
           Iterator i = clauses.iterator();
           while (i.hasNext()) {
-            PayloadSpans spans = ((SpanQuery)i.next()).getPayloadSpans(reader);
+            Spans spans = ((SpanQuery)i.next()).getSpans(reader);
             if (   ((target == -1) && spans.next())
                 || ((target != -1) && spans.skipTo(target))) {
               queue.put(spans);
@@ -209,7 +205,7 @@
           return queue.size() != 0;
         }
 
-        private PayloadSpans top() { return (PayloadSpans)queue.top(); }
+        private Spans top() { return (Spans)queue.top(); }
 
         public boolean skipTo(int target) throws IOException {
           if (queue == null) {
@@ -239,7 +235,7 @@
       // TODO: Remove warning after API has been finalized
       public Collection/*<byte[]>*/ getPayload() throws IOException {
         ArrayList result = null;
-        PayloadSpans theTop = top();
+        Spans theTop = top();
         if (theTop != null && theTop.isPayloadAvailable()) {
           result = new ArrayList(theTop.getPayload());
         }
@@ -248,7 +244,7 @@
 
       // TODO: Remove warning after API has been finalized
      public boolean isPayloadAvailable() {
-        PayloadSpans top = top();
+        Spans top = top();
         return top != null && top.isPayloadAvailable();
       }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanQuery.java Tue Aug  4 19:10:02
2009
@@ -32,22 +32,6 @@
    * to search for spans. */
   public abstract Spans getSpans(IndexReader reader) throws IOException;
 
-  /**
-   * Returns the matches for this query in an index, including access to any {@link org.apache.lucene.index.Payload}s
at those
-   * positions.  Implementing classes that want access to the payloads will need to implement
this.
-   * @param reader  The {@link org.apache.lucene.index.IndexReader} to use to get spans/payloads
-   * @return null
-   * @throws IOException if there is an error accessing the payload
-   *
-   * <font color="#FF0000">
-   * WARNING: The status of the <b>Payloads</b> feature is experimental.
-   * The APIs introduced here might change in the future and will not be
-   * supported anymore in such a case.</font>
-   */
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException{
-    return null;
-  }
-
   /** Returns the name of the field matched by this query.*/
   public abstract String getField();
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java Tue Aug 
4 19:10:02 2009
@@ -79,9 +79,4 @@
     return new TermSpans(reader.termPositions(term), term);
   }
 
-
-  public PayloadSpans getPayloadSpans(IndexReader reader) throws IOException {
-    return (PayloadSpans) getSpans(reader);
-  }
-
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/Spans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/Spans.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/Spans.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/Spans.java Tue Aug  4 19:10:02
2009
@@ -18,6 +18,7 @@
  */
 
 import java.io.IOException;
+import java.util.Collection;
 
 /** Expert: an enumeration of span matches.  Used to implement span searching.
  * Each span represents a range of term positions within a document.  Matches
@@ -50,5 +51,46 @@
 
   /** Returns the end position of the current match.  Initially invalid. */
   int end();
+  
+  /**
+   * Returns the payload data for the current span.
+   * This is invalid until {@link #next()} is called for
+   * the first time.
+   * This method must not be called more than once after each call
+   * of {@link #next()}. However, most payloads are loaded lazily,
+   * so if the payload data for the current position is not needed,
+   * this method may not be called at all for performance reasons. An ordered
+   * SpanQuery does not lazy load, so if you have payloads in your index and
+   * you do not want ordered SpanNearQuerys to collect payloads, you can
+   * disable collection with a constructor option.<br>
+   * <br>
+    * Note that the return type is a collection, thus the ordering should not be relied upon.
+    * <br/>
+   * <p><font color="#FF0000">
+   * WARNING: The status of the <b>Payloads</b> feature is experimental.
+   * The APIs introduced here might change in the future and will not be
+   * supported anymore in such a case.</font>
+   *
+   * @return a List of byte arrays containing the data of this payload, otherwise null if
isPayloadAvailable is false
+   * @throws java.io.IOException
+    */
+  // TODO: Remove warning after API has been finalized
+  Collection/*<byte[]>*/ getPayload() throws IOException;
+
+  /**
+   * Checks if a payload can be loaded at this position.
+   * <p/>
+   * Payloads can only be loaded once per call to
+   * {@link #next()}.
+   * <p/>
+   * <p><font color="#FF0000">
+   * WARNING: The status of the <b>Payloads</b> feature is experimental.
+   * The APIs introduced here might change in the future and will not be
+   * supported anymore in such a case.</font>
+   *
+   * @return true if there is a payload available at this position that can be loaded
+   */
+  // TODO: Remove warning after API has been finalized
+  public boolean isPayloadAvailable();
 
 }

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=800925&r1=800924&r2=800925&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 Tue Aug  4 19:10:02
2009
@@ -27,7 +27,7 @@
  * Expert:
  * Public for extension only
  */
-public class TermSpans implements PayloadSpans {
+public class TermSpans implements Spans {
   protected TermPositions positions;
   protected Term term;
   protected int doc;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestPositionIncrement.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestPositionIncrement.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestPositionIncrement.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestPositionIncrement.java Tue Aug
 4 19:10:02 2009
@@ -45,7 +45,6 @@
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.index.Payload;
 import org.apache.lucene.search.payloads.PayloadSpanUtil;
-import org.apache.lucene.search.spans.PayloadSpans;
 import org.apache.lucene.search.spans.SpanNearQuery;
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
@@ -279,7 +278,7 @@
       count = 0;
       boolean sawZero = false;
       //System.out.println("\ngetPayloadSpans test");
-      PayloadSpans pspans = snq.getPayloadSpans(is.getIndexReader());
+      Spans pspans = snq.getSpans(is.getIndexReader());
       while (pspans.next()) {
         //System.out.println(pspans.doc() + " - " + pspans.start() + " - "+ pspans.end());
         Collection payloads = pspans.getPayload();

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
Tue Aug  4 19:10:02 2009
@@ -57,6 +57,14 @@
     public int start() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
+
+    public Collection getPayload() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean isPayloadAvailable() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
     
   }
 
@@ -81,7 +89,7 @@
     
   }
 
-  static final class JustCompilePayloadSpans implements PayloadSpans {
+  static final class JustCompilePayloadSpans implements Spans {
 
     public Collection getPayload() throws IOException {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java?rev=800925&r1=800924&r2=800925&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java Tue Aug
 4 19:10:02 2009
@@ -26,7 +26,6 @@
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.LowerCaseTokenizer;
-import org.apache.lucene.analysis.Token;
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
@@ -51,7 +50,7 @@
 import org.apache.lucene.util.LuceneTestCase;
 
 public class TestPayloadSpans extends LuceneTestCase {
-  private final static boolean DEBUG = false;
+  private final static boolean DEBUG = true;
   private IndexSearcher searcher;
   private Similarity similarity = new DefaultSimilarity();
   protected IndexReader indexReader;
@@ -73,14 +72,14 @@
 
   public void testSpanTermQuery() throws Exception {
     SpanTermQuery stq;
-    PayloadSpans spans;
+    Spans spans;
     stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "seventy"));
-    spans = stq.getPayloadSpans(indexReader);
+    spans = stq.getSpans(indexReader);
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 100, 1, 1, 1);
 
     stq = new SpanTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "seventy"));  
-    spans = stq.getPayloadSpans(indexReader);
+    spans = stq.getSpans(indexReader);
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 100, 0, 0, 0);
   }
@@ -91,7 +90,7 @@
     SpanFirstQuery sfq;
     match = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
     sfq = new SpanFirstQuery(match, 2);
-    PayloadSpans spans = sfq.getPayloadSpans(indexReader);
+    Spans spans = sfq.getSpans(indexReader);
     checkSpans(spans, 109, 1, 1, 1);
     //Test more complicated subclause
     SpanQuery[] clauses = new SpanQuery[2];
@@ -99,20 +98,49 @@
     clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "hundred"));
     match = new SpanNearQuery(clauses, 0, true);
     sfq = new SpanFirstQuery(match, 2);
-    checkSpans(sfq.getPayloadSpans(indexReader), 100, 2, 1, 1);
+    checkSpans(sfq.getSpans(indexReader), 100, 2, 1, 1);
 
     match = new SpanNearQuery(clauses, 0, false);
     sfq = new SpanFirstQuery(match, 2);
-    checkSpans(sfq.getPayloadSpans(indexReader), 100, 2, 1, 1);
+    checkSpans(sfq.getSpans(indexReader), 100, 2, 1, 1);
     
   }
   
+  public void testSpanNot() throws Exception {
+    SpanQuery[] clauses = new SpanQuery[2];
+    clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
+    clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "three"));
+    SpanQuery spq = new SpanNearQuery(clauses, 5, true);
+    SpanNotQuery snq = new SpanNotQuery(spq, new SpanTermQuery(new Term(PayloadHelper.FIELD,
"two")));
+    checkSpans(snq.getSpans(getSpanNotSearcher().getIndexReader()), 1,new int[]{2});
+  }
+  
+  public IndexSearcher getSpanNotSearcher()
+      throws IOException {
+    RAMDirectory directory = new RAMDirectory();
+    PayloadAnalyzer analyzer = new PayloadAnalyzer();
+    IndexWriter writer = new IndexWriter(directory, analyzer, true);
+    writer.setSimilarity(similarity);
+
+    Document doc = new Document();
+    doc.add(new Field(PayloadHelper.FIELD, "one two three one four three",
+        Field.Store.YES, Field.Index.ANALYZED));
+    writer.addDocument(doc);
+
+    writer.close();
+
+    IndexSearcher searcher = new IndexSearcher(directory);
+    searcher.setSimilarity(similarity);
+    return searcher;
+
+  }
+  
   public void testNestedSpans() throws Exception {
     SpanTermQuery stq;
-    PayloadSpans spans;
+    Spans spans;
     IndexSearcher searcher = getSearcher();
     stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "mark"));
-    spans = stq.getPayloadSpans(searcher.getIndexReader());
+    spans = stq.getSpans(searcher.getIndexReader());
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 0, null);
 
@@ -123,7 +151,7 @@
     clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
     SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 12, false);
 
-    spans = spanNearQuery.getPayloadSpans(searcher.getIndexReader());
+    spans = spanNearQuery.getSpans(searcher.getIndexReader());
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 2, new int[]{3,3});
 
@@ -135,7 +163,7 @@
     spanNearQuery = new SpanNearQuery(clauses, 6, true);
    
     
-    spans = spanNearQuery.getPayloadSpans(searcher.getIndexReader());
+    spans = spanNearQuery.getSpans(searcher.getIndexReader());
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 1, new int[]{3});
      
@@ -157,13 +185,13 @@
     
     // yy within 6 of xx within 6 of rr
 
-    spans = nestedSpanNearQuery.getPayloadSpans(searcher.getIndexReader());
+    spans = nestedSpanNearQuery.getSpans(searcher.getIndexReader());
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 2, new int[]{3,3});
   }
   
   public void testFirstClauseWithoutPayload() throws Exception {
-    PayloadSpans spans;
+    Spans spans;
     IndexSearcher searcher = getSearcher();
 
     SpanQuery[] clauses = new SpanQuery[3];
@@ -187,13 +215,13 @@
      
     SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
 
-    spans = nestedSpanNearQuery.getPayloadSpans(searcher.getIndexReader());
+    spans = nestedSpanNearQuery.getSpans(searcher.getIndexReader());
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 1, new int[]{3});
   }
   
   public void testHeavilyNestedSpanQuery() throws Exception {
-    PayloadSpans spans;
+    Spans spans;
     IndexSearcher searcher = getSearcher();
 
     SpanQuery[] clauses = new SpanQuery[3];
@@ -222,7 +250,7 @@
      
     SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
 
-    spans = nestedSpanNearQuery.getPayloadSpans(searcher.getIndexReader());
+    spans = nestedSpanNearQuery.getSpans(searcher.getIndexReader());
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 2, new int[]{8, 8});
   }
@@ -243,7 +271,7 @@
     SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
     SpanQuery[] sqs = { stq1, stq2 };
     SpanNearQuery snq = new SpanNearQuery(sqs, 1, true);
-    PayloadSpans spans = snq.getPayloadSpans(is.getIndexReader());
+    Spans spans = snq.getSpans(is.getIndexReader());
 
     TopDocs topDocs = is.search(snq, 1);
     Set payloadSet = new HashSet();
@@ -277,7 +305,7 @@
     SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
     SpanQuery[] sqs = { stq1, stq2 };
     SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
-    PayloadSpans spans = snq.getPayloadSpans(is.getIndexReader());
+    Spans spans = snq.getSpans(is.getIndexReader());
 
     TopDocs topDocs = is.search(snq, 1);
     Set payloadSet = new HashSet();
@@ -311,7 +339,7 @@
     SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
     SpanQuery[] sqs = { stq1, stq2 };
     SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
-    PayloadSpans spans = snq.getPayloadSpans(is.getIndexReader());
+    Spans spans = snq.getSpans(is.getIndexReader());
 
     TopDocs topDocs = is.search(snq, 1);
     Set payloadSet = new HashSet();
@@ -364,7 +392,7 @@
     
   }
 
-  private void checkSpans(PayloadSpans spans, int expectedNumSpans, int expectedNumPayloads,
+  private void checkSpans(Spans spans, int expectedNumSpans, int expectedNumPayloads,
                           int expectedPayloadLength, int expectedFirstByte) throws IOException
{
     assertTrue("spans is null and it shouldn't be", spans != null);
     //each position match should have a span associated with it, since there is just one
underlying term query, there should
@@ -420,7 +448,7 @@
     return searcher;
   }
   
-  private void checkSpans(PayloadSpans spans, int numSpans, int[] numPayloads) throws IOException
{
+  private void checkSpans(Spans spans, int numSpans, int[] numPayloads) throws IOException
{
     int cnt = 0;
 
     while (spans.next() == true) {



Mime
View raw message