From 4b607b50d65b515954c1c45d2285f38fbd3a38b2 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 859d84fe02a0..1f1736353174 100644 --- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java +++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java @@ -49,6 +49,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) { @@ -93,6 +94,8 @@ public List collate(SpellingResult result, PossibilityIterator.RankedSpellPossibility possibility = possibilityIter.next(); String collationQueryStr = getCollation(originalQuery, possibility.corrections); long 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++; @@ -213,7 +216,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); @@ -222,7 +224,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);