You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2014/08/09 22:07:00 UTC
svn commit: r1617010 - in /lucene/dev/trunk/lucene/classification/src:
java/org/apache/lucene/classification/utils/DocToDoubleVectorUtils.java
test/org/apache/lucene/classification/utils/DocToDoubleVectorUtilsTest.java
Author: tommaso
Date: Sat Aug 9 20:07:00 2014
New Revision: 1617010
URL: http://svn.apache.org/r1617010
Log:
LUCENE-5880 - avoid NegativeArraySizeException in DocToDoubleVectorUtils
Modified:
lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/utils/DocToDoubleVectorUtils.java
lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/utils/DocToDoubleVectorUtilsTest.java
Modified: lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/utils/DocToDoubleVectorUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/utils/DocToDoubleVectorUtils.java?rev=1617010&r1=1617009&r2=1617010&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/utils/DocToDoubleVectorUtils.java (original)
+++ lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/utils/DocToDoubleVectorUtils.java Sat Aug 9 20:07:00 2014
@@ -41,7 +41,7 @@ public class DocToDoubleVectorUtils {
public static Double[] toSparseLocalFreqDoubleArray(Terms docTerms, Terms fieldTerms) throws IOException {
TermsEnum fieldTermsEnum = fieldTerms.iterator(null);
Double[] freqVector = null;
- if (docTerms != null) {
+ if (docTerms != null && fieldTerms.size() > -1) {
freqVector = new Double[(int) fieldTerms.size()];
int i = 0;
TermsEnum docTermsEnum = docTerms.iterator(null);
Modified: lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/utils/DocToDoubleVectorUtilsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/utils/DocToDoubleVectorUtilsTest.java?rev=1617010&r1=1617009&r2=1617010&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/utils/DocToDoubleVectorUtilsTest.java (original)
+++ lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/utils/DocToDoubleVectorUtilsTest.java Sat Aug 9 20:07:00 2014
@@ -94,12 +94,14 @@ public class DocToDoubleVectorUtilsTest
@Test
public void testSparseFreqDoubleArrayConversion() throws Exception {
Terms fieldTerms = MultiFields.getTerms(index, "text");
- IndexSearcher indexSearcher = new IndexSearcher(index);
- for (ScoreDoc scoreDoc : indexSearcher.search(new MatchAllDocsQuery(), Integer.MAX_VALUE).scoreDocs) {
- Terms docTerms = index.getTermVector(scoreDoc.doc, "text");
- Double[] vector = DocToDoubleVectorUtils.toSparseLocalFreqDoubleArray(docTerms, fieldTerms);
- assertNotNull(vector);
- assertTrue(vector.length > 0);
+ if (fieldTerms != null && fieldTerms.size() != -1) {
+ IndexSearcher indexSearcher = new IndexSearcher(index);
+ for (ScoreDoc scoreDoc : indexSearcher.search(new MatchAllDocsQuery(), Integer.MAX_VALUE).scoreDocs) {
+ Terms docTerms = index.getTermVector(scoreDoc.doc, "text");
+ Double[] vector = DocToDoubleVectorUtils.toSparseLocalFreqDoubleArray(docTerms, fieldTerms);
+ assertNotNull(vector);
+ assertTrue(vector.length > 0);
+ }
}
}
}