diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 8833db90edd..b5a8d9f2c7c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -148,6 +148,9 @@ New Features new functions exists(), if(), and(), or(), xor(), not(), def(), and true and false constants. (yonik) +* SOLR-2491: Add support for using spellcheck collation in conjunction + with grouping. Note that the number of hits returned for collations + is the number of ungrouped hits. (James Dyer via rmuir) Optimizations ---------------------- diff --git a/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java index 5ed1ab3e4c0..92705b232d1 100644 --- a/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java +++ b/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java @@ -22,6 +22,7 @@ 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.util.NamedList; import org.apache.solr.handler.component.QueryComponent; @@ -77,6 +78,7 @@ public class SpellCheckCollator { params.remove(CommonParams.START); params.set(CommonParams.FL, "id"); params.set(CommonParams.ROWS, "0"); + params.remove(GroupParams.GROUP); // creating a request here... make sure to close it! ResponseBuilder checkResponse = new ResponseBuilder(new LocalSolrQueryRequest(ultimateResponse.req.getCore(), params),new SolrQueryResponse(), Arrays.asList(new SearchComponent[] { queryComponent })); diff --git a/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java b/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java index c819c9f8a8a..e4a43342110 100644 --- a/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java +++ b/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.apache.solr.SolrTestCaseJ4; 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.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; @@ -236,4 +237,37 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 { assertTrue(correctionForLoane.equals("love") || correctionForLoane.equals("loaves")); } } + + @Test + public void testCollateWithGrouping() 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(SpellCheckComponent.SPELLCHECK_BUILD, "true"); + params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); + params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); + params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "5"); + params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"); + params.add(CommonParams.Q, "lowerfilt:(+fauth)"); + params.add(GroupParams.GROUP, "true"); + params.add(GroupParams.GROUP_FIELD, "id"); + + //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would + //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1. + 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 suggestions = (NamedList) spellCheck.get("suggestions"); + List collations = suggestions.getAll("collation"); + assertTrue(collations.size() == 1); + } }