mirror of https://github.com/apache/lucene.git
SOLR-8175: fix AIOOBE w/WordBreakSolrSpellChecker
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1717492 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ce0363c0ad
commit
dac0b56589
|
@ -188,6 +188,12 @@ New Features
|
|||
* SOLR-7928: Improve CheckIndex to work against HdfsDirectory
|
||||
(Mike Drob, Gregory Chanan)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
* SOLR-8175: Word Break Spellchecker would throw AIOOBE with certain queries containing
|
||||
"should" clauses. (Ryan Josal via James Dyer)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -199,8 +199,8 @@ public class WordBreakSolrSpellChecker extends SolrSpellChecker {
|
|||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Token[] tokenArr = options.tokens.toArray(new Token[options.tokens.size()]);
|
||||
List<Token> tokenArrWithSeparators = new ArrayList<>(options.tokens.size() + 2);
|
||||
List<Term> termArr = new ArrayList<>(options.tokens.size() + 2);
|
||||
|
||||
List<ResultEntry> breakSuggestionList = new ArrayList<>();
|
||||
List<ResultEntry> noBreakSuggestionList = new ArrayList<>();
|
||||
boolean lastOneProhibited = false;
|
||||
|
@ -219,6 +219,7 @@ public class WordBreakSolrSpellChecker extends SolrSpellChecker {
|
|||
if (i > 0
|
||||
&& (prohibited != lastOneProhibited || required != lastOneRequired || lastOneprocedesNewBooleanOp)) {
|
||||
termArr.add(WordBreakSpellChecker.SEPARATOR_TERM);
|
||||
tokenArrWithSeparators.add(null);
|
||||
}
|
||||
lastOneProhibited = prohibited;
|
||||
lastOneRequired = required;
|
||||
|
@ -226,6 +227,7 @@ public class WordBreakSolrSpellChecker extends SolrSpellChecker {
|
|||
|
||||
Term thisTerm = new Term(field, tokenArr[i].toString());
|
||||
termArr.add(thisTerm);
|
||||
tokenArrWithSeparators.add(tokenArr[i]);
|
||||
if (breakWords) {
|
||||
SuggestWord[][] breakSuggestions = wbsp.suggestWordBreaks(thisTerm,
|
||||
numSuggestions, ir, options.suggestMode, sortMethod);
|
||||
|
@ -269,10 +271,10 @@ public class WordBreakSolrSpellChecker extends SolrSpellChecker {
|
|||
if (i > firstTermIndex) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(tokenArr[i].toString());
|
||||
sb.append(tokenArrWithSeparators.get(i).toString());
|
||||
}
|
||||
Token token = new Token(sb.toString(), tokenArr[firstTermIndex]
|
||||
.startOffset(), tokenArr[lastTermIndex].endOffset());
|
||||
Token token = new Token(sb.toString(), tokenArrWithSeparators.get(firstTermIndex)
|
||||
.startOffset(), tokenArrWithSeparators.get(lastTermIndex).endOffset());
|
||||
combineSuggestionList.add(new ResultEntry(token, cs.suggestion.string,
|
||||
cs.suggestion.freq));
|
||||
}
|
||||
|
|
|
@ -70,6 +70,17 @@ public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {
|
|||
RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
|
||||
QueryConverter qc = new SpellingQueryConverter();
|
||||
qc.setAnalyzer(new MockAnalyzer(random()));
|
||||
|
||||
{
|
||||
//Prior to SOLR-8175, the required term would cause an AIOOBE.
|
||||
Collection<Token> tokens = qc.convert("+pine apple good ness");
|
||||
SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getIndexReader(), 10);
|
||||
SpellingResult result = checker.getSuggestions(spellOpts);
|
||||
searcher.decref();
|
||||
assertTrue(result != null && result.getSuggestions() != null);
|
||||
assertTrue(result.getSuggestions().size()==5);
|
||||
}
|
||||
|
||||
Collection<Token> tokens = qc.convert("paintable pine apple good ness");
|
||||
SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getIndexReader(), 10);
|
||||
SpellingResult result = checker.getSuggestions(spellOpts);
|
||||
|
|
Loading…
Reference in New Issue