Skip to content

Commit

Permalink
Use dummy TermStatistics when term is not found Closes elastic#10660
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/org/elasticsearch/action/termvector/TermVectorWriter.java
  • Loading branch information
s1monw committed Apr 20, 2015
1 parent 9d5662c commit 6213a21
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.elasticsearch.action.termvector;

import org.apache.lucene.index.*;
import org.apache.lucene.search.TermStatistics;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.action.termvector.TermVectorRequest.Flag;
import org.elasticsearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -81,7 +82,11 @@ void setFields(Fields termVectorsByField, Set<String> selectedFields, EnumSet<Fl
boolean foundTerm = topLevelIterator.seekExact(term);
startTerm(term);
if (flags.contains(Flag.TermStatistics)) {
writeTermStatistics(topLevelIterator);
if (foundTerm) {
writeTermStatistics(topLevelIterator);
} else {
writeEmptyTermStatistics();
}
}
if (useDocsAndPos) {
// given we have pos or offsets
Expand Down Expand Up @@ -208,6 +213,12 @@ private void writeTermStatistics(TermsEnum topLevelIterator) throws IOException

}

private void writeEmptyTermStatistics() throws IOException {
writePotentiallyNegativeVInt(0);
writePotentiallyNegativeVLong(0);

}

private void writeFieldStatistics(Terms topLevelTerms) throws IOException {
long sttf = topLevelTerms.getSumTotalTermFreq();
assert (sttf >= -1);
Expand Down

0 comments on commit 6213a21

Please sign in to comment.