diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java index 3394de1c91da..7ae0304c7bd0 100644 --- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java +++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java @@ -50,6 +50,7 @@ public class SpellCheckCollator { private int maxCollationEvaluations = 10000; private boolean suggestionsMayOverlap = false; private int docCollectionLimit = 0; + private boolean addParenthesis = true; public List collate(SpellingResult result, String originalQuery, ResponseBuilder ultimateResponse) { @@ -94,6 +95,8 @@ public List collate(SpellingResult result, PossibilityIterator.RankedSpellPossibility possibility = possibilityIter.next(); String collationQueryStr = getCollation(originalQuery, possibility.corrections); int hits = 0; + // Multi-term token suggestions need to be treated as same position or not + addParenthesis = ultimateResponse.req.getParams().getBool("spellcheck.samePositionTokens",true); if (verifyCandidateWithQuery) { tryNo++; @@ -201,7 +204,6 @@ private String getCollation(String origQuery, if (tok.getPositionIncrement() == 0) continue; corr = correction.getCorrection(); - boolean addParenthesis = false; Character requiredOrProhibited = null; int indexOfSpace = corr.indexOf(' '); StringBuilder corrSb = new StringBuilder(corr); @@ -210,7 +212,6 @@ private String getCollation(String origQuery, //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 && indexOfSpace0 ? origQuery.charAt(tok.startOffset()-1) : ' '; if(previousChar=='-' || previousChar=='+') { corrSb.insert(indexOfSpace + bump, previousChar);