From eabfc42a21c8be4906015bbc6292089f9837f273 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 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);