lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1372178 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/codecs/ lucene/core/src/java/org/apache/lucene/codecs/lucene3x/ lucene/core/src/java/org/apache/lucene/codecs/lucene40/ lucene/core...
Date Sun, 12 Aug 2012 19:00:40 GMT
Author: rmuir
Date: Sun Aug 12 19:00:38 2012
New Revision: 1372178

URL: http://svn.apache.org/viewvc?rev=1372178&view=rev
Log:
revisit payloads API in DocsAndPositionsEnum

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFields.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/SegmentTermPositions.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java
    lucene/dev/branches/branch_4x/lucene/memory/   (props changed)
    lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Sun Aug 12 19:00:38 2012
@@ -22,6 +22,11 @@ API Changes
   had positions or offsets, since this can be configured on a 
   per-field-per-document basis. (Robert Muir)
 
+* Removed DocsAndPositionsEnum.hasPayload() and simplified the
+  contract of getPayload(). It returns null if there is no payload,
+  otherwise returns the current payload. You can now call it multiple
+  times per position if you want. (Robert Muir)
+
 Bug Fixes
 
 * LUCENE-4297: BooleanScorer2 would multiply the coord() factor

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java Sun Aug 12 19:00:38 2012
@@ -126,6 +126,7 @@ public final class MappingMultiDocsAndPo
     BytesRef payload = current.getPayload();
     if (mergeState.currentPayloadProcessor[upto] != null && payload != null) {
       // to not violate the D&P api, we must give the processor a private copy
+      // TODO: reuse a BytesRef if there is a PPP
       payload = BytesRef.deepCopyOf(payload);
       mergeState.currentPayloadProcessor[upto].processPayload(payload);
       if (payload.length == 0) {
@@ -135,12 +136,5 @@ public final class MappingMultiDocsAndPo
     }
     return payload;
   }
-
-  @Override
-  public boolean hasPayload() {
-    // TODO: note this is actually bogus if there is a payloadProcessor,
-    // because it might remove it: but lets just remove this method completely
-    return current.hasPayload();
-  }
 }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java Sun Aug 12 19:00:38 2012
@@ -112,12 +112,7 @@ public abstract class PostingsConsumer {
         totTF += freq;
         for(int i=0;i<freq;i++) {
           final int position = postingsEnum.nextPosition();
-          final BytesRef payload;
-          if (postingsEnum.hasPayload()) {
-            payload = postingsEnum.getPayload();
-          } else {
-            payload = null;
-          }
+          final BytesRef payload = postingsEnum.getPayload();
           this.addPosition(position, payload, -1, -1);
         }
         this.finishDoc();
@@ -137,12 +132,7 @@ public abstract class PostingsConsumer {
         totTF += freq;
         for(int i=0;i<freq;i++) {
           final int position = postingsEnum.nextPosition();
-          final BytesRef payload;
-          if (postingsEnum.hasPayload()) {
-            payload = postingsEnum.getPayload();
-          } else {
-            payload = null;
-          }
+          final BytesRef payload = postingsEnum.getPayload();
           this.addPosition(position, payload, postingsEnum.startOffset(), postingsEnum.endOffset());
         }
         this.finishDoc();

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java Sun Aug 12 19:00:38 2012
@@ -271,8 +271,7 @@ public abstract class TermVectorsWriter 
             final int startOffset = docsAndPositionsEnum.startOffset();
             final int endOffset = docsAndPositionsEnum.endOffset();
             
-            BytesRef payload = docsAndPositionsEnum.hasPayload() ? 
-                docsAndPositionsEnum.getPayload() : null;
+            BytesRef payload = docsAndPositionsEnum.getPayload();
                 
             if (payloadProcessor != null && payload != null) {
               // to not violate the D&P api, we must give the processor a private copy

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFields.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFields.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFields.java Sun Aug 12 19:00:38 2012
@@ -1090,28 +1090,8 @@ class Lucene3xFields extends FieldsProdu
     }
 
     @Override
-    public boolean hasPayload() {
-      assert docID != NO_MORE_DOCS;
-      return pos.isPayloadAvailable();
-    }
-
-    private BytesRef payload;
-
-    @Override
     public BytesRef getPayload() throws IOException {
-      final int len = pos.getPayloadLength();
-      if (payload == null) {
-        payload = new BytesRef();
-        payload.bytes = new byte[len];
-      } else {
-        if (payload.bytes.length < len) {
-          payload.grow(len);
-        }
-      }
-      
-      payload.bytes = pos.getPayload(payload.bytes, 0);
-      payload.length = len;
-      return payload;
+      return pos.getPayload();
     }
   }
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java Sun Aug 12 19:00:38 2012
@@ -641,11 +641,6 @@ class Lucene3xTermVectorsReader extends 
     }
 
     @Override
-    public boolean hasPayload() {
-      return false;
-    }
-
-    @Override
     public int nextPosition() {
       assert (positions != null && nextPos < positions.length) ||
         startOffsets != null && nextPos < startOffsets.length;

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/SegmentTermPositions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/SegmentTermPositions.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/SegmentTermPositions.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/SegmentTermPositions.java Sun Aug 12 19:00:38 2012
@@ -23,6 +23,7 @@ import org.apache.lucene.index.FieldInfo
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.FieldInfo.IndexOptions;
 import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.BytesRef;
 
 /**
  * @lucene.experimental
@@ -36,6 +37,7 @@ extends SegmentTermDocs  {
   private int proxCount;
   private int position;
   
+  private BytesRef payload;
   // the current payload length
   private int payloadLength;
   // indicates whether the payload of the current position has
@@ -192,26 +194,24 @@ extends SegmentTermDocs  {
     return payloadLength;
   }
 
-  public byte[] getPayload(byte[] data, int offset) throws IOException {
-    if (!needToLoadPayload) {
-      throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
-    }
-
-    // read payloads lazily
-    byte[] retArray;
-    int retOffset;
-    if (data == null || data.length - offset < payloadLength) {
-      // the array is too small to store the payload data,
-      // so we allocate a new one
-      retArray = new byte[payloadLength];
-      retOffset = 0;
-    } else {
-      retArray = data;
-      retOffset = offset;
+  public BytesRef getPayload() throws IOException {
+    if (payloadLength <= 0) {
+      return null; // no payload
     }
-    proxStream.readBytes(retArray, retOffset, payloadLength);
-    needToLoadPayload = false;
-    return retArray;
+
+    if (needToLoadPayload) {
+      // read payloads lazily
+      if (payload == null) {
+        payload = new BytesRef(payloadLength);
+      } else {
+        payload.grow(payloadLength);
+      }
+      
+      proxStream.readBytes(payload.bytes, payload.offset, payloadLength);
+      payload.length = payloadLength;
+      needToLoadPayload = false;
+    }
+    return payload;
   }
 
   public boolean isPayloadAvailable() {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java Sun Aug 12 19:00:38 2012
@@ -873,12 +873,7 @@ public class Lucene40PostingsReader exte
      *  payload was indexed. */
     @Override
     public BytesRef getPayload() throws IOException {
-      throw new IOException("No payloads exist for this field!");
-    }
-
-    @Override
-    public boolean hasPayload() {
-      return false;
+      return null;
     }
   }
   
@@ -1152,28 +1147,26 @@ public class Lucene40PostingsReader exte
     @Override
     public BytesRef getPayload() throws IOException {
       if (storePayloads) {
+        if (payloadLength <= 0) {
+          return null;
+        }
         assert lazyProxPointer == -1;
         assert posPendingCount < freq;
-        if (!payloadPending) {
-          throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
-        }
-        if (payloadLength > payload.bytes.length) {
-          payload.grow(payloadLength);
-        }
+        
+        if (payloadPending) {
+          if (payloadLength > payload.bytes.length) {
+            payload.grow(payloadLength);
+          }
 
-        proxIn.readBytes(payload.bytes, 0, payloadLength);
-        payload.length = payloadLength;
-        payloadPending = false;
+          proxIn.readBytes(payload.bytes, 0, payloadLength);
+          payload.length = payloadLength;
+          payloadPending = false;
+        }
 
         return payload;
       } else {
-        throw new IOException("No payloads exist for this field!");
+        return null;
       }
     }
-
-    @Override
-    public boolean hasPayload() {
-      return payloadPending && payloadLength > 0;
-    }
   }
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java Sun Aug 12 19:00:38 2012
@@ -671,7 +671,6 @@ public class Lucene40TermVectorsReader e
 
     @Override
     public BytesRef getPayload() {
-      // TODO: dumb that we have to duplicate hasPayload
       if (payloadOffsets == null) {
         return null;
       } else {
@@ -688,17 +687,6 @@ public class Lucene40TermVectorsReader e
     }
 
     @Override
-    public boolean hasPayload() {
-      if (payloadOffsets == null) {
-        return false;
-      } else {
-        int off = payloadOffsets[nextPos-1];
-        int end = nextPos == payloadOffsets.length ? payloadBytes.length : payloadOffsets[nextPos];
-        return end - off > 0;
-      }
-    }
-
-    @Override
     public int nextPosition() {
       assert (positions != null && nextPos < positions.length) ||
         startOffsets != null && nextPos < startOffsets.length;

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java Sun Aug 12 19:00:38 2012
@@ -348,9 +348,8 @@ public class DirectPostingsFormat extend
                     scratch.add(docsAndPositionsEnum.endOffset());
                   }
                   if (hasPayloads) {
-                    final BytesRef payload;
-                    if (docsAndPositionsEnum.hasPayload()) {
-                      payload = docsAndPositionsEnum.getPayload();
+                    final BytesRef payload = docsAndPositionsEnum.getPayload();
+                    if (payload != null) {
                       scratch.add(payload.length);
                       ros.writeBytes(payload.bytes, payload.offset, payload.length);
                     } else {
@@ -421,9 +420,8 @@ public class DirectPostingsFormat extend
                 for(int pos=0;pos<freq;pos++) {
                   positions[upto][posUpto] = docsAndPositionsEnum.nextPosition();
                   if (hasPayloads) {
-                    if (docsAndPositionsEnum.hasPayload()) {
-                      BytesRef payload = docsAndPositionsEnum.getPayload();
-                      assert payload != null;
+                    BytesRef payload = docsAndPositionsEnum.getPayload();
+                    if (payload != null) {
                       byte[] payloadBytes = new byte[payload.length];
                       System.arraycopy(payload.bytes, payload.offset, payloadBytes, 0, payload.length);
                       payloads[upto][pos] = payloadBytes;
@@ -1807,17 +1805,11 @@ public class DirectPostingsFormat extend
     }
 
     @Override
-    public boolean hasPayload() {
-      return payloadLength > 0;
-    }
-
-    @Override
     public BytesRef getPayload() {
       if (payloadLength > 0) {
         payload.bytes = payloadBytes;
         payload.offset = lastPayloadOffset;
         payload.length = payloadLength;
-        payloadLength = 0;
         return payload;
       } else {
         return null;
@@ -2010,7 +2002,6 @@ public class DirectPostingsFormat extend
     private int upto;
     private int docID = -1;
     private int posUpto;
-    private boolean gotPayload;
     private int[] curPositions;
 
     public HighFreqDocsAndPositionsEnum(Bits liveDocs, boolean hasOffsets) {
@@ -2080,7 +2071,6 @@ public class DirectPostingsFormat extend
     @Override
     public int nextPosition() {
       posUpto += posJump;
-      gotPayload = false;
       return curPositions[posUpto];
     }
 
@@ -2214,21 +2204,22 @@ public class DirectPostingsFormat extend
       }
     }
 
-    @Override
-    public boolean hasPayload() {
-      return !gotPayload && payloads != null && payloads[upto][posUpto/(hasOffsets ? 3 : 1)] != null;
-    }
-
     private final BytesRef payload = new BytesRef();
 
     @Override
     public BytesRef getPayload() {
-      final byte[] payloadBytes = payloads[upto][posUpto/(hasOffsets ? 3:1)];
-      payload.bytes = payloadBytes;
-      payload.length = payloadBytes.length;
-      payload.offset = 0;
-      gotPayload = true;
-      return payload;
+      if (payloads == null) {
+        return null;
+      } else {
+        final byte[] payloadBytes = payloads[upto][posUpto/(hasOffsets ? 3:1)];
+        if (payloadBytes == null) {
+          return null;
+        }
+        payload.bytes = payloadBytes;
+        payload.length = payloadBytes.length;
+        payload.offset = 0;
+        return payload;
+      }
     }
   }
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java Sun Aug 12 19:00:38 2012
@@ -446,7 +446,6 @@ public class MemoryPostingsFormat extend
     private int numDocs;
     private int posPending;
     private int payloadLength;
-    private boolean payloadRetrieved;
     final boolean storeOffsets;
     int offsetLength;
     int startOffset;
@@ -484,7 +483,6 @@ public class MemoryPostingsFormat extend
       payloadLength = 0;
       this.numDocs = numDocs;
       posPending = 0;
-      payloadRetrieved = false;
       startOffset = storeOffsets ? 0 : -1; // always return -1 if no offsets are stored
       offsetLength = 0;
       return this;
@@ -577,10 +575,6 @@ public class MemoryPostingsFormat extend
         payload.offset = in.getPosition();
         in.skipBytes(payloadLength);
         payload.length = payloadLength;
-        // Necessary, in case caller changed the
-        // payload.bytes from prior call:
-        payload.bytes = buffer;
-        payloadRetrieved = false;
       }
 
       //System.out.println("      pos=" + pos + " payload=" + payload + " fp=" + in.getPosition());
@@ -599,13 +593,7 @@ public class MemoryPostingsFormat extend
 
     @Override
     public BytesRef getPayload() {
-      payloadRetrieved = true;
-      return payload;
-    }
-
-    @Override
-    public boolean hasPayload() {
-      return !payloadRetrieved && payload.length > 0;
+      return payload.length > 0 ? payload : null;
     }
 
     @Override

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java Sun Aug 12 19:00:38 2012
@@ -533,18 +533,12 @@ public class PulsingPostingsReader exten
     }
 
     @Override
-    public boolean hasPayload() {
-      return storePayloads && !payloadRetrieved && payloadLength > 0;
-    }
-
-    @Override
     public BytesRef getPayload() throws IOException {
       //System.out.println("PR  getPayload payloadLength=" + payloadLength + " this=" + this);
       if (payloadRetrieved) {
-        throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
-      }
-      payloadRetrieved = true;
-      if (payloadLength > 0) {
+        return payload;
+      } else if (storePayloads && payloadLength > 0) {
+        payloadRetrieved = true;
         if (payload == null) {
           payload = new BytesRef(payloadLength);
         } else {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java Sun Aug 12 19:00:38 2012
@@ -714,7 +714,11 @@ public class SepPostingsReader extends P
     @Override
     public BytesRef getPayload() throws IOException {
       if (!payloadPending) {
-        throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
+        return null;
+      }
+      
+      if (pendingPayloadBytes == 0) {
+        return payload;
       }
 
       assert pendingPayloadBytes >= payloadLength;
@@ -731,15 +735,9 @@ public class SepPostingsReader extends P
       }
 
       payloadIn.readBytes(payload.bytes, 0, payloadLength);
-      payloadPending = false;
       payload.length = payloadLength;
       pendingPayloadBytes = 0;
       return payload;
     }
-
-    @Override
-    public boolean hasPayload() {
-      return payloadPending && payloadLength > 0;
-    }
   }
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java Sun Aug 12 19:00:38 2012
@@ -472,18 +472,7 @@ class SimpleTextFieldsReader extends Fie
 
     @Override
     public BytesRef getPayload() {
-      // Some tests rely on only being able to retrieve the
-      // payload once
-      try {
-        return payload;
-      } finally {
-        payload = null;
-      }
-    }
-
-    @Override
-    public boolean hasPayload() {
-      return payload != null;
+      return payload;
     }
   }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java Sun Aug 12 19:00:38 2012
@@ -524,16 +524,10 @@ public class SimpleTextTermVectorsReader
 
     @Override
     public BytesRef getPayload() {
-      // assert hasPayload(); // you should have called this
       return payloads == null ? null : payloads[nextPos-1];
     }
 
     @Override
-    public boolean hasPayload() {
-      return payloads != null && payloads[nextPos-1] != null;
-    }
-
-    @Override
     public int nextPosition() {
       assert (positions != null && nextPos < positions.length) ||
         startOffsets != null && nextPos < startOffsets.length;

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java Sun Aug 12 19:00:38 2012
@@ -832,11 +832,9 @@ public class CheckIndex {
                 throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " < lastPos " + lastPos);
               }
               lastPos = pos;
-              if (postings.hasPayload()) {
-                BytesRef payload = postings.getPayload();
-                if (payload.length < 1) {
-                  throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " payload length is out of bounds " + payload.length);
-                }
+              BytesRef payload = postings.getPayload();
+              if (payload != null && payload.length < 1) {
+                throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " payload length is out of bounds " + payload.length);
               }
               if (hasOffsets) {
                 int startOffset = postings.startOffset();
@@ -1528,10 +1526,10 @@ public class CheckIndex {
                         }
                       }
                       
-                      BytesRef payload = null;
-                      if (postings.hasPayload()) {
+                      BytesRef payload = postings.getPayload();
+           
+                      if (payload != null) {
                         assert vectorsHasPayload;
-                        payload = postings.getPayload();
                       }
                       
                       if (postingsHasPayload && vectorsHasPayload) {
@@ -1540,13 +1538,13 @@ public class CheckIndex {
                         if (payload == null) {
                           // we have payloads, but not at this position. 
                           // postings has payloads too, it should not have one at this position
-                          if (postingsPostings.hasPayload()) {
+                          if (postingsPostings.getPayload() != null) {
                             throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has no payload but postings does: " + postingsPostings.getPayload());
                           }
                         } else {
                           // we have payloads, and one at this position
                           // postings should also have one at this position, with the same bytes.
-                          if (!postingsPostings.hasPayload()) {
+                          if (postingsPostings.getPayload() == null) {
                             throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has payload=" + payload + " but postings does not.");
                           }
                           BytesRef postingsPayload = postingsPostings.getPayload();

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java Sun Aug 12 19:00:38 2012
@@ -48,11 +48,8 @@ public abstract class DocsAndPositionsEn
   public abstract int endOffset() throws IOException;
 
   /** Returns the payload at this position, or null if no
-   *  payload was indexed.  Only call this once per
-   *  position. You should not modify anything (neither
-   *  members of the returned BytesRef nor bytes in the
-   *  byte[]). */
+   *  payload was indexed. You should not modify anything 
+   *  (neither members of the returned BytesRef nor bytes 
+   *  in the byte[]). */
   public abstract BytesRef getPayload() throws IOException;
-
-  public abstract boolean hasPayload();
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java Sun Aug 12 19:00:38 2012
@@ -307,11 +307,6 @@ public class FilterAtomicReader extends 
     public BytesRef getPayload() throws IOException {
       return in.getPayload();
     }
-
-    @Override
-    public boolean hasPayload() {
-      return in.hasPayload();
-    }
     
     @Override
     public AttributeSource attributes() {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java Sun Aug 12 19:00:38 2012
@@ -138,11 +138,6 @@ public final class MultiDocsAndPositions
   }
 
   @Override
-  public boolean hasPayload() {
-    return current.hasPayload();
-  }
-
-  @Override
   public BytesRef getPayload() throws IOException {
     return current.getPayload();
   }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java Sun Aug 12 19:00:38 2012
@@ -548,12 +548,7 @@ class UnionDocsAndPositionsEnum extends 
 
   @Override
   public BytesRef getPayload() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public boolean hasPayload() {
-    throw new UnsupportedOperationException();
+    return null;
   }
 
   @Override

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java Sun Aug 12 19:00:38 2012
@@ -118,8 +118,8 @@ public class PayloadTermQuery extends Sp
       }
 
       protected void processPayload(Similarity similarity) throws IOException {
-        final DocsAndPositionsEnum postings = termSpans.getPostings();
-        if (postings.hasPayload()) {
+        if (termSpans.isPayloadAvailable()) {
+          final DocsAndPositionsEnum postings = termSpans.getPostings();
           payload = postings.getPayload();
           if (payload != null) {
             payloadScore = function.currentScore(doc, term.field(),

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java Sun Aug 12 19:00:38 2012
@@ -126,7 +126,7 @@ public class NearSpansUnordered extends 
 
     // TODO: Remove warning after API has been finalized
     @Override
-    public boolean isPayloadAvailable() {
+    public boolean isPayloadAvailable() throws IOException {
       return spans.isPayloadAvailable();
     }
 
@@ -256,7 +256,7 @@ public class NearSpansUnordered extends 
 
   // TODO: Remove warning after API has been finalized
   @Override
-  public boolean isPayloadAvailable() {
+  public boolean isPayloadAvailable() throws IOException {
     SpansCell pointer = min();
     while (pointer != null) {
       if (pointer.isPayloadAvailable()) {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Sun Aug 12 19:00:38 2012
@@ -157,7 +157,7 @@ public class SpanNotQuery extends SpanQu
 
       // TODO: Remove warning after API has been finalized
       @Override
-      public boolean isPayloadAvailable() {
+      public boolean isPayloadAvailable() throws IOException {
         return includeSpans.isPayloadAvailable();
       }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Sun Aug 12 19:00:38 2012
@@ -247,7 +247,7 @@ public class SpanOrQuery extends SpanQue
       }
 
       @Override
-      public boolean isPayloadAvailable() {
+      public boolean isPayloadAvailable() throws IOException {
         Spans top = top();
         return top != null && top.isPayloadAvailable();
       }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java Sun Aug 12 19:00:38 2012
@@ -176,7 +176,7 @@ public abstract class SpanPositionCheckQ
     // TODO: Remove warning after API has been finalized
 
     @Override
-    public boolean isPayloadAvailable() {
+    public boolean isPayloadAvailable() throws IOException {
       return spans.isPayloadAvailable();
     }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java Sun Aug 12 19:00:38 2012
@@ -82,6 +82,6 @@ public abstract class Spans {
    *
    * @return true if there is a payload available at this position that can be loaded
    */
-  public abstract boolean isPayloadAvailable();
+  public abstract boolean isPayloadAvailable() throws IOException;
   
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java Sun Aug 12 19:00:38 2012
@@ -36,6 +36,7 @@ public class TermSpans extends Spans {
   protected int freq;
   protected int count;
   protected int position;
+  protected boolean readPayload;
 
   public TermSpans(DocsAndPositionsEnum postings, Term term) {
     this.postings = postings;
@@ -64,6 +65,7 @@ public class TermSpans extends Spans {
     }
     position = postings.nextPosition();
     count++;
+    readPayload = false;
     return true;
   }
 
@@ -78,7 +80,7 @@ public class TermSpans extends Spans {
     count = 0;
     position = postings.nextPosition();
     count++;
-
+    readPayload = false;
     return true;
   }
 
@@ -101,6 +103,7 @@ public class TermSpans extends Spans {
   @Override
   public Collection<byte[]> getPayload() throws IOException {
     final BytesRef payload = postings.getPayload();
+    readPayload = true;
     final byte[] bytes;
     if (payload != null) {
       bytes = new byte[payload.length];
@@ -113,8 +116,8 @@ public class TermSpans extends Spans {
 
   // TODO: Remove warning after API has been finalized
   @Override
-  public boolean isPayloadAvailable() {
-    return postings.hasPayload();
+  public boolean isPayloadAvailable() throws IOException {
+    return readPayload == false && postings.getPayload() != null;
   }
 
   @Override

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java Sun Aug 12 19:00:38 2012
@@ -437,14 +437,14 @@ public class TestCodecs extends LuceneTe
         final int pos = posEnum.nextPosition();
         assertEquals(positions[i].pos, pos);
         if (positions[i].payload != null) {
-          assertTrue(posEnum.hasPayload());
+          assertNotNull(posEnum.getPayload());
           if (random().nextInt(3) < 2) {
             // Verify the payload bytes
             final BytesRef otherPayload = posEnum.getPayload();
             assertTrue("expected=" + positions[i].payload.toString() + " got=" + otherPayload.toString(), positions[i].payload.equals(otherPayload));
           }
         } else {
-          assertFalse(posEnum.hasPayload());
+          assertNull(posEnum.getPayload());
         }
       }
     }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java Sun Aug 12 19:00:38 2012
@@ -205,11 +205,11 @@ public class TestDocumentWriter extends 
     int freq = termPositions.freq();
     assertEquals(3, freq);
     assertEquals(0, termPositions.nextPosition());
-    assertEquals(true, termPositions.hasPayload());
+    assertNotNull(termPositions.getPayload());
     assertEquals(6, termPositions.nextPosition());
-    assertEquals(false, termPositions.hasPayload());
+    assertNull(termPositions.getPayload());
     assertEquals(7, termPositions.nextPosition());
-    assertEquals(false, termPositions.hasPayload());
+    assertNull(termPositions.getPayload());
     reader.close();
   }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java Sun Aug 12 19:00:38 2012
@@ -412,12 +412,9 @@ public class TestDuelingCodecs extends L
       assertEquals(info, freq, rightDocs.freq());
       for (int i = 0; i < freq; i++) {
         assertEquals(info, leftDocs.nextPosition(), rightDocs.nextPosition());
-        assertEquals(info, leftDocs.hasPayload(), rightDocs.hasPayload());
+        assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
         assertEquals(info, leftDocs.startOffset(), rightDocs.startOffset());
         assertEquals(info, leftDocs.endOffset(), rightDocs.endOffset());
-        if (leftDocs.hasPayload()) {
-          assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
-        }
       }
     }
     assertEquals(info, DocIdSetIterator.NO_MORE_DOCS, rightDocs.nextDoc());
@@ -509,10 +506,7 @@ public class TestDuelingCodecs extends L
       assertEquals(info, freq, rightDocs.freq());
       for (int i = 0; i < freq; i++) {
         assertEquals(info, leftDocs.nextPosition(), rightDocs.nextPosition());
-        assertEquals(info, leftDocs.hasPayload(), rightDocs.hasPayload());
-        if (leftDocs.hasPayload()) {
-          assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
-        }
+        assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
       }
     }
   }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java Sun Aug 12 19:00:38 2012
@@ -205,8 +205,11 @@ public class TestLongPostings extends Lu
             assertTrue(freq >=1 && freq <= 4);
             for(int pos=0;pos<freq;pos++) {
               assertEquals(pos, postings.nextPosition());
-              if (random().nextBoolean() && postings.hasPayload()) {
+              if (random().nextBoolean()) {
                 postings.getPayload();
+                if (random().nextBoolean()) {
+                  postings.getPayload(); // get it again
+                }
               }
             }
           }
@@ -247,8 +250,11 @@ public class TestLongPostings extends Lu
             assertTrue(freq >=1 && freq <= 4);
             for(int pos=0;pos<freq;pos++) {
               assertEquals(pos, postings.nextPosition());
-              if (random().nextBoolean() && postings.hasPayload()) {
+              if (random().nextBoolean()) {
                 postings.getPayload();
+                if (random().nextBoolean()) {
+                  postings.getPayload(); // get it again
+                }
               }
             }
           }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java Sun Aug 12 19:00:38 2012
@@ -173,8 +173,8 @@ public class TestPayloadProcessorProvide
       DocsAndPositionsEnum tpe = MultiFields.getTermPositionsEnum(reader, null, field, text);
       while (tpe.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
         tpe.nextPosition();
-        if (tpe.hasPayload()) {
-          BytesRef payload = tpe.getPayload();
+        BytesRef payload = tpe.getPayload();
+        if (payload != null) {
           assertEquals(1, payload.length);
           assertEquals(1, payload.bytes[0]);
           ++numPayloads;

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java Sun Aug 12 19:00:38 2012
@@ -201,18 +201,10 @@ public class TestPayloads extends Lucene
             for (int i = 0; i < freq; i++) {
                 for (int j = 0; j < numTerms; j++) {
                     tps[j].nextPosition();
-                    if (tps[j].hasPayload()) {
-                      BytesRef br = tps[j].getPayload();
+                    BytesRef br = tps[j].getPayload();
+                    if (br != null) {
                       System.arraycopy(br.bytes, br.offset, verifyPayloadData, offset, br.length);
                       offset += br.length;
-                      // Just to ensure all codecs can
-                      // handle a caller that mucks with the
-                      // returned payload:
-                      if (rarely()) {
-                        br.bytes = new byte[random().nextInt(5)];
-                      }
-                      br.length = 0;
-                      br.offset = 0;
                     }
                 }
             }
@@ -268,11 +260,6 @@ public class TestPayloads extends Lucene
         tp.nextPosition();
         assertEquals("Wrong payload length.", 3 * skipInterval - 2 * numDocs - 1, tp.getPayload().length);
         
-        /*
-         * Test multiple call of getPayload()
-         */
-        assertFalse(tp.hasPayload());
-        
         reader.close();
         
         // test long payload
@@ -621,7 +608,6 @@ public class TestPayloads extends Lucene
     DocsAndPositionsEnum de = sr.termPositionsEnum(null, "field", new BytesRef("withPayload"));
     de.nextDoc();
     de.nextPosition();
-    assertTrue(de.hasPayload());
     assertEquals(new BytesRef("test"), de.getPayload());
     writer.close();
     reader.close();
@@ -656,7 +642,6 @@ public class TestPayloads extends Lucene
     DocsAndPositionsEnum de = sr.termPositionsEnum(null, "field", new BytesRef("withPayload"));
     de.nextDoc();
     de.nextPosition();
-    assertTrue(de.hasPayload());
     assertEquals(new BytesRef("test"), de.getPayload());
     writer.close();
     reader.close();

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java Sun Aug 12 19:00:38 2012
@@ -76,7 +76,6 @@ public class TestPayloadsOnVectors exten
     DocsAndPositionsEnum de = termsEnum.docsAndPositions(null, null);
     assertEquals(0, de.nextDoc());
     assertEquals(0, de.nextPosition());
-    assertTrue(de.hasPayload());
     assertEquals(new BytesRef("test"), de.getPayload());
     writer.close();
     reader.close();
@@ -119,7 +118,6 @@ public class TestPayloadsOnVectors exten
     DocsAndPositionsEnum de = termsEnum.docsAndPositions(null, null);
     assertEquals(0, de.nextDoc());
     assertEquals(3, de.nextPosition());
-    assertTrue(de.hasPayload());
     assertEquals(new BytesRef("test"), de.getPayload());
     writer.close();
     reader.close();

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java Sun Aug 12 19:00:38 2012
@@ -731,20 +731,21 @@ public class TestPostingsFormat extends 
                 System.out.println("      now check payload length=" + (position.payload == null ? 0 : position.payload.length));
               }
               if (position.payload == null || position.payload.length == 0) {
-                assertFalse("should not have payload", docsAndPositionsEnum.hasPayload());
+                assertNull("should not have payload", docsAndPositionsEnum.getPayload());
               } else {
-                assertTrue("should have payload but doesn't", docsAndPositionsEnum.hasPayload());
-
                 BytesRef payload = docsAndPositionsEnum.getPayload();
-                assertFalse("2nd call to hasPayload should be false", docsAndPositionsEnum.hasPayload());
+                assertNotNull("should have payload but doesn't", payload);
 
-                assertNotNull("payload should not be null", payload);
                 assertEquals("payload length is wrong", position.payload.length, payload.length);
                 for(int byteUpto=0;byteUpto<position.payload.length;byteUpto++) {
                   assertEquals("payload bytes are wrong",
                                position.payload[byteUpto],
                                payload.bytes[payload.offset+byteUpto]);
                 }
+                
+                // make a deep copy
+                payload = BytesRef.deepCopyOf(payload);
+                assertEquals("2nd call to getPayload returns something different!", payload, docsAndPositionsEnum.getPayload());
               }
             } else {
               if (VERBOSE) {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java Sun Aug 12 19:00:38 2012
@@ -170,7 +170,7 @@ public class TestPostingsOffsets extends
           assertTrue(storedNumbers.substring(start, end).equals(term));
           if (withPayloads) {
             // check that we have a payload and it starts with "pos"
-            assertTrue(dp.hasPayload());
+            assertNotNull(dp.getPayload());
             BytesRef payload = dp.getPayload();
             assertTrue(payload.utf8ToString().startsWith("pos:"));
           } // note: withPayloads=false doesnt necessarily mean we dont have them from MockAnalyzer!
@@ -198,7 +198,7 @@ public class TestPostingsOffsets extends
         assertTrue(storedNumbers.substring(start, end).equals("hundred"));
         if (withPayloads) {
           // check that we have a payload and it starts with "pos"
-          assertTrue(dp.hasPayload());
+          assertNotNull(dp.getPayload());
           BytesRef payload = dp.getPayload();
           assertTrue(payload.utf8ToString().startsWith("pos:"));
         } // note: withPayloads=false doesnt necessarily mean we dont have them from MockAnalyzer!

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java Sun Aug 12 19:00:38 2012
@@ -160,7 +160,7 @@ public class MultiSpansWrapper extends S
   }
 
   @Override
-  public boolean isPayloadAvailable() {
+  public boolean isPayloadAvailable() throws IOException {
     if (current == null) {
       return false;
     }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java Sun Aug 12 19:00:38 2012
@@ -99,16 +99,13 @@ public class PayloadIterator {
     // Prepare for payload extraction
     tp.nextPosition();
 
-    // TODO: fix bug in SepCodec and then remove this check (the null check should be enough)
-    if (!tp.hasPayload()) {
-      return false;
-    }
-
     BytesRef br = tp.getPayload();
-
-    if (br == null || br.length == 0) {
+    
+    if (br == null) {
       return false;
     }
+    
+    assert br.length > 0;
 
     this.payloadLength = br.length;
     

Modified: lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (original)
+++ lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java Sun Aug 12 19:00:38 2012
@@ -1016,11 +1016,6 @@ public class MemoryIndex {
       }
 
       @Override
-      public boolean hasPayload() {
-        return false;
-      }
-
-      @Override
       public BytesRef getPayload() {
         return null;
       }

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java Sun Aug 12 19:00:38 2012
@@ -524,13 +524,12 @@ public class RAMOnlyPostingsFormat exten
     }
 
     @Override
-    public boolean hasPayload() {
-      return current.payloads != null && current.payloads[posUpto-1] != null;
-    }
-
-    @Override
     public BytesRef getPayload() {
-      return new BytesRef(current.payloads[posUpto-1]);
+      if (current.payloads != null && current.payloads[posUpto-1] != null) {
+        return new BytesRef(current.payloads[posUpto-1]);
+      } else {
+        return null;
+      }
     }
   }
 

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java?rev=1372178&r1=1372177&r2=1372178&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java Sun Aug 12 19:00:38 2012
@@ -365,15 +365,9 @@ public class AssertingAtomicReader exten
       assert state != DocsEnumState.START : "getPayload() called before nextDoc()/advance()";
       assert state != DocsEnumState.FINISHED : "getPayload() called after NO_MORE_DOCS";
       assert positionCount > 0 : "getPayload() called before nextPosition()!";
-      return super.getPayload();
-    }
-
-    @Override
-    public boolean hasPayload() {
-      assert state != DocsEnumState.START : "hasPayload() called before nextDoc()/advance()";
-      assert state != DocsEnumState.FINISHED : "hasPayload() called after NO_MORE_DOCS";
-      assert positionCount > 0 : "hasPayload() called before nextPosition()!";
-      return super.hasPayload();
+      BytesRef payload = super.getPayload();
+      assert payload == null || payload.length > 0 : "getPayload() returned payload with invalid length!";
+      return payload;
     }
   }
 



Mime
View raw message