From 004a2b2ca1bd9a4bdc0b53b849f4bc9b461e7b1e Mon Sep 17 00:00:00 2001 From: abhidemon Date: Thu, 9 Mar 2017 19:16:14 +0530 Subject: [PATCH] fix(spellCheckCollator): Configurable parentheses around spell-suggs Parentheses around spell suggestions which have whitespace between them means all the tokens inside the braces are at the same position (the way Edismax parser parses it). This needs to be made configurable because braces around tokens can be unwanted in some cases, (eg. Where we use WordBreakSolrSpellChecker and all the tokens need to be present in the matching docs) --- .../java/org/apache/solr/spelling/SpellCheckCollator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 0738081aba6d..89fd23993237 100644 --- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java +++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java @@ -48,6 +48,7 @@ public class SpellCheckCollator { private int maxCollationEvaluations = 10000; private boolean suggestionsMayOverlap = false; private int docCollectionLimit = 0; + private boolean addParenthesis = false; public List collate(SpellingResult result, String originalQuery, ResponseBuilder ultimateResponse) { @@ -92,6 +93,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",false); if (verifyCandidateWithQuery) { tryNo++; @@ -199,7 +202,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); @@ -208,7 +210,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);