LUCENE-7950 - fixed potential NPE when no docs have the class field

This commit is contained in:
Tommaso Teofili 2017-09-02 14:43:59 +02:00
parent cd471cc98d
commit c2c2e8a85e
1 changed files with 16 additions and 14 deletions

View File

@ -113,6 +113,7 @@ public class SimpleNaiveBayesDocumentClassifier extends SimpleNaiveBayesClassifi
Map<String, List<String[]>> fieldName2tokensArray = new LinkedHashMap<>(); Map<String, List<String[]>> fieldName2tokensArray = new LinkedHashMap<>();
Map<String, Float> fieldName2boost = new LinkedHashMap<>(); Map<String, Float> fieldName2boost = new LinkedHashMap<>();
Terms classes = MultiFields.getTerms(indexReader, classFieldName); Terms classes = MultiFields.getTerms(indexReader, classFieldName);
if (classes != null) {
TermsEnum classesEnum = classes.iterator(); TermsEnum classesEnum = classes.iterator();
BytesRef c; BytesRef c;
@ -132,6 +133,7 @@ public class SimpleNaiveBayesDocumentClassifier extends SimpleNaiveBayesClassifi
} }
assignedClasses.add(new ClassificationResult<>(term.bytes(), classScore)); assignedClasses.add(new ClassificationResult<>(term.bytes(), classScore));
} }
}
return normClassificationResults(assignedClasses); return normClassificationResults(assignedClasses);
} }