diff --git a/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java index e31f4b79343..099a1f26622 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java @@ -49,14 +49,17 @@ import org.apache.lucene.util.FixedBitSet; */ public abstract class PostingsConsumer { - /** Adds a new doc in this term. */ + /** Adds a new doc in this term. + * freq will be -1 when term frequencies are omitted + * for the field. */ public abstract void startDoc(int docID, int freq) throws IOException; /** Add a new position & payload, and start/end offset. A * null payload means no payload; a non-null payload with * zero length also means no payload. Caller may reuse * the {@link BytesRef} for the payload between calls - * (method must fully consume the payload). */ + * (method must fully consume the payload). startOffset + * and endOffset will be -1 when offsets are not indexed. */ public abstract void addPosition(int position, BytesRef payload, int startOffset, int endOffset) throws IOException; /** Called when we are done adding positions & payloads @@ -78,7 +81,7 @@ public abstract class PostingsConsumer { break; } visitedDocs.set(doc); - this.startDoc(doc, 0); + this.startDoc(doc, -1); this.finishDoc(); df++; } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/TermsConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/TermsConsumer.java index 4148430f408..85dc6132b49 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/TermsConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/TermsConsumer.java @@ -57,10 +57,14 @@ public abstract class TermsConsumer { * no docs. */ public abstract PostingsConsumer startTerm(BytesRef text) throws IOException; - /** Finishes the current term; numDocs must be > 0. */ + /** Finishes the current term; numDocs must be > 0. + * stats.totalTermFreq will be -1 when term + * frequencies are omitted for the field. */ public abstract void finishTerm(BytesRef text, TermStats stats) throws IOException; - /** Called when we are done adding terms to this field */ + /** Called when we are done adding terms to this field. + * sumTotalTermFreq will be -1 when term + * frequencies are omitted for the field. */ public abstract void finish(long sumTotalTermFreq, long sumDocFreq, int docCount) throws IOException; /** Return the BytesRef Comparator used to sort terms diff --git a/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java b/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java index 6a5f1f119bf..658ea591791 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java +++ b/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java @@ -430,7 +430,7 @@ final class FreqProxTermsWriterPerField extends TermsHashConsumerPerField implem if (readTermFreq) { termDocFreq = postings.docFreqs[termID]; } else { - termDocFreq = 0; + termDocFreq = -1; } postings.lastDocCodes[termID] = -1; } else { @@ -441,7 +441,7 @@ final class FreqProxTermsWriterPerField extends TermsHashConsumerPerField implem final int code = freq.readVInt(); if (!readTermFreq) { docID += code; - termDocFreq = 0; + termDocFreq = -1; } else { docID += code >>> 1; if ((code & 1) != 0) { @@ -469,7 +469,7 @@ final class FreqProxTermsWriterPerField extends TermsHashConsumerPerField implem // 2nd sweep does the real flush, but I suspect // that'd add too much time to flush. visitedDocs.set(docID); - postingsConsumer.startDoc(docID, termDocFreq); + postingsConsumer.startDoc(docID, writeTermFreq ? termDocFreq : -1); if (docID < delDocLimit) { // Mark it deleted. TODO: we could also skip // writing its postings; this would be diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java b/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java index 8be1027cd0a..fdb9307731c 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java @@ -154,7 +154,7 @@ public class TestCodecs extends LuceneTestCase { for(int i=0;i