mirror of https://github.com/apache/lucene.git
SOLR-3211: Allow parameter overrides when testing spellcheck collations
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1348936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
28f43e3b56
commit
b232abb645
|
@ -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
|
||||
----------------------
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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'"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollateWithFilter() throws Exception
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue