mirror of https://github.com/apache/lucene.git
LUCENE-5880 - avoid NegativeArraySizeException in DocToDoubleVectorUtils
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1617010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
872bd9145c
commit
1b5afe0f26
|
@ -41,7 +41,7 @@ public class DocToDoubleVectorUtils {
|
||||||
public static Double[] toSparseLocalFreqDoubleArray(Terms docTerms, Terms fieldTerms) throws IOException {
|
public static Double[] toSparseLocalFreqDoubleArray(Terms docTerms, Terms fieldTerms) throws IOException {
|
||||||
TermsEnum fieldTermsEnum = fieldTerms.iterator(null);
|
TermsEnum fieldTermsEnum = fieldTerms.iterator(null);
|
||||||
Double[] freqVector = null;
|
Double[] freqVector = null;
|
||||||
if (docTerms != null) {
|
if (docTerms != null && fieldTerms.size() > -1) {
|
||||||
freqVector = new Double[(int) fieldTerms.size()];
|
freqVector = new Double[(int) fieldTerms.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
TermsEnum docTermsEnum = docTerms.iterator(null);
|
TermsEnum docTermsEnum = docTerms.iterator(null);
|
||||||
|
|
|
@ -94,12 +94,14 @@ public class DocToDoubleVectorUtilsTest extends LuceneTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testSparseFreqDoubleArrayConversion() throws Exception {
|
public void testSparseFreqDoubleArrayConversion() throws Exception {
|
||||||
Terms fieldTerms = MultiFields.getTerms(index, "text");
|
Terms fieldTerms = MultiFields.getTerms(index, "text");
|
||||||
IndexSearcher indexSearcher = new IndexSearcher(index);
|
if (fieldTerms != null && fieldTerms.size() != -1) {
|
||||||
for (ScoreDoc scoreDoc : indexSearcher.search(new MatchAllDocsQuery(), Integer.MAX_VALUE).scoreDocs) {
|
IndexSearcher indexSearcher = new IndexSearcher(index);
|
||||||
Terms docTerms = index.getTermVector(scoreDoc.doc, "text");
|
for (ScoreDoc scoreDoc : indexSearcher.search(new MatchAllDocsQuery(), Integer.MAX_VALUE).scoreDocs) {
|
||||||
Double[] vector = DocToDoubleVectorUtils.toSparseLocalFreqDoubleArray(docTerms, fieldTerms);
|
Terms docTerms = index.getTermVector(scoreDoc.doc, "text");
|
||||||
assertNotNull(vector);
|
Double[] vector = DocToDoubleVectorUtils.toSparseLocalFreqDoubleArray(docTerms, fieldTerms);
|
||||||
assertTrue(vector.length > 0);
|
assertNotNull(vector);
|
||||||
|
assertTrue(vector.length > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue