Apache Lucene open-source search software
SOLR-12284: Stop adding parenthesis to word-break suggestions, unless query uses boolean operators.
jdyer1d92b891f95f3
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 08c7c00707e..ea166fbcb3b 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -193,6 +193,9 @@ Bug Fixes* SOLR-12275: wrong caching for {!filters} as well as for `filters` local param in {!parent} and {!child}(David Smiley, Mikhail Khluldnev)++* SOLR-12284: WordBreakSolrSpellchecker will no longer add parenthesis in collations when breaking words in+ non-boolean queries. (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 859d84fe02a..ad3accfd37e 100644--- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java+++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java@@ -221,8 +221,7 @@ public class SpellCheckCollator {//If the correction contains whitespace (because it involved breaking a word in 2+ words),//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;+ while(indexOfSpace>-1 && indexOfSpace<corr.length()-1) {char previousChar = tok.startOffset()>0 ? origQuery.charAt(tok.startOffset()-1) : ' ';if(previousChar=='-' || previousChar=='+') {corrSb.insert(indexOfSpace + bump, previousChar);@@ -231,6 +230,7 @@ public class SpellCheckCollator {}bump++;} else if ((tok.getFlags() & QueryConverter.TERM_IN_BOOLEAN_QUERY_FLAG) == QueryConverter.TERM_IN_BOOLEAN_QUERY_FLAG) {+ addParenthesis = true;corrSb.insert(indexOfSpace + bump, "AND ");bump += 4;}diff --git a/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.javaindex 258594aa4c8..e96f4995394 100644--- a/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java+++ b/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java@@ -234,13 +234,13 @@ public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {"//lst[@name='collation'][1 ]/str[@name='collationQuery']='lowerfilt:(printable line ample goodness)'","//lst[@name='collation'][2 ]/str[@name='collationQuery']='lowerfilt:(paintablepine ample goodness)'","//lst[@name='collation'][3 ]/str[@name='collationQuery']='lowerfilt:(printable pineapple goodness)'",- "//lst[@name='collation'][4 ]/str[@name='collationQuery']='lowerfilt:((paint able) line ample goodness)'",- "//lst[@name='collation'][5 ]/str[@name='collationQuery']='lowerfilt:(printable (pi ne) ample goodness)'",- "//lst[@name='collation'][6 ]/str[@name='collationQuery']='lowerfilt:((paint able) pineapple goodness)'",- "//lst[@name='collation'][7 ]/str[@name='collationQuery']='lowerfilt:((paint able) (pi ne) ample goodness)'",+ "//lst[@name='collation'][4 ]/str[@name='collationQuery']='lowerfilt:(paint able line ample goodness)'",+ "//lst[@name='collation'][5 ]/str[@name='collationQuery']='lowerfilt:(printable pi ne ample goodness)'",+ "//lst[@name='collation'][6 ]/str[@name='collationQuery']='lowerfilt:(paint able pineapple goodness)'",+ "//lst[@name='collation'][7 ]/str[@name='collationQuery']='lowerfilt:(paint able pi ne ample goodness)'","//lst[@name='collation'][8 ]/str[@name='collationQuery']='lowerfilt:(pintable line ample goodness)'","//lst[@name='collation'][9 ]/str[@name='collationQuery']='lowerfilt:(pintable pineapple goodness)'",- "//lst[@name='collation'][10]/str[@name='collationQuery']='lowerfilt:(pintable (pi ne) ample goodness)'",+ "//lst[@name='collation'][10]/str[@name='collationQuery']='lowerfilt:(pintable pi ne ample goodness)'","//lst[@name='collation'][10]/lst[@name='misspellingsAndCorrections']/str[@name='paintable']='pintable'","//lst[@name='collation'][10]/lst[@name='misspellingsAndCorrections']/str[@name='pine']='pi ne'","//lst[@name='collation'][10]/lst[@name='misspellingsAndCorrections']/str[@name='apple']='ample'",@@ -297,7 +297,7 @@ public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true",SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "10"),"//lst[@name='collation'][1 ]/str[@name='collationQuery']='lowerfilt:(+line -ample)'",- "//lst[@name='collation'][2 ]/str[@name='collationQuery']='lowerfilt:((+pi +ne) -ample)'"+ "//lst[@name='collation'][2 ]/str[@name='collationQuery']='lowerfilt:(+pi +ne -ample)'");assertQ(req("q", "lowerfilt:(+printableinpuntableplantable)",@@ -309,7 +309,7 @@ public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {SpellCheckComponent.SPELLCHECK_COLLATE, "true",SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true",SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"),- "//lst[@name='collation'][1 ]/str[@name='collationQuery']='lowerfilt:((+printable +in +puntable +plantable))'"+ "//lst[@name='collation'][1 ]/str[@name='collationQuery']='lowerfilt:(+printable +in +puntable +plantable)'");assertQ(req("q", "zxcv AND qwtp AND fghj",