Apache Lucene open-source search software
SOLR-4489: fix StringIndexOutOfBoundsException in SpellCheckComponent
James Dyere4cba1525be9
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 9390f52f81f..8353e7acda8 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -69,6 +69,10 @@ Bug Fixes* SOLR-3633 - web UI reports an error if CoreAdminHandler says there are noSolrCores (steffkes)++* SOLR-4489 - SpellCheckComponent can throw StringIndexOutOfBoundsException+ when generating collations involving multiple word-break corrections.+ (James Dyer)Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.javaindex b57552ae6d9..3c3ef7c86ae 100644--- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java+++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java@@ -202,7 +202,7 @@ public class SpellCheckCollator {//then be sure all of the new words have the same optional/required/prohibited status in the query.while(indexOfSpace>-1 && indexOfSpace<corr.length()-1) {addParenthesis = true;- char previousChar = tok.startOffset()>0 ? collation.charAt(tok.startOffset()-1) : ' ';+ char previousChar = tok.startOffset()>0 ? origQuery.charAt(tok.startOffset()-1) : ' ';if(previousChar=='-' || previousChar=='+') {corrSb.insert(indexOfSpace + bump, previousChar);if(requiredOrProhibited==null) {diff --git a/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.javaindex 2caf2a20c58..8d3e7243f9c 100644--- a/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java+++ b/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java@@ -44,6 +44,7 @@ public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {assertNull(h.validateUpdate(adoc("id", "4", "lowerfilt", "printable in pointable paint able")));assertNull(h.validateUpdate(adoc("id", "5", "lowerfilt", "printable in puntable paint able ")));assertNull(h.validateUpdate(adoc("id", "6", "lowerfilt", "paint able in pintable plantable")));+ assertNull(h.validateUpdate(adoc("id", "7", "lowerfilt", "zxcvqwtp fg hj")));assertNull(h.validateUpdate(commit()));//docfreq=7: in//docfreq=5: able@@ -277,6 +278,21 @@ public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true",SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"),"//lst[@name='collation'][1 ]/str[@name='collationQuery']='lowerfilt:((+printable +in +puntable +plantable))'"- );+ );+ assertQ(req(+ "q", "zxcv AND qwtp AND fghj",+ "qt", "spellCheckWithWordbreak",+ "defType", "edismax",+ "qf", "lowerfilt",+ "indent", "true",+ SpellCheckComponent.SPELLCHECK_BUILD, "true",+ SpellCheckComponent.COMPONENT_NAME, "true",+ SpellCheckComponent.SPELLCHECK_ACCURACY, ".75",+ SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true",+ SpellCheckComponent.SPELLCHECK_COLLATE, "true",+ SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true",+ SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "10"),+ "//lst[@name='collation'][1 ]/str[@name='collationQuery']='zxcvqwtp AND (fg AND hj)'"+ );}}