Apache Lucene open-source search software
SOLR-3211: Allow parameter overrides when testing spellcheck collations
James Dyerb232abb6459f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a9dfddd0b79..3c3079c420d 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -351,6 +351,11 @@ New Features{"delete":{"id":"myid", "_version_":123456789}}(yonik)+* SOLR-3211: Allow parameter overrides in conjunction with "spellcheck.maxCollationTries".+ To do so, use parameters starting with "spellcheck.collateParam." For instance, to+ override the "mm" parameter, specify "spellcheck.collateParam.mm". This is helpful+ in cases where testing spellcheck collations for result counts should use different+ parameters from the main query (James Dyer)Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.javaindex 6c05b04dec3..7e106437345 100644--- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java+++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java@@ -18,12 +18,15 @@ package org.apache.solr.spelling;import java.util.ArrayList;import java.util.Arrays;+import java.util.Iterator;import java.util.List;import org.apache.lucene.analysis.Token;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.GroupParams;import org.apache.solr.common.params.ModifiableSolrParams;+import org.apache.solr.common.params.SolrParams;+import org.apache.solr.common.params.SpellingParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.handler.component.QueryComponent;import org.apache.solr.handler.component.ResponseBuilder;@@ -74,8 +77,23 @@ public class SpellCheckCollator {if (verifyCandidateWithQuery) {tryNo++;-- ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams());+ SolrParams origParams = ultimateResponse.req.getParams();+ ModifiableSolrParams params = new ModifiableSolrParams(origParams);+ Iterator<String> origParamIterator = origParams.getParameterNamesIterator();+ int pl = SpellingParams.SPELLCHECK_COLLATE_PARAM_OVERRIDE.length();+ while (origParamIterator.hasNext()) {+ String origParamName = origParamIterator.next();+ if (origParamName+ .startsWith(SpellingParams.SPELLCHECK_COLLATE_PARAM_OVERRIDE)+ && origParamName.length() > pl) {+ String[] val = origParams.getParams(origParamName);+ if (val.length == 1 && val[0].length() == 0) {+ params.set(origParamName.substring(pl), (String[]) null);+ } else {+ params.set(origParamName.substring(pl), val);+ }+ }+ }params.set(CommonParams.Q, collationQueryStr);params.remove(CommonParams.START);params.set(CommonParams.FL, "id");diff --git a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.javaindex 08f2985cc8c..86db57d588d 100644--- a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java+++ b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java@@ -54,6 +54,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {assertNull(h.validateUpdate(adoc("id", "10", "teststop", "Once in Paris Dick built a fire on the hearth")));assertNull(h.validateUpdate(adoc("id", "11", "teststop", "Dick waited for Jane as he watched the sparks flow upward")));assertNull(h.validateUpdate(adoc("id", "12", "teststop", "This June parisian rendez-vous is ruined because of a customs snafu")));+ assertNull(h.validateUpdate(adoc("id", "13", "teststop", "partisan political machine")));assertNull(h.validateUpdate(commit()));}@@ -108,6 +109,44 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {}}++ public void testCollateWithOverride() throws Exception+ {+ assertQ(+ req(+ SpellCheckComponent.COMPONENT_NAME, "true",+ SpellCheckComponent.SPELLCHECK_DICT, "direct",+ SpellingParams.SPELLCHECK_COUNT, "10",+ SpellingParams.SPELLCHECK_COLLATE, "true",+ SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10",+ SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10",+ "qt", "spellCheckCompRH",+ "defType", "edismax",+ "qf", "teststop",+ "mm", "1",+ CommonParams.Q, "partisian politcal mashine"+ ),+ "//lst[@name='spellcheck']/lst[@name='suggestions']/str[@name='collation']='parisian political machine'"+ );+ assertQ(+ req(+ SpellCheckComponent.COMPONENT_NAME, "true",+ SpellCheckComponent.SPELLCHECK_DICT, "direct",+ SpellingParams.SPELLCHECK_COUNT, "10",+ SpellingParams.SPELLCHECK_COLLATE, "true",+ SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10",+ SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10",+ "qt", "spellCheckCompRH",+ "defType", "edismax",+ "qf", "teststop",+ "mm", "1",+ SpellingParams.SPELLCHECK_COLLATE_PARAM_OVERRIDE + "mm", "100%",+ CommonParams.Q, "partisian politcal mashine"+ ),+ "//lst[@name='spellcheck']/lst[@name='suggestions']/str[@name='collation']='partisan political machine'"+ );++ }@Testpublic void testCollateWithFilter() throws Exceptiondiff --git a/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java b/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.javaindex 3a4284c8158..06c51d3c664 100644--- a/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java+++ b/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java@@ -138,7 +138,15 @@ public interface SpellingParams {* </p>*/public static final String SPELLCHECK_COLLATE_EXTENDED_RESULTS = SPELLCHECK_PREFIX + "collateExtendedResults";-++ /**+ * <p>+ * For use with {@link SpellingParams#SPELLCHECK_MAX_COLLATION_TRIES}, use this to override any original query parameters+ * when issuing test queries. For instance, if the original query has "mm=1" but it is preferred to test collations+ * with "mm=100%", then use "spellcheck.collateParam.mm=100%".+ * </p>+ */+ public static final String SPELLCHECK_COLLATE_PARAM_OVERRIDE = SPELLCHECK_PREFIX + "collateParam.";/*** Certain spelling implementations may allow for an accuracy setting.*/