SOLR-2491: support spellcheck collation w/ grouping

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1133043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-06-07 15:16:10 +00:00
parent 3d9e264b56
commit 5cc571ad3f
3 changed files with 39 additions and 0 deletions

View File

@ -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
----------------------

View File

@ -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 }));

View File

@ -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<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() == 1);
}
}