XMoreLikeThis: fix potentially unpositioned enum

This commit is contained in:
Alex Ksikes 2015-07-06 18:03:47 +02:00
parent 1f04d6c2bb
commit afe9c52f07
1 changed files with 7 additions and 7 deletions

View File

@ -39,10 +39,7 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.index.*; import org.apache.lucene.index.*;
import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.*;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.similarities.DefaultSimilarity; import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.search.similarities.TFIDFSimilarity; import org.apache.lucene.search.similarities.TFIDFSimilarity;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
@ -855,8 +852,11 @@ public final class XMoreLikeThis {
continue; continue;
} }
PostingsEnum docs = termsEnum.postings(null, null); final PostingsEnum docs = termsEnum.postings(null, null);
final int freq = docs.freq(); int freq = 0;
while(docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
freq += docs.freq();
}
// increment frequency // increment frequency
Int cnt = termFreqMap.get(term); Int cnt = termFreqMap.get(term);