mirror of https://github.com/apache/lucene.git
SOLR-5090: SpellCheckComponent sometimes throws NPE when "spellcheck.alternativeTermCount" is set to zero
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1592591 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3c14dc6a57
commit
14d72257a6
|
@ -134,6 +134,9 @@ Bug Fixes
|
|||
|
||||
* SOLR-6023: FieldAnalysisRequestHandler throws NPE if no parameters are supplied.
|
||||
(shalin)
|
||||
|
||||
* SOLR-5090: SpellCheckComponent sometimes throws NPE if
|
||||
"spellcheck.alternativeTermCount" is set to zero (James Dyer).
|
||||
|
||||
Other Changes
|
||||
---------------------
|
||||
|
|
|
@ -158,7 +158,7 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
|
|||
boolean extendedResults = params.getBool(SPELLCHECK_EXTENDED_RESULTS, false);
|
||||
boolean collate = params.getBool(SPELLCHECK_COLLATE, false);
|
||||
float accuracy = params.getFloat(SPELLCHECK_ACCURACY, Float.MIN_VALUE);
|
||||
Integer alternativeTermCount = params.getInt(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT);
|
||||
int alternativeTermCount = params.getInt(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT, 0);
|
||||
Integer maxResultsForSuggest = params.getInt(SpellingParams.SPELLCHECK_MAX_RESULTS_FOR_SUGGEST);
|
||||
ModifiableSolrParams customParams = new ModifiableSolrParams();
|
||||
for (String checkerName : getDictionaryNames(params)) {
|
||||
|
@ -177,7 +177,7 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
|
|||
SuggestMode suggestMode = SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX;
|
||||
if (onlyMorePopular) {
|
||||
suggestMode = SuggestMode.SUGGEST_MORE_POPULAR;
|
||||
} else if (alternativeTermCount != null) {
|
||||
} else if (alternativeTermCount > 0) {
|
||||
suggestMode = SuggestMode.SUGGEST_ALWAYS;
|
||||
}
|
||||
|
||||
|
|
|
@ -156,17 +156,17 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
|
|||
docFreq = reader.docFreq(term);
|
||||
}
|
||||
String[] suggestions = spellChecker.suggestSimilar(tokenText,
|
||||
((options.alternativeTermCount == null || docFreq == 0) ? count
|
||||
((options.alternativeTermCount == 0 || docFreq == 0) ? count
|
||||
: options.alternativeTermCount), field != null ? reader : null, // workaround LUCENE-1295
|
||||
field, options.suggestMode, theAccuracy);
|
||||
if (suggestions.length == 1 && suggestions[0].equals(tokenText)
|
||||
&& options.alternativeTermCount == null) {
|
||||
&& options.alternativeTermCount == 0) {
|
||||
// These are spelled the same, continue on
|
||||
continue;
|
||||
}
|
||||
// If considering alternatives to "correctly-spelled" terms, then add the
|
||||
// original as a viable suggestion.
|
||||
if (options.alternativeTermCount != null && docFreq > 0) {
|
||||
if (options.alternativeTermCount > 0 && docFreq > 0) {
|
||||
boolean foundOriginal = false;
|
||||
String[] suggestionsWithOrig = new String[suggestions.length + 1];
|
||||
for (int i = 0; i < suggestions.length; i++) {
|
||||
|
|
|
@ -185,13 +185,13 @@ public class DirectSolrSpellChecker extends SolrSpellChecker {
|
|||
String tokenText = token.toString();
|
||||
Term term = new Term(field, tokenText);
|
||||
int freq = options.reader.docFreq(term);
|
||||
int count = (options.alternativeTermCount != null && freq > 0) ? options.alternativeTermCount: options.count;
|
||||
int count = (options.alternativeTermCount > 0 && freq > 0) ? options.alternativeTermCount: options.count;
|
||||
SuggestWord[] suggestions = checker.suggestSimilar(term, count,options.reader, options.suggestMode, accuracy);
|
||||
result.addFrequency(token, freq);
|
||||
|
||||
// If considering alternatives to "correctly-spelled" terms, then add the
|
||||
// original as a viable suggestion.
|
||||
if (options.alternativeTermCount != null && freq > 0) {
|
||||
if (options.alternativeTermCount > 0 && freq > 0) {
|
||||
boolean foundOriginal = false;
|
||||
SuggestWord[] suggestionsWithOrig = new SuggestWord[suggestions.length + 1];
|
||||
for (int i = 0; i < suggestions.length; i++) {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class SpellingOptions {
|
|||
*/
|
||||
public int count = 1;
|
||||
|
||||
public Integer alternativeTermCount = null;
|
||||
public int alternativeTermCount = 0;
|
||||
|
||||
public SuggestMode suggestMode = SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX;
|
||||
/**
|
||||
|
@ -95,7 +95,7 @@ public class SpellingOptions {
|
|||
}
|
||||
|
||||
public SpellingOptions(Collection<Token> tokens, IndexReader reader,
|
||||
int count, Integer alternativeTermCount, SuggestMode suggestMode,
|
||||
int count, int alternativeTermCount, SuggestMode suggestMode,
|
||||
boolean extendedResults, float accuracy, SolrParams customParams) {
|
||||
this.tokens = tokens;
|
||||
this.reader = reader;
|
||||
|
|
|
@ -463,6 +463,14 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
|
|||
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='collation']/int[@name='hits']=1",
|
||||
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='collation']/lst[@name='misspellingsAndCorrections']/str[@name='june']='jane'"
|
||||
);
|
||||
//SOLR-5090, alternativeTermCount==0 was being evaluated, sometimes would throw NPE
|
||||
assertQ(req("q", "teststop:(june customs)", "mm", "2", "qt",
|
||||
"spellCheckCompRH", "indent", "true",
|
||||
SpellCheckComponent.COMPONENT_NAME, "true",
|
||||
SpellCheckComponent.SPELLCHECK_DICT, dictionary[i],
|
||||
SpellCheckComponent.SPELLCHECK_COUNT, "10",
|
||||
SpellCheckComponent.SPELLCHECK_ALTERNATIVE_TERM_COUNT, "0",
|
||||
SpellCheckComponent.SPELLCHECK_COLLATE, "true"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue