mirror of https://github.com/apache/lucene.git
LUCENE-3407: wrong stats from MemoryCodec when freqs are omitted
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1163213 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aefe15aad9
commit
7c92a0d48d
|
@ -554,7 +554,7 @@ public class MemoryCodec extends Codec {
|
|||
if (field.indexOptions != IndexOptions.DOCS_ONLY) {
|
||||
totalTermFreq = docFreq + buffer.readVLong();
|
||||
} else {
|
||||
totalTermFreq = 0;
|
||||
totalTermFreq = -1;
|
||||
}
|
||||
current.output.offset = buffer.getPosition();
|
||||
if (VERBOSE) System.out.println(" df=" + docFreq + " totTF=" + totalTermFreq + " offset=" + buffer.getPosition() + " len=" + current.output.length);
|
||||
|
@ -692,7 +692,7 @@ public class MemoryCodec extends Codec {
|
|||
if (field.indexOptions != IndexOptions.DOCS_ONLY) {
|
||||
sumTotalTermFreq = in.readVLong();
|
||||
} else {
|
||||
sumTotalTermFreq = 0;
|
||||
sumTotalTermFreq = -1;
|
||||
}
|
||||
sumDocFreq = in.readVLong();
|
||||
|
||||
|
|
|
@ -428,4 +428,25 @@ public class TestOmitTf extends LuceneTestCase {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** test that when freqs are omitted, that totalTermFreq and sumTotalTermFreq are -1 */
|
||||
public void testStats() throws Exception {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter iw = new RandomIndexWriter(random, dir,
|
||||
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||
Document doc = new Document();
|
||||
FieldType ft = new FieldType(TextField.TYPE_UNSTORED);
|
||||
ft.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
ft.freeze();
|
||||
Field f = newField("foo", "bar", ft);
|
||||
doc.add(f);
|
||||
iw.addDocument(doc);
|
||||
IndexReader ir = iw.getReader();
|
||||
iw.close();
|
||||
Terms terms = MultiFields.getTerms(ir, "foo");
|
||||
assertEquals(-1, terms.totalTermFreq(new BytesRef("bar")));
|
||||
assertEquals(-1, terms.getSumTotalTermFreq());
|
||||
ir.close();
|
||||
dir.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue