SOLR-7304: SpellingQueryConverter to ignore "TO" as a possible range query operator

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1718415 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2015-12-07 15:55:40 +00:00
parent f893548be5
commit 933a753aca
3 changed files with 42 additions and 3 deletions

View File

@ -207,8 +207,10 @@ Bug Fixes
* SOLR-8366: ConcurrentUpdateSolrClient attempts to use response's content type as charset encoding
for parsing exception. (shalin)
* SOLR-6271: fix ConjunctionSolrSpellChecker to not compare StringDistance by instance.
* SOLR-6271: Fix ConjunctionSolrSpellChecker to not compare StringDistance by instance.
(Igor Kostromin via James Dyer)
* SOLR-7304: Fix Spellcheck Collate to not invalidate range queries. (James Dyer)
Other Changes
----------------------

View File

@ -104,6 +104,8 @@ public class SpellingQueryConverter extends QueryConverter {
if (original == null) { // this can happen with q.alt = and no query
return Collections.emptyList();
}
boolean mightContainRangeQuery = (original.indexOf('[') != -1 || original.indexOf('{') != -1)
&& (original.indexOf(']') != -1 || original.indexOf('}') != -1);
Collection<Token> result = new ArrayList<>();
Matcher matcher = QUERY_REGEX.matcher(original);
String nextWord = null;
@ -123,7 +125,10 @@ public class SpellingQueryConverter extends QueryConverter {
if(matcher.find()) {
nextWord = matcher.group(0);
nextStartIndex = matcher.start();
}
}
if(mightContainRangeQuery && "TO".equals(word)) {
continue;
}
if("AND".equals(word) || "OR".equals(word) || "NOT".equals(word)) {
lastBooleanOp = word;
continue;

View File

@ -48,7 +48,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
public static void beforeClass() throws Exception {
initCore("solrconfig-spellcheckcomponent.xml", "schema.xml");
assertU(adoc("id", "0",
"lowerfilt", "faith hope and love",
"lowerfilt", "faith hope and love to",
"teststop", "metanoia"));
assertU(adoc("id", "1",
"lowerfilt", "faith hope and loaves",
@ -94,6 +94,38 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
"teststop", "metanoia"));
assertU(commit());
}
@Test
public void testCollationWithRangeQuery() throws Exception
{
SolrCore core = h.getCore();
SearchComponent speller = core.getSearchComponent("spellcheck");
assertTrue("speller is null and it shouldn't be", speller != null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
params.add(SpellingParams.SPELLCHECK_BUILD, "true");
params.add(SpellingParams.SPELLCHECK_COUNT, "10");
params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
params.add(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT, "10");
params.add(CommonParams.Q, "id:[1 TO 10] AND lowerfilt:lovw");
{
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
NamedList collationHolder = (NamedList) spellCheck.get("collations");
List<String> collations = collationHolder.getAll("collation");
assertTrue(collations.size()==1);
String collation = collations.iterator().next();
System.out.println(collation);
assertTrue("Incorrect collation: " + collation,"id:[1 TO 10] AND lowerfilt:love".equals(collation));
}
}
@Test
public void testCollationWithHypens() throws Exception