mirror of https://github.com/apache/lucene.git
LUCENE-7950 - fixed potential NPE when no docs have the class field
This commit is contained in:
parent
cd471cc98d
commit
c2c2e8a85e
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue