From 419f3c0918bd04e683f07fd42cff2af2b8d00843 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..20f349181977 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 = false; 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",false); 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);