You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2014/11/12 15:56:24 UTC

svn commit: r1638805 [2/8] - in /lucene/dev/lucene2878: dev-tools/idea/lucene/highlighter/ lucene/analysis/common/src/test/org/apache/lucene/analysis/sinks/ lucene/analysis/common/src/test/org/apache/lucene/analysis/standard/ lucene/codecs/src/java/org...

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/PushPostingsWriterBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/PushPostingsWriterBase.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/PushPostingsWriterBase.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/PushPostingsWriterBase.java Wed Nov 12 14:56:17 2014
@@ -17,9 +17,6 @@ package org.apache.lucene.codecs;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
-import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexOptions;
@@ -27,6 +24,8 @@ import org.apache.lucene.index.TermsEnum
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.FixedBitSet;
 
+import java.io.IOException;
+
 /**
  * Extension of {@link PostingsWriterBase}, adding a push
  * API for writing each element of the postings.  This API
@@ -43,7 +42,6 @@ public abstract class PushPostingsWriter
 
   // Reused in writeTerm
   private DocsEnum docsEnum;
-  private DocsAndPositionsEnum posEnum;
   private int enumFlags;
 
   /** {@link FieldInfo} of current field being written. */
@@ -103,15 +101,15 @@ public abstract class PushPostingsWriter
       enumFlags = DocsEnum.FLAG_FREQS;
     } else if (writeOffsets == false) {
       if (writePayloads) {
-        enumFlags = DocsAndPositionsEnum.FLAG_PAYLOADS;
+        enumFlags = DocsEnum.FLAG_PAYLOADS;
       } else {
         enumFlags = 0;
       }
     } else {
       if (writePayloads) {
-        enumFlags = DocsAndPositionsEnum.FLAG_PAYLOADS | DocsAndPositionsEnum.FLAG_OFFSETS;
+        enumFlags = DocsEnum.FLAG_PAYLOADS | DocsEnum.FLAG_OFFSETS;
       } else {
-        enumFlags = DocsAndPositionsEnum.FLAG_OFFSETS;
+        enumFlags = DocsEnum.FLAG_OFFSETS;
       }
     }
 
@@ -124,8 +122,7 @@ public abstract class PushPostingsWriter
     if (writePositions == false) {
       docsEnum = termsEnum.docs(null, docsEnum, enumFlags);
     } else {
-      posEnum = termsEnum.docsAndPositions(null, posEnum, enumFlags);
-      docsEnum = posEnum;
+      docsEnum = termsEnum.docsAndPositions(null, docsEnum, enumFlags);
     }
     assert docsEnum != null;
 
@@ -149,13 +146,13 @@ public abstract class PushPostingsWriter
 
       if (writePositions) {
         for(int i=0;i<freq;i++) {
-          int pos = posEnum.nextPosition();
-          BytesRef payload = writePayloads ? posEnum.getPayload() : null;
+          int pos = docsEnum.nextPosition();
+          BytesRef payload = writePayloads ? docsEnum.getPayload() : null;
           int startOffset;
           int endOffset;
           if (writeOffsets) {
-            startOffset = posEnum.startOffset();
-            endOffset = posEnum.endOffset();
+            startOffset = docsEnum.startOffset();
+            endOffset = docsEnum.endOffset();
           } else {
             startOffset = -1;
             endOffset = -1;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsReader.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsReader.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsReader.java Wed Nov 12 14:56:17 2014
@@ -21,7 +21,7 @@ import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; // javadocs
-import org.apache.lucene.index.DocsAndPositionsEnum; // javadocs
+import org.apache.lucene.index.DocsEnum; // javadocs
 import org.apache.lucene.index.Fields;
 import org.apache.lucene.util.Accountable;
 
@@ -40,7 +40,7 @@ public abstract class TermVectorsReader 
   /** Returns term vectors for this document, or null if
    *  term vectors were not indexed. If offsets are
    *  available they are in an {@link OffsetAttribute}
-   *  available from the {@link DocsAndPositionsEnum}. */
+   *  available from the {@link DocsEnum}. */
   public abstract Fields get(int doc) throws IOException;
   
   /** 

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java Wed Nov 12 14:56:17 2014
@@ -17,11 +17,7 @@ package org.apache.lucene.codecs;
  * limitations under the License.
  */
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.Iterator;
-
-import org.apache.lucene.index.DocsAndPositionsEnum;
+import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FieldInfos;
 import org.apache.lucene.index.Fields;
@@ -34,6 +30,10 @@ import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Iterator;
+
 /**
  * Codec API for writing term vectors:
  * <p>
@@ -230,7 +230,7 @@ public abstract class TermVectorsWriter 
     String lastFieldName = null;
     
     TermsEnum termsEnum = null;
-    DocsAndPositionsEnum docsAndPositionsEnum = null;
+    DocsEnum docsAndPositionsEnum = null;
     
     int fieldCount = 0;
     for(String fieldName : vectors) {
@@ -287,7 +287,7 @@ public abstract class TermVectorsWriter 
             
             final BytesRef payload = docsAndPositionsEnum.getPayload();
 
-            assert !hasPositions || pos >= 0;
+            assert !hasPositions || pos >= 0 ;
             addPosition(pos, startOffset, endOffset, payload);
           }
         }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java Wed Nov 12 14:56:17 2014
@@ -17,9 +17,6 @@ package org.apache.lucene.codecs.blocktr
  * limitations under the License.
  */
 
-import java.io.IOException;
-
-import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.IndexOptions;
 import org.apache.lucene.index.TermState;
@@ -36,6 +33,8 @@ import org.apache.lucene.util.fst.ByteSe
 import org.apache.lucene.util.fst.FST;
 import org.apache.lucene.util.fst.Outputs;
 
+import java.io.IOException;
+
 // NOTE: cannot seek!
 final class IntersectTermsEnum extends TermsEnum {
   final IndexInput in;
@@ -209,7 +208,7 @@ final class IntersectTermsEnum extends T
   }
 
   @Override
-  public DocsAndPositionsEnum docsAndPositions(Bits skipDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+  public DocsEnum docsAndPositions(Bits skipDocs, DocsEnum reuse, int flags) throws IOException {
     if (fr.fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
       // Positions were not indexed:
       return null;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnum.java Wed Nov 12 14:56:17 2014
@@ -17,11 +17,7 @@ package org.apache.lucene.codecs.blocktr
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.io.PrintStream;
-
 import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.IndexOptions;
 import org.apache.lucene.index.TermState;
@@ -36,6 +32,9 @@ import org.apache.lucene.util.RamUsageEs
 import org.apache.lucene.util.fst.FST;
 import org.apache.lucene.util.fst.Util;
 
+import java.io.IOException;
+import java.io.PrintStream;
+
 /** Iterates through terms in this field */
 final class SegmentTermsEnum extends TermsEnum {
 
@@ -994,7 +993,7 @@ final class SegmentTermsEnum extends Ter
   }
 
   @Override
-  public DocsAndPositionsEnum docsAndPositions(Bits skipDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+  public DocsEnum docsAndPositions(Bits skipDocs, DocsEnum reuse, int flags) throws IOException {
     if (fr.fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
       // Positions were not indexed:
       return null;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsReader.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsReader.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsReader.java Wed Nov 12 14:56:17 2014
@@ -17,28 +17,9 @@ package org.apache.lucene.codecs.compres
  * limitations under the License.
  */
 
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.BLOCK_SIZE;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.CODEC_SFX_DAT;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.CODEC_SFX_IDX;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.FLAGS_BITS;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.OFFSETS;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.PAYLOADS;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.POSITIONS;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VECTORS_EXTENSION;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VECTORS_INDEX_EXTENSION;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VERSION_CURRENT;
-import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VERSION_START;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.codecs.TermVectorsReader;
 import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FieldInfos;
@@ -63,6 +44,23 @@ import org.apache.lucene.util.LongsRef;
 import org.apache.lucene.util.packed.BlockPackedReaderIterator;
 import org.apache.lucene.util.packed.PackedInts;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.BLOCK_SIZE;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.CODEC_SFX_DAT;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.CODEC_SFX_IDX;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.FLAGS_BITS;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.OFFSETS;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.PAYLOADS;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.POSITIONS;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VECTORS_EXTENSION;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VECTORS_INDEX_EXTENSION;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VERSION_CURRENT;
+import static org.apache.lucene.codecs.compressing.CompressingTermVectorsWriter.VERSION_START;
 
 /**
  * {@link TermVectorsReader} for {@link CompressingTermVectorsFormat}.
@@ -915,17 +913,17 @@ public final class CompressingTermVector
     }
 
     @Override
-    public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+    public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
       if (positions == null && startOffsets == null) {
         return null;
       }
       // TODO: slightly sheisty
-      return (DocsAndPositionsEnum) docs(liveDocs, reuse, flags);
+      return docs(liveDocs, reuse, flags);
     }
 
   }
 
-  private static class TVDocsEnum extends DocsAndPositionsEnum {
+  private static class TVDocsEnum extends DocsEnum {
 
     private Bits liveDocs;
     private int doc = -1;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50DocValuesProducer.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50DocValuesProducer.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50DocValuesProducer.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50DocValuesProducer.java Wed Nov 12 14:56:17 2014
@@ -17,41 +17,11 @@ package org.apache.lucene.codecs.lucene5
  * limitations under the License.
  */
 
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BINARY_FIXED_UNCOMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BINARY_PREFIX_COMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BINARY_VARIABLE_UNCOMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.CONST_COMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.DELTA_COMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.GCD_COMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.MONOTONIC_COMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.SORTED_SINGLE_VALUED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.SORTED_WITH_ADDRESSES;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.TABLE_COMPRESSED;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.INTERVAL_SHIFT;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.INTERVAL_COUNT;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.INTERVAL_MASK;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.REVERSE_INTERVAL_SHIFT;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.REVERSE_INTERVAL_MASK;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BLOCK_INTERVAL_SHIFT;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BLOCK_INTERVAL_MASK;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.ALL_LIVE;
-import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.ALL_MISSING;
-
-import java.io.Closeable; // javadocs
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.codecs.DocValuesProducer;
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FieldInfos;
@@ -77,6 +47,35 @@ import org.apache.lucene.util.RamUsageEs
 import org.apache.lucene.util.packed.DirectReader;
 import org.apache.lucene.util.packed.MonotonicBlockPackedReader;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.ALL_LIVE;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.ALL_MISSING;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BINARY_FIXED_UNCOMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BINARY_PREFIX_COMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BINARY_VARIABLE_UNCOMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BLOCK_INTERVAL_MASK;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.BLOCK_INTERVAL_SHIFT;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.CONST_COMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.DELTA_COMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.GCD_COMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.INTERVAL_COUNT;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.INTERVAL_MASK;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.INTERVAL_SHIFT;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.MONOTONIC_COMPRESSED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.REVERSE_INTERVAL_MASK;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.REVERSE_INTERVAL_SHIFT;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.SORTED_SINGLE_VALUED;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.SORTED_WITH_ADDRESSES;
+import static org.apache.lucene.codecs.lucene50.Lucene50DocValuesConsumer.TABLE_COMPRESSED;
+
 /** reader for {@link Lucene50DocValuesFormat} */
 class Lucene50DocValuesProducer extends DocValuesProducer implements Closeable {
   private final Map<String,NumericEntry> numerics = new HashMap<>();
@@ -1145,7 +1144,7 @@ class Lucene50DocValuesProducer extends 
       }
       
       @Override
-      public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+      public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
         throw new UnsupportedOperationException();
       }
     }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java Wed Nov 12 14:56:17 2014
@@ -17,15 +17,10 @@ package org.apache.lucene.codecs.lucene5
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-
 import org.apache.lucene.codecs.BlockTermState;
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.codecs.PostingsReaderBase;
 import org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat.IntBlockTermState;
-import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexFileNames;
@@ -40,6 +35,10 @@ import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.RamUsageEstimator;
 
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
 import static org.apache.lucene.codecs.lucene50.ForUtil.MAX_DATA_SIZE;
 import static org.apache.lucene.codecs.lucene50.ForUtil.MAX_ENCODED_SIZE;
 import static org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat.BLOCK_SIZE;
@@ -196,30 +195,38 @@ public final class Lucene50PostingsReade
     
   @Override
   public DocsEnum docs(FieldInfo fieldInfo, BlockTermState termState, Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
-    BlockDocsEnum docsEnum;
-    if (reuse instanceof BlockDocsEnum) {
-      docsEnum = (BlockDocsEnum) reuse;
-      if (!docsEnum.canReuse(docIn, fieldInfo)) {
+    if ((flags & DocsEnum.FLAG_POSITIONS) != DocsEnum.FLAG_POSITIONS) {
+      BlockDocsEnum docsEnum;
+      if (reuse instanceof BlockDocsEnum) {
+        docsEnum = (BlockDocsEnum) reuse;
+        if (!docsEnum.canReuse(docIn, fieldInfo)) {
+          docsEnum = new BlockDocsEnum(fieldInfo);
+        }
+      } else {
         docsEnum = new BlockDocsEnum(fieldInfo);
       }
-    } else {
-      docsEnum = new BlockDocsEnum(fieldInfo);
+      return docsEnum.reset(liveDocs, (IntBlockTermState) termState, flags);
     }
-    return docsEnum.reset(liveDocs, (IntBlockTermState) termState, flags);
+
+    return docsAndPositions(fieldInfo, termState, liveDocs, reuse, flags);
   }
 
   // TODO: specialize to liveDocs vs not
   
   @Override
-  public DocsAndPositionsEnum docsAndPositions(FieldInfo fieldInfo, BlockTermState termState, Bits liveDocs,
-                                               DocsAndPositionsEnum reuse, int flags)
+  public DocsEnum docsAndPositions(FieldInfo fieldInfo, BlockTermState termState, Bits liveDocs,
+                                               DocsEnum reuse, int flags)
     throws IOException {
 
+    boolean indexHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
     boolean indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
     boolean indexHasPayloads = fieldInfo.hasPayloads();
 
-    if ((!indexHasOffsets || (flags & DocsAndPositionsEnum.FLAG_OFFSETS) == 0) &&
-        (!indexHasPayloads || (flags & DocsAndPositionsEnum.FLAG_PAYLOADS) == 0)) {
+    if (!indexHasPositions)
+      return null;
+
+    if ((!indexHasOffsets || (flags & DocsEnum.FLAG_OFFSETS) == 0) &&
+        (!indexHasPayloads || (flags & DocsEnum.FLAG_PAYLOADS) == 0)) {
       BlockDocsAndPositionsEnum docsAndPositionsEnum;
       if (reuse instanceof BlockDocsAndPositionsEnum) {
         docsAndPositionsEnum = (BlockDocsAndPositionsEnum) reuse;
@@ -339,6 +346,11 @@ public final class Lucene50PostingsReade
     }
 
     @Override
+    public int nextPosition() throws IOException {
+      return -1;
+    }
+
+    @Override
     public int docID() {
       return doc;
     }
@@ -474,7 +486,7 @@ public final class Lucene50PostingsReade
   }
 
 
-  final class BlockDocsAndPositionsEnum extends DocsAndPositionsEnum {
+  final class BlockDocsAndPositionsEnum extends DocsEnum {
     
     private final byte[] encoded;
 
@@ -552,7 +564,7 @@ public final class Lucene50PostingsReade
         indexHasPayloads == fieldInfo.hasPayloads();
     }
     
-    public DocsAndPositionsEnum reset(Bits liveDocs, IntBlockTermState termState) throws IOException {
+    public DocsEnum reset(Bits liveDocs, IntBlockTermState termState) throws IOException {
       this.liveDocs = liveDocs;
 
       docFreq = termState.docFreq;
@@ -771,6 +783,10 @@ public final class Lucene50PostingsReade
 
     @Override
     public int nextPosition() throws IOException {
+
+      if (posPendingCount == 0)
+        return NO_MORE_POSITIONS;
+
       if (posPendingFP != -1) {
         posIn.seek(posPendingFP);
         posPendingFP = -1;
@@ -794,6 +810,16 @@ public final class Lucene50PostingsReade
     }
 
     @Override
+    public int startPosition() {
+      return position;
+    }
+
+    @Override
+    public int endPosition() {
+      return position;
+    }
+
+    @Override
     public int startOffset() {
       return -1;
     }
@@ -815,7 +841,7 @@ public final class Lucene50PostingsReade
   }
 
   // Also handles payloads + offsets
-  final class EverythingEnum extends DocsAndPositionsEnum {
+  final class EverythingEnum extends DocsEnum {
     
     private final byte[] encoded;
 
@@ -962,8 +988,8 @@ public final class Lucene50PostingsReade
         lastPosBlockFP = posTermStartFP + termState.lastPosBlockOffset;
       }
 
-      this.needsOffsets = (flags & DocsAndPositionsEnum.FLAG_OFFSETS) != 0;
-      this.needsPayloads = (flags & DocsAndPositionsEnum.FLAG_PAYLOADS) != 0;
+      this.needsOffsets = (flags & DocsEnum.FLAG_OFFSETS) != 0;
+      this.needsPayloads = (flags & DocsEnum.FLAG_PAYLOADS) != 0;
 
       doc = -1;
       accum = 0;
@@ -1230,6 +1256,9 @@ public final class Lucene50PostingsReade
 
     @Override
     public int nextPosition() throws IOException {
+      if (posPendingCount == 0)
+        return NO_MORE_POSITIONS;
+
       if (posPendingFP != -1) {
         posIn.seek(posPendingFP);
         posPendingFP = -1;
@@ -1274,6 +1303,16 @@ public final class Lucene50PostingsReade
     }
 
     @Override
+    public int startPosition() {
+      return position;
+    }
+
+    @Override
+    public int endPosition() {
+      return position;
+    }
+
+    @Override
     public int startOffset() {
       return startOffset;
     }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java Wed Nov 12 14:56:17 2014
@@ -889,7 +889,7 @@ public class CheckIndex implements Close
     
     DocsEnum docs = null;
     DocsEnum docsAndFreqs = null;
-    DocsAndPositionsEnum postings = null;
+    DocsEnum postings = null;
     
     String lastField = null;
     for (String field : fields) {
@@ -1812,11 +1812,11 @@ public class CheckIndex implements Close
       }
 
       DocsEnum docs = null;
-      DocsAndPositionsEnum postings = null;
+      DocsEnum postings = null;
 
       // Only used if crossCheckTermVectors is true:
       DocsEnum postingsDocs = null;
-      DocsAndPositionsEnum postingsPostings = null;
+      DocsEnum postingsPostings = null;
 
       final Bits liveDocs = reader.getLiveDocs();
 

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java Wed Nov 12 14:56:17 2014
@@ -17,11 +17,12 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.util.AttributeSource;
-import org.apache.lucene.util.Bits; // javadocs
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+
+import java.io.IOException;
 
 /** Iterates through the documents and term freqs.
  *  NOTE: you must first call {@link #nextDoc} before using
@@ -30,9 +31,7 @@ public abstract class DocsEnum extends D
   
   /**
    * Flag to pass to {@link TermsEnum#docs(Bits,DocsEnum,int)} if you don't
-   * require term frequencies in the returned enum. When passed to
-   * {@link TermsEnum#docsAndPositions(Bits,DocsAndPositionsEnum,int)} means
-   * that no offsets and payloads will be returned.
+   * require term frequencies in the returned enum.
    */
   public static final int FLAG_NONE = 0x0;
 
@@ -40,6 +39,20 @@ public abstract class DocsEnum extends D
    *  if you require term frequencies in the returned enum. */
   public static final int FLAG_FREQS = 0x1;
 
+  /** Flag to pass to {@link TermsEnum#docs(Bits,DocsEnum,int)}
+   * if you require term positions in the returned enum. */
+  public static final int FLAG_POSITIONS = 0x3;
+  
+  /** Flag to pass to {@link TermsEnum#docs(Bits,DocsEnum,int)}
+   *  if you require offsets in the returned enum. */
+  public static final int FLAG_OFFSETS = 0x7;
+
+  /** Flag to pass to  {@link TermsEnum#docs(Bits,DocsEnum,int)}
+   *  if you require payloads in the returned enum. */
+  public static final int FLAG_PAYLOADS = 0x11;
+
+  public static final int NO_MORE_POSITIONS = Integer.MAX_VALUE;
+
   private AttributeSource atts = null;
 
   /** Sole constructor. (For invocation by subclass 
@@ -64,4 +77,40 @@ public abstract class DocsEnum extends D
     if (atts == null) atts = new AttributeSource();
     return atts;
   }
+
+  /** Returns the next position.  You should only call this
+   *  up to {@link DocsEnum#freq()} times else
+   *  the behavior is not defined.  If positions were not
+   *  indexed this will return -1; this only happens if
+   *  offsets were indexed and you passed needsOffset=true
+   *  when pulling the enum.  */
+  public abstract int nextPosition() throws IOException;
+
+  public int startPosition() throws IOException {
+    throw new UnsupportedOperationException("startPosition() is not implemented on " + this.getClass().getSimpleName());
+  }
+
+  public int endPosition() throws IOException {
+    throw new UnsupportedOperationException("endPosition() is not implemented on " + this.getClass().getSimpleName());
+  }
+
+  /** Returns start offset for the current position, or -1
+   *  if offsets were not indexed. */
+  public int startOffset() throws IOException {
+    throw new UnsupportedOperationException("startOffset() is not implemented on " + this.getClass().getSimpleName());
+  }
+
+  /** Returns end offset for the current position, or -1 if
+   *  offsets were not indexed. */
+  public int endOffset() throws IOException {
+    throw new UnsupportedOperationException("endOffset() is not implemented on " + this.getClass().getSimpleName());
+  }
+
+  /** Returns the payload at this position, or null if no
+   *  payload was indexed. You should not modify anything 
+   *  (neither members of the returned BytesRef nor bytes 
+   *  in the byte[]). */
+  public BytesRef getPayload() throws IOException {
+    return null;
+  }
 }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java Wed Nov 12 14:56:17 2014
@@ -17,14 +17,14 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.Iterator;
-
 import org.apache.lucene.search.CachingWrapperFilter;
 import org.apache.lucene.util.AttributeSource;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 
+import java.io.IOException;
+import java.util.Iterator;
+
 /**  A <code>FilterLeafReader</code> contains another LeafReader, which it
  * uses as its basic source of data, possibly transforming the data along the
  * way or providing additional functionality. The class
@@ -220,7 +220,7 @@ public class FilterLeafReader extends Le
     }
 
     @Override
-    public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+    public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
       return in.docsAndPositions(liveDocs, reuse, flags);
     }
   }
@@ -267,55 +267,18 @@ public class FilterLeafReader extends Le
     }
 
     @Override
-    public long cost() {
-      return in.cost();
-    }
-  }
-
-  /** Base class for filtering {@link DocsAndPositionsEnum} implementations. */
-  public static class FilterDocsAndPositionsEnum extends DocsAndPositionsEnum {
-    /** The underlying DocsAndPositionsEnum instance. */
-    protected final DocsAndPositionsEnum in;
-
-    /**
-     * Create a new FilterDocsAndPositionsEnum
-     * @param in the underlying DocsAndPositionsEnum instance.
-     */
-    public FilterDocsAndPositionsEnum(DocsAndPositionsEnum in) {
-      if (in == null) {
-        throw new NullPointerException("incoming DocsAndPositionsEnum cannot be null");
-      }
-      this.in = in;
-    }
-
-    @Override
-    public AttributeSource attributes() {
-      return in.attributes();
-    }
-
-    @Override
-    public int docID() {
-      return in.docID();
-    }
-
-    @Override
-    public int freq() throws IOException {
-      return in.freq();
-    }
-
-    @Override
-    public int nextDoc() throws IOException {
-      return in.nextDoc();
+    public int nextPosition() throws IOException {
+      return in.nextPosition();
     }
 
     @Override
-    public int advance(int target) throws IOException {
-      return in.advance(target);
+    public int startPosition() throws IOException {
+      return in.startPosition();
     }
 
     @Override
-    public int nextPosition() throws IOException {
-      return in.nextPosition();
+    public int endPosition() throws IOException {
+      return in.endPosition();
     }
 
     @Override
@@ -332,7 +295,7 @@ public class FilterLeafReader extends Le
     public BytesRef getPayload() throws IOException {
       return in.getPayload();
     }
-    
+
     @Override
     public long cost() {
       return in.cost();

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java Wed Nov 12 14:56:17 2014
@@ -184,7 +184,7 @@ public abstract class FilteredTermsEnum 
   }
     
   @Override
-  public DocsAndPositionsEnum docsAndPositions(Bits bits, DocsAndPositionsEnum reuse, int flags) throws IOException {
+  public DocsEnum docsAndPositions(Bits bits, DocsEnum reuse, int flags) throws IOException {
     return tenum.docsAndPositions(bits, reuse, flags);
   }
   

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java Wed Nov 12 14:56:17 2014
@@ -17,18 +17,18 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import org.apache.lucene.index.FreqProxTermsWriterPerField.FreqProxPostingsArray;
+import org.apache.lucene.util.AttributeSource;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
+
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.FreqProxTermsWriterPerField.FreqProxPostingsArray;
-import org.apache.lucene.util.AttributeSource; // javadocs
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.BytesRefBuilder;
-
 /** Implements limited (iterators only, no stats) {@link
  *  Fields} interface over the in-RAM buffered
  *  fields/terms/postings, to flush postings through the
@@ -256,7 +256,7 @@ class FreqProxFields extends Fields {
     }
 
     @Override
-    public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) {
+    public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) {
       if (liveDocs != null) {
         throw new IllegalArgumentException("liveDocs must be null");
       }
@@ -268,7 +268,7 @@ class FreqProxFields extends Fields {
         throw new IllegalArgumentException("did not index positions");
       }
 
-      if (!terms.hasOffsets && (flags & DocsAndPositionsEnum.FLAG_OFFSETS) != 0) {
+      if (!terms.hasOffsets && (flags & DocsEnum.FLAG_OFFSETS) == DocsEnum.FLAG_OFFSETS) {
         // Caller wants offsets but we didn't index them;
         // don't lie:
         throw new IllegalArgumentException("did not index offsets");
@@ -348,6 +348,11 @@ class FreqProxFields extends Fields {
     }
 
     @Override
+    public int nextPosition() throws IOException {
+      return -1;
+    }
+
+    @Override
     public int nextDoc() throws IOException {
       if (reader.eof()) {
         if (ended) {
@@ -389,7 +394,7 @@ class FreqProxFields extends Fields {
     }
   }
 
-  private static class FreqProxDocsAndPositionsEnum extends DocsAndPositionsEnum {
+  private static class FreqProxDocsAndPositionsEnum extends DocsEnum {
 
     final FreqProxTermsWriterPerField terms;
     final FreqProxPostingsArray postingsArray;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/LeafReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/LeafReader.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/LeafReader.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/LeafReader.java Wed Nov 12 14:56:17 2014
@@ -17,11 +17,10 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
-import org.apache.lucene.index.IndexReader.ReaderClosedListener;
 import org.apache.lucene.util.Bits;
 
+import java.io.IOException;
+
 /** {@code LeafReader} is an abstract class, providing an interface for accessing an
  index.  Search of an index is done entirely through this abstract interface,
  so that any subclass which implements it is searchable. IndexReaders implemented
@@ -238,11 +237,11 @@ public abstract class LeafReader extends
     return null;
   }
 
-  /** Returns {@link DocsAndPositionsEnum} for the specified
+  /** Returns {@link DocsEnum} for the specified
    *  term.  This will return null if the
    *  field or term does not exist or positions weren't indexed.
-   *  @see TermsEnum#docsAndPositions(Bits, DocsAndPositionsEnum) */
-  public final DocsAndPositionsEnum termPositionsEnum(Term term) throws IOException {
+   *  @see TermsEnum#docsAndPositions(Bits, DocsEnum) */
+  public final DocsEnum termPositionsEnum(Term term) throws IOException {
     assert term.field() != null;
     assert term.bytes() != null;
     final Fields fields = fields();

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappedMultiFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappedMultiFields.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappedMultiFields.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappedMultiFields.java Wed Nov 12 14:56:17 2014
@@ -17,10 +17,10 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.util.Bits;
 
+import java.io.IOException;
+
 import static org.apache.lucene.index.FilterLeafReader.FilterFields;
 import static org.apache.lucene.index.FilterLeafReader.FilterTerms;
 import static org.apache.lucene.index.FilterLeafReader.FilterTermsEnum;
@@ -120,7 +120,7 @@ public class MappedMultiFields extends F
     }
 
     @Override
-    public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+    public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
       if (liveDocs != null) {
         throw new IllegalArgumentException("liveDocs must be null");
       }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsAndPositionsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsAndPositionsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsAndPositionsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsAndPositionsEnum.java Wed Nov 12 14:56:17 2014
@@ -29,12 +29,12 @@ import java.io.IOException;
  * @lucene.experimental
  */
 
-final class MappingMultiDocsAndPositionsEnum extends DocsAndPositionsEnum {
+final class MappingMultiDocsAndPositionsEnum extends DocsEnum {
   private MultiDocsAndPositionsEnum.EnumWithSlice[] subs;
   int numSubs;
   int upto;
   MergeState.DocMap currentMap;
-  DocsAndPositionsEnum current;
+  DocsEnum current;
   int currentBase;
   int doc = -1;
   private MergeState mergeState;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MappingMultiDocsEnum.java Wed Nov 12 14:56:17 2014
@@ -70,6 +70,11 @@ final class MappingMultiDocsEnum extends
   }
 
   @Override
+  public int nextPosition() throws IOException {
+    return -1;
+  }
+
+  @Override
   public int docID() {
     return doc;
   }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java Wed Nov 12 14:56:17 2014
@@ -28,20 +28,20 @@ import java.util.Arrays;
  * @lucene.experimental
  */
 
-public final class MultiDocsAndPositionsEnum extends DocsAndPositionsEnum {
+public final class MultiDocsAndPositionsEnum extends DocsEnum {
   private final MultiTermsEnum parent;
-  final DocsAndPositionsEnum[] subDocsAndPositionsEnum;
+  final DocsEnum[] subDocsAndPositionsEnum;
   private final EnumWithSlice[] subs;
   int numSubs;
   int upto;
-  DocsAndPositionsEnum current;
+  DocsEnum current;
   int currentBase;
   int doc = -1;
 
   /** Sole constructor. */
   public MultiDocsAndPositionsEnum(MultiTermsEnum parent, int subReaderCount) {
     this.parent = parent;
-    subDocsAndPositionsEnum = new DocsAndPositionsEnum[subReaderCount];
+    subDocsAndPositionsEnum = new DocsEnum[subReaderCount];
     this.subs = new EnumWithSlice[subReaderCount];
     for (int i = 0; i < subs.length; i++) {
       subs[i] = new EnumWithSlice();
@@ -159,14 +159,14 @@ public final class MultiDocsAndPositions
   }
 
   // TODO: implement bulk read more efficiently than super
-  /** Holds a {@link DocsAndPositionsEnum} along with the
+  /** Holds a {@link DocsEnum} along with the
    *  corresponding {@link ReaderSlice}. */
   public final static class EnumWithSlice {
     EnumWithSlice() {
     }
 
-    /** {@link DocsAndPositionsEnum} for this sub-reader. */
-    public DocsAndPositionsEnum docsAndPositionsEnum;
+    /** {@link DocsEnum} for this sub-reader. */
+    public DocsEnum docsAndPositionsEnum;
 
     /** {@link ReaderSlice} describing how this sub-reader
      *  fits into the composite reader. */

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiDocsEnum.java Wed Nov 12 14:56:17 2014
@@ -18,6 +18,8 @@ package org.apache.lucene.index;
  */
 
 
+import org.apache.lucene.util.BytesRef;
+
 import java.io.IOException;
 import java.util.Arrays;
 
@@ -89,6 +91,26 @@ public final class MultiDocsEnum extends
   public int docID() {
     return doc;
   }
+  
+  @Override
+  public int nextPosition() throws IOException {
+    return current.nextPosition();
+  }
+
+  @Override
+  public int startOffset() throws IOException {
+    return current.startOffset();
+  }
+
+  @Override
+  public int endOffset() throws IOException {
+    return current.endOffset();
+  }
+
+  @Override
+  public BytesRef getPayload() throws IOException {
+    return current.getPayload();
+  }
 
   @Override
   public int advance(int target) throws IOException {

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiFields.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiFields.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiFields.java Wed Nov 12 14:56:17 2014
@@ -158,22 +158,22 @@ public final class MultiFields extends F
     return null;
   }
 
-  /** Returns {@link DocsAndPositionsEnum} for the specified
+  /** Returns {@link DocsEnum} for the specified
    *  field & term.  This will return null if the field or
    *  term does not exist or positions were not indexed. 
    *  @see #getTermPositionsEnum(IndexReader, Bits, String, BytesRef, int) */
-  public static DocsAndPositionsEnum getTermPositionsEnum(IndexReader r, Bits liveDocs, String field, BytesRef term) throws IOException {
-    return getTermPositionsEnum(r, liveDocs, field, term, DocsAndPositionsEnum.FLAG_OFFSETS | DocsAndPositionsEnum.FLAG_PAYLOADS);
+  public static DocsEnum getTermPositionsEnum(IndexReader r, Bits liveDocs, String field, BytesRef term) throws IOException {
+    return getTermPositionsEnum(r, liveDocs, field, term, DocsEnum.FLAG_OFFSETS | DocsEnum.FLAG_PAYLOADS);
   }
 
-  /** Returns {@link DocsAndPositionsEnum} for the specified
+  /** Returns {@link DocsEnum} for the specified
    *  field & term, with control over whether offsets and payloads are
    *  required.  Some codecs may be able to optimize
    *  their implementation when offsets and/or payloads are not
    *  required. This will return null if the field or term does not
    *  exist or positions were not indexed. See {@link
-   *  TermsEnum#docsAndPositions(Bits,DocsAndPositionsEnum,int)}. */
-  public static DocsAndPositionsEnum getTermPositionsEnum(IndexReader r, Bits liveDocs, String field, BytesRef term, int flags) throws IOException {
+   *  TermsEnum#docs(Bits,DocsEnum,int)}. */
+  public static DocsEnum getTermPositionsEnum(IndexReader r, Bits liveDocs, String field, BytesRef term, int flags) throws IOException {
     assert field != null;
     assert term != null;
     final Terms terms = getTerms(r, field);

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiTermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiTermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/MultiTermsEnum.java Wed Nov 12 14:56:17 2014
@@ -401,7 +401,7 @@ public final class MultiTermsEnum extend
   }
 
   @Override
-  public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+  public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
     MultiDocsAndPositionsEnum docsAndPositionsEnum;
     // Can only reuse if incoming enum is also a MultiDocsAndPositionsEnum
     if (reuse != null && reuse instanceof MultiDocsAndPositionsEnum) {
@@ -452,7 +452,7 @@ public final class MultiTermsEnum extend
       }
 
       assert entry.index < docsAndPositionsEnum.subDocsAndPositionsEnum.length: entry.index + " vs " + docsAndPositionsEnum.subDocsAndPositionsEnum.length + "; " + subs.length;
-      final DocsAndPositionsEnum subPostings = entry.terms.docsAndPositions(b, docsAndPositionsEnum.subDocsAndPositionsEnum[entry.index], flags);
+      final DocsEnum subPostings = entry.terms.docsAndPositions(b, docsAndPositionsEnum.subDocsAndPositionsEnum[entry.index], flags);
 
       if (subPostings != null) {
         docsAndPositionsEnum.subDocsAndPositionsEnum[entry.index] = subPostings;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedDocValuesTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedDocValuesTermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedDocValuesTermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedDocValuesTermsEnum.java Wed Nov 12 14:56:17 2014
@@ -17,12 +17,12 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
 
+import java.io.IOException;
+
 /** Implements a {@link TermsEnum} wrapping a provided
  * {@link SortedDocValues}. */
 
@@ -114,7 +114,7 @@ class SortedDocValuesTermsEnum extends T
   }
 
   @Override
-  public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+  public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
     throw new UnsupportedOperationException();
   }
 

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValuesTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValuesTermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValuesTermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValuesTermsEnum.java Wed Nov 12 14:56:17 2014
@@ -17,12 +17,12 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
 
+import java.io.IOException;
+
 /** Implements a {@link TermsEnum} wrapping a provided
  * {@link SortedSetDocValues}. */
 
@@ -114,7 +114,7 @@ class SortedSetDocValuesTermsEnum extend
   }
 
   @Override
-  public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+  public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
     throw new UnsupportedOperationException();
   }
 

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermContext.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermContext.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermContext.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermContext.java Wed Nov 12 14:56:17 2014
@@ -17,11 +17,11 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import org.apache.lucene.util.BytesRef;
+
 import java.io.IOException;
 import java.util.Arrays;
 
-import org.apache.lucene.util.BytesRef;
-
 /**
  * Maintains a {@link IndexReader} {@link TermState} view over
  * {@link IndexReader} instances containing a single term. The

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java Wed Nov 12 14:56:17 2014
@@ -17,18 +17,18 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.util.AttributeSource;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefIterator;
 
+import java.io.IOException;
+
 /** Iterator to seek ({@link #seekCeil(BytesRef)}, {@link
  * #seekExact(BytesRef)}) or step through ({@link
  * #next} terms to obtain frequency information ({@link
  * #docFreq}), {@link DocsEnum} or {@link
- * DocsAndPositionsEnum} for the current term ({@link
+ * DocsEnum} for the current term ({@link
  * #docs}.
  * 
  * <p>Term enumerations are always ordered by
@@ -162,20 +162,20 @@ public abstract class TermsEnum implemen
    * @see #docs(Bits, DocsEnum, int) */
   public abstract DocsEnum docs(Bits liveDocs, DocsEnum reuse, int flags) throws IOException;
 
-  /** Get {@link DocsAndPositionsEnum} for the current term.
+  /** Get {@link DocsEnum} for the current term.
    *  Do not call this when the enum is unpositioned.  This
    *  method will return null if positions were not
    *  indexed.
    *  
    *  @param liveDocs unset bits are documents that should not
    *  be returned
-   *  @param reuse pass a prior DocsAndPositionsEnum for possible reuse
-   *  @see #docsAndPositions(Bits, DocsAndPositionsEnum, int) */
-  public final DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse) throws IOException {
-    return docsAndPositions(liveDocs, reuse, DocsAndPositionsEnum.FLAG_OFFSETS | DocsAndPositionsEnum.FLAG_PAYLOADS);
+   *  @param reuse pass a prior DocsEnum for possible reuse
+   **/
+  public final DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse) throws IOException {
+    return docsAndPositions(liveDocs, reuse, DocsEnum.FLAG_OFFSETS | DocsEnum.FLAG_PAYLOADS);
   }
 
-  /** Get {@link DocsAndPositionsEnum} for the current term,
+  /** Get {@link DocsEnum} for the current term,
    *  with control over whether offsets and payloads are
    *  required.  Some codecs may be able to optimize their
    *  implementation when offsets and/or payloads are not required.
@@ -184,11 +184,11 @@ public abstract class TermsEnum implemen
 
    *  @param liveDocs unset bits are documents that should not
    *  be returned
-   *  @param reuse pass a prior DocsAndPositionsEnum for possible reuse
+   *  @param reuse pass a prior DocsEnum for possible reuse
    *  @param flags specifies which optional per-position values you
-   *         require; see {@link DocsAndPositionsEnum#FLAG_OFFSETS} and 
-   *         {@link DocsAndPositionsEnum#FLAG_PAYLOADS}. */
-  public abstract DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException;
+   *         require; see {@link DocsEnum#FLAG_OFFSETS} and 
+   *         {@link DocsEnum#FLAG_PAYLOADS}. */
+  public abstract DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags) throws IOException;
 
   /**
    * Expert: Returns the TermsEnums internal state to position the TermsEnum
@@ -250,11 +250,6 @@ public abstract class TermsEnum implemen
     }
       
     @Override
-    public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) {
-      throw new IllegalStateException("this method should never be called");
-    }
-      
-    @Override
     public BytesRef next() {
       return null;
     }
@@ -273,5 +268,11 @@ public abstract class TermsEnum implemen
     public void seekExact(BytesRef term, TermState state) {
       throw new IllegalStateException("this method should never be called");
     }
+
+    @Override
+    public DocsEnum docsAndPositions(Bits liveDocs, DocsEnum reuse, int flags)
+        throws IOException {
+      throw new IllegalStateException("this method should never be called");
+    }
   };
 }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java Wed Nov 12 14:56:17 2014
@@ -17,21 +17,22 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ToStringUtils;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
 /** A Query that matches documents matching boolean combinations of other
   * queries, e.g. {@link TermQuery}s, {@link PhraseQuery}s or other
   * BooleanQuerys.
@@ -242,7 +243,7 @@ public class BooleanQuery extends Query 
       for (Iterator<Weight> wIter = weights.iterator(); wIter.hasNext();) {
         Weight w = wIter.next();
         BooleanClause c = cIter.next();
-        if (w.scorer(context, context.reader().getLiveDocs()) == null) {
+        if (w.scorer(context, DocsEnum.FLAG_FREQS, context.reader().getLiveDocs()) == null) {
           if (c.isRequired()) {
             fail = true;
             Explanation r = new Explanation(0.0f, "no match on required clause (" + c.getQuery().toString() + ")");
@@ -305,13 +306,13 @@ public class BooleanQuery extends Query 
     }
 
     @Override
-    public BulkScorer bulkScorer(LeafReaderContext context, boolean scoreDocsInOrder,
+    public BulkScorer bulkScorer(LeafReaderContext context, boolean scoreDocsInOrder, int flags,
                                  Bits acceptDocs) throws IOException {
 
       if (scoreDocsInOrder || minNrShouldMatch > 1) {
         // TODO: (LUCENE-4872) in some cases BooleanScorer may be faster for minNrShouldMatch
         // but the same is even true of pure conjunctions...
-        return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
+        return super.bulkScorer(context, scoreDocsInOrder, flags, acceptDocs);
       }
 
       List<BulkScorer> prohibited = new ArrayList<BulkScorer>();
@@ -319,7 +320,7 @@ public class BooleanQuery extends Query 
       Iterator<BooleanClause> cIter = clauses.iterator();
       for (Weight w  : weights) {
         BooleanClause c =  cIter.next();
-        BulkScorer subScorer = w.bulkScorer(context, false, acceptDocs);
+        BulkScorer subScorer = w.bulkScorer(context, false, flags, acceptDocs);
         if (subScorer == null) {
           if (c.isRequired()) {
             return null;
@@ -328,7 +329,7 @@ public class BooleanQuery extends Query 
           // TODO: there are some cases where BooleanScorer
           // would handle conjunctions faster than
           // BooleanScorer2...
-          return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
+          return super.bulkScorer(context, scoreDocsInOrder, flags, acceptDocs);
         } else if (c.isProhibited()) {
           prohibited.add(subScorer);
         } else {
@@ -340,7 +341,7 @@ public class BooleanQuery extends Query 
     }
 
     @Override
-    public Scorer scorer(LeafReaderContext context, Bits acceptDocs)
+    public Scorer scorer(LeafReaderContext context, int flags, Bits acceptDocs)
         throws IOException {
       // initially the user provided value,
       // but if minNrShouldMatch == optional.size(),
@@ -353,7 +354,7 @@ public class BooleanQuery extends Query 
       Iterator<BooleanClause> cIter = clauses.iterator();
       for (Weight w  : weights) {
         BooleanClause c =  cIter.next();
-        Scorer subScorer = w.scorer(context, acceptDocs);
+        Scorer subScorer = w.scorer(context, flags, acceptDocs);
         if (subScorer == null) {
           if (c.isRequired()) {
             return null;
@@ -454,8 +455,17 @@ public class BooleanQuery extends Query 
       // scorer() will return an out-of-order scorer if requested.
       return true;
     }
+
+    @Override
+    public String toString() {
+      StringBuffer sb = new StringBuffer("BooleanWeight[");
+      for (Weight weight : weights) {
+        sb.append(weight.toString()).append(",");
+      }
+      return sb.append("]").toString();
+    }
     
-    private Scorer req(List<Scorer> required, boolean disableCoord) {
+    private Scorer req(List<Scorer> required, boolean disableCoord) throws IOException {
       if (required.size() == 1) {
         Scorer req = required.get(0);
         if (!disableCoord && maxCoord > 1) {

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java Wed Nov 12 14:56:17 2014
@@ -17,11 +17,12 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.index.DocsEnum;
+import org.apache.lucene.search.BooleanQuery.BooleanWeight;
+
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.lucene.search.BooleanQuery.BooleanWeight;
-
 /* Description from Doug Cutting (excerpted from
  * LUCENE-1483):
  *
@@ -98,8 +99,13 @@ final class BooleanScorer extends BulkSc
       return true;
     }
 
+    @Override
+    public int postingFeatures() {
+      return DocsEnum.FLAG_FREQS;
+    }
+
   }
-  
+
   static final class Bucket {
     int doc = -1;            // tells if bucket is valid
     double score;             // incremental score

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java Wed Nov 12 14:56:17 2014
@@ -21,8 +21,6 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
 
-import org.apache.lucene.search.Scorer.ChildScorer;
-
 /** Internal document-at-a-time scorers used to deal with stupid coord() computation */
 class BooleanTopLevelScorers {
   
@@ -61,7 +59,7 @@ class BooleanTopLevelScorers {
     private final Scorer req;
     private final Scorer opt;
     
-    CoordinatingConjunctionScorer(Weight weight, float coords[], Scorer req, int reqCount, Scorer opt) {
+    CoordinatingConjunctionScorer(Weight weight, float coords[], Scorer req, int reqCount, Scorer opt) throws IOException {
       super(weight, new Scorer[] { req, opt });
       this.coords = coords;
       this.req = req;

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java Wed Nov 12 14:56:17 2014
@@ -74,10 +74,16 @@ public abstract class CachingCollector e
     public final int freq() { throw new UnsupportedOperationException(); }
 
     @Override
+    public int nextPosition() throws IOException {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
     public final int nextDoc() { throw new UnsupportedOperationException(); }
 
     @Override
     public long cost() { return 1; }
+
   }
 
   private static class NoScoreCachingCollector extends CachingCollector {
@@ -96,6 +102,11 @@ public abstract class CachingCollector e
       docs = new ArrayList<>();
     }
 
+    @Override
+    public int postingFeatures() {
+      return in.postingFeatures();
+    }
+
     protected NoScoreCachingLeafCollector wrap(LeafCollector in, int maxDocsToCache) {
       return new NoScoreCachingLeafCollector(in, maxDocsToCache);
     }
@@ -304,7 +315,7 @@ public abstract class CachingCollector e
    * @param acceptDocsOutOfOrder
    *          whether documents are allowed to be collected out-of-order
    */
-  public static CachingCollector create(final boolean acceptDocsOutOfOrder, boolean cacheScores, double maxRAMMB) {
+  public static CachingCollector create(final boolean acceptDocsOutOfOrder, final int flags, boolean cacheScores, double maxRAMMB) {
     Collector other = new SimpleCollector() {
       @Override
       public boolean acceptsDocsOutOfOrder() {
@@ -312,6 +323,11 @@ public abstract class CachingCollector e
       }
 
       @Override
+      public int postingFeatures() {
+        return flags;
+      }
+
+      @Override
       public void collect(int doc) {}
 
     };

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/Collector.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/Collector.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/Collector.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/Collector.java Wed Nov 12 14:56:17 2014
@@ -17,10 +17,10 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.index.LeafReaderContext;
 
+import java.io.IOException;
+
 /**
  * <p>Expert: Collectors are primarily meant to be used to
  * gather raw results from a search, and implement sorting
@@ -72,5 +72,10 @@ public interface Collector {
    *          next atomic reader context
    */
   LeafCollector getLeafCollector(LeafReaderContext context) throws IOException;
-
+  
+  /**
+   * Returns the posting features required by this collector.
+   */
+  public int postingFeatures();
+  
 }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java Wed Nov 12 14:56:17 2014
@@ -17,126 +17,183 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.util.ArrayUtil;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
 
-import org.apache.lucene.util.ArrayUtil;
-
 /** Scorer for conjunctions, sets of queries, all of which are required. */
 class ConjunctionScorer extends Scorer {
-  protected int lastDoc = -1;
-  protected final DocsAndFreqs[] docsAndFreqs;
-  private final DocsAndFreqs lead;
+  
+  private final Scorer[] scorersOrdered;
+  private final Scorer[] scorers;
+  private int lastDoc = -1;
   private final float coord;
+  final PositionQueue posQueue;
 
-  ConjunctionScorer(Weight weight, Scorer[] scorers) {
+  public ConjunctionScorer(Weight weight, Scorer[] scorers) throws IOException {
     this(weight, scorers, 1f);
   }
   
-  ConjunctionScorer(Weight weight, Scorer[] scorers, float coord) {
+  public ConjunctionScorer(Weight weight, Scorer[] scorers, float coord) throws IOException {
     super(weight);
+    scorersOrdered = new Scorer[scorers.length];
+    System.arraycopy(scorers, 0, scorersOrdered, 0, scorers.length);
+    this.scorers = scorers;
     this.coord = coord;
-    this.docsAndFreqs = new DocsAndFreqs[scorers.length];
+    posQueue = new PositionQueue(scorers);
+    
     for (int i = 0; i < scorers.length; i++) {
-      docsAndFreqs[i] = new DocsAndFreqs(scorers[i]);
+      if (scorers[i].nextDoc() == NO_MORE_DOCS) {
+        // If even one of the sub-scorers does not have any documents, this
+        // scorer should not attempt to do any more work.
+        lastDoc = NO_MORE_DOCS;
+        return;
+      }
     }
-    // Sort the array the first time to allow the least frequent DocsEnum to
-    // lead the matching.
-    ArrayUtil.timSort(docsAndFreqs, new Comparator<DocsAndFreqs>() {
+
+    // Sort the array the first time...
+    // We don't need to sort the array in any future calls because we know
+    // it will already start off sorted (all scorers on same doc).
+    
+    // Note that this comparator is not consistent with equals!
+    // Also we use mergeSort here to be stable (so order of Scorers that
+    // match on first document keeps preserved):
+    ArrayUtil.timSort(scorers, new Comparator<Scorer>() { // sort the array
       @Override
-      public int compare(DocsAndFreqs o1, DocsAndFreqs o2) {
-        return Long.compare(o1.cost, o2.cost);
+      public int compare(Scorer o1, Scorer o2) {
+        return o1.docID() - o2.docID();
       }
     });
 
-    lead = docsAndFreqs[0]; // least frequent DocsEnum leads the intersection
-  }
+    // NOTE: doNext() must be called before the re-sorting of the array later on.
+    // The reason is this: assume there are 5 scorers, whose first docs are 1,
+    // 2, 3, 5, 5 respectively. Sorting (above) leaves the array as is. Calling
+    // doNext() here advances all the first scorers to 5 (or a larger doc ID
+    // they all agree on). 
+    // However, if we re-sort before doNext() is called, the order will be 5, 3,
+    // 2, 1, 5 and then doNext() will stop immediately, since the first scorer's
+    // docs equals the last one. So the invariant that after calling doNext() 
+    // all scorers are on the same doc ID is broken.
+    if (doNext() == NO_MORE_DOCS) {
+      // The scorers did not agree on any document.
+      lastDoc = NO_MORE_DOCS;
+      return;
+    }
 
-  private int doNext(int doc) throws IOException {
-    for(;;) {
-      // doc may already be NO_MORE_DOCS here, but we don't check explicitly
-      // since all scorers should advance to NO_MORE_DOCS, match, then
-      // return that value.
-      advanceHead: for(;;) {
-        for (int i = 1; i < docsAndFreqs.length; i++) {
-          // invariant: docsAndFreqs[i].doc <= doc at this point.
-
-          // docsAndFreqs[i].doc may already be equal to doc if we "broke advanceHead"
-          // on the previous iteration and the advance on the lead scorer exactly matched.
-          if (docsAndFreqs[i].doc < doc) {
-            docsAndFreqs[i].doc = docsAndFreqs[i].scorer.advance(doc);
-
-            if (docsAndFreqs[i].doc > doc) {
-              // DocsEnum beyond the current doc - break and advance lead to the new highest doc.
-              doc = docsAndFreqs[i].doc;
-              break advanceHead;
-            }
-          }
-        }
-        // success - all DocsEnums are on the same doc
-        return doc;
-      }
-      // advance head for next iteration
-      doc = lead.doc = lead.scorer.advance(doc);
+    // If first-time skip distance is any predictor of
+    // scorer sparseness, then we should always try to skip first on
+    // those scorers.
+    // Keep last scorer in it's last place (it will be the first
+    // to be skipped on), but reverse all of the others so that
+    // they will be skipped on in order of original high skip.
+    int end = scorers.length - 1;
+    int max = end >> 1;
+    for (int i = 0; i < max; i++) {
+      Scorer tmp = scorers[i];
+      int idx = end - i - 1;
+      scorers[i] = scorers[idx];
+      scorers[idx] = tmp;
     }
   }
 
+  private int doNext() throws IOException {
+    int first = 0;
+    int doc = scorers[scorers.length - 1].docID();
+    Scorer firstScorer;
+    while ((firstScorer = scorers[first]).docID() < doc) {
+      doc = firstScorer.advance(doc);
+      first = first == scorers.length - 1 ? 0 : first + 1;
+    }
+    posQueue.advanceTo(doc);
+    return doc;
+  }
+  
   @Override
   public int advance(int target) throws IOException {
-    lead.doc = lead.scorer.advance(target);
-    return lastDoc = doNext(lead.doc);
+    if (lastDoc == NO_MORE_DOCS) {
+      return lastDoc;
+    } else if (scorers[(scorers.length - 1)].docID() < target) {
+      scorers[(scorers.length - 1)].advance(target);
+    }
+    return lastDoc = doNext();
   }
 
   @Override
   public int docID() {
     return lastDoc;
   }
-
+  
   @Override
   public int nextDoc() throws IOException {
-    lead.doc = lead.scorer.nextDoc();
-    return lastDoc = doNext(lead.doc);
+    if (lastDoc == NO_MORE_DOCS) {
+      return lastDoc;
+    } else if (lastDoc == -1) {
+      lastDoc = scorers[scorers.length - 1].docID();
+      posQueue.advanceTo(lastDoc);
+      return lastDoc;
+    }
+    scorers[(scorers.length - 1)].nextDoc();
+    return lastDoc = doNext();
   }
-
+  
   @Override
   public float score() throws IOException {
     // TODO: sum into a double and cast to float if we ever send required clauses to BS1
     float sum = 0.0f;
-    for (DocsAndFreqs docs : docsAndFreqs) {
-      sum += docs.scorer.score();
+    for (int i = 0; i < scorers.length; i++) {
+      sum += scorers[i].score();
     }
     return sum * coord;
   }
-  
+
   @Override
-  public int freq() {
-    return docsAndFreqs.length;
+  public int freq() throws IOException {
+    return scorers.length;
   }
 
   @Override
-  public long cost() {
-    return lead.scorer.cost();
+  public int nextPosition() throws IOException {
+    return posQueue.nextPosition();
   }
 
   @Override
-  public Collection<ChildScorer> getChildren() {
-    ArrayList<ChildScorer> children = new ArrayList<>(docsAndFreqs.length);
-    for (DocsAndFreqs docs : docsAndFreqs) {
-      children.add(new ChildScorer(docs.scorer, "MUST"));
+  public int startPosition() throws IOException {
+    return posQueue.startPosition();
+  }
+
+  @Override
+  public int endPosition() throws IOException {
+    return posQueue.endPosition();
+  }
+
+  @Override
+  public int startOffset() throws IOException {
+    return posQueue.startOffset();
+  }
+
+  @Override
+  public int endOffset() throws IOException {
+    return posQueue.endOffset();
+  }
+
+  @Override
+  public long cost() {
+    long sum = 0;
+    for (int i = 0; i < scorers.length; i++) {
+      sum += scorers[i].cost();
     }
-    return children;
+    return sum; // nocommit is this right?
   }
 
-  static final class DocsAndFreqs {
-    final long cost;
-    final Scorer scorer;
-    int doc = -1;
-   
-    DocsAndFreqs(Scorer scorer) {
-      this.scorer = scorer;
-      this.cost = scorer.cost();
+  @Override
+  public Collection<ChildScorer> getChildren() {
+    ArrayList<ChildScorer> children = new ArrayList<ChildScorer>(scorers.length);
+    for (Scorer scorer : scorersOrdered) {
+      children.add(new ChildScorer(scorer, "MUST"));
     }
+    return children;
   }
 }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java Wed Nov 12 14:56:17 2014
@@ -17,8 +17,9 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
-import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ToStringUtils;
@@ -134,14 +135,14 @@ public class ConstantScoreQuery extends 
     }
 
     @Override
-    public BulkScorer bulkScorer(LeafReaderContext context, boolean scoreDocsInOrder, Bits acceptDocs) throws IOException {
+    public BulkScorer bulkScorer(LeafReaderContext context, boolean scoreDocsInOrder, int flags, Bits acceptDocs) throws IOException {
       final DocIdSetIterator disi;
       if (filter != null) {
         assert query == null;
-        return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
+        return super.bulkScorer(context, scoreDocsInOrder, flags, acceptDocs);
       } else {
         assert query != null && innerWeight != null;
-        BulkScorer bulkScorer = innerWeight.bulkScorer(context, scoreDocsInOrder, acceptDocs);
+        BulkScorer bulkScorer = innerWeight.bulkScorer(context, scoreDocsInOrder, flags, acceptDocs);
         if (bulkScorer == null) {
           return null;
         }
@@ -150,7 +151,7 @@ public class ConstantScoreQuery extends 
     }
 
     @Override
-    public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
+    public Scorer scorer(LeafReaderContext context, int flags, Bits acceptDocs) throws IOException {
       final DocIdSetIterator disi;
       if (filter != null) {
         assert query == null;
@@ -161,7 +162,7 @@ public class ConstantScoreQuery extends 
         disi = dis.iterator();
       } else {
         assert query != null && innerWeight != null;
-        disi = innerWeight.scorer(context, acceptDocs);
+        disi = innerWeight.scorer(context, flags, acceptDocs);
       }
 
       if (disi == null) {
@@ -177,7 +178,7 @@ public class ConstantScoreQuery extends 
 
     @Override
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
-      final Scorer cs = scorer(context, context.reader().getLiveDocs());
+      final Scorer cs = scorer(context, DocsEnum.FLAG_FREQS, context.reader().getLiveDocs());
       final boolean exists = (cs != null && cs.advance(doc) == doc);
 
       final ComplexExplanation result = new ComplexExplanation();
@@ -259,10 +260,15 @@ public class ConstantScoreQuery extends 
     }
 
     @Override
+    public int nextPosition() throws IOException {
+      return -1;
+    }
+
+    @Override
     public int advance(int target) throws IOException {
       return docIdSetIterator.advance(target);
     }
-    
+
     @Override
     public long cost() {
       return docIdSetIterator.cost();

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java Wed Nov 12 14:56:17 2014
@@ -16,6 +16,11 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.util.Bits;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -23,11 +28,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.util.Bits;
-
 /**
  * A query that generates the union of documents produced by its subqueries, and that scores each document with the maximum
  * score for that document as produced by any subquery, plus a tie breaking increment for any additional matching subqueries.
@@ -153,11 +153,11 @@ public class DisjunctionMaxQuery extends
 
     /** Create the scorer used to score our associated DisjunctionMaxQuery */
     @Override
-    public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
+    public Scorer scorer(LeafReaderContext context, int flags, Bits acceptDocs) throws IOException {
       List<Scorer> scorers = new ArrayList<>();
       for (Weight w : weights) {
         // we will advance() subscorers
-        Scorer subScorer = w.scorer(context, acceptDocs);
+        Scorer subScorer = w.scorer(context, flags, acceptDocs);
         if (subScorer != null) {
           scorers.add(subScorer);
         }

Modified: lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java?rev=1638805&r1=1638804&r2=1638805&view=diff
==============================================================================
--- lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java (original)
+++ lucene/dev/lucene2878/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java Wed Nov 12 14:56:17 2014
@@ -46,6 +46,7 @@ final class DisjunctionMaxScorer extends
   DisjunctionMaxScorer(Weight weight, float tieBreakerMultiplier, Scorer[] subScorers) {
     super(weight, subScorers);
     this.tieBreakerMultiplier = tieBreakerMultiplier;
+        
   }
   
   @Override
@@ -66,4 +67,5 @@ final class DisjunctionMaxScorer extends
   protected float getFinal() {
     return scoreMax + (scoreSum - scoreMax) * tieBreakerMultiplier; 
   }
+
 }