Search in sources :

Example 1 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class ClusteringComponentTest method testComponent.

@Test
public void testComponent() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent sc = core.getSearchComponent("clustering");
    assertTrue("sc is null and it shouldn't be", sc != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(ClusteringComponent.COMPONENT_NAME, "true");
    params.add(CommonParams.Q, "*:*");
    params.add(ClusteringParams.USE_SEARCH_RESULTS, "true");
    SolrRequestHandler handler = core.getRequestHandler("standard");
    SolrQueryResponse rsp;
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap<>());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    NamedList<?> values = rsp.getValues();
    Object clusters = values.get("clusters");
    //System.out.println("Clusters: " + clusters);
    assertTrue("clusters is null and it shouldn't be", clusters != null);
    req.close();
    params = new ModifiableSolrParams();
    params.add(ClusteringComponent.COMPONENT_NAME, "true");
    params.add(ClusteringParams.ENGINE_NAME, "mock");
    params.add(ClusteringParams.USE_COLLECTION, "true");
    params.add(QueryComponent.COMPONENT_NAME, "false");
    handler = core.getRequestHandler("docClustering");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap<>());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    values = rsp.getValues();
    clusters = values.get("clusters");
    //System.out.println("Clusters: " + clusters);
    assertTrue("clusters is null and it shouldn't be", clusters != null);
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SearchComponent(org.apache.solr.handler.component.SearchComponent) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 2 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollateWithMultipleRequestHandlers.

@Test
public void testCollateWithMultipleRequestHandlers() 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_DICT, "multipleFields");
    params.add(SpellingParams.SPELLCHECK_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "1");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
    params.add(CommonParams.Q, "peac");
    //SpellCheckCompRH has no "qf" defined.  It will not find "peace" from "peac" despite it being in the dictionary
    //because requrying against this Request Handler results in 0 hits.
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(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");
    String singleCollation = (String) collationHolder.get("collation");
    assertNull(singleCollation);
    //SpellCheckCompRH1 has "lowerfilt1" defined in the "qf" param.  It will find "peace" from "peac" because
    //requrying field "lowerfilt1" returns the hit.
    params.remove(SpellingParams.SPELLCHECK_BUILD);
    handler = core.getRequestHandler("spellCheckCompRH1");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    singleCollation = (String) collationHolder.get("collation");
    assertEquals(singleCollation, "peace");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 3 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testExtendedCollate.

@Test
public void testExtendedCollate() 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(CommonParams.QT, "spellCheckCompRH");
    params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)");
    params.add(SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true");
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellingParams.SPELLCHECK_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    // Testing backwards-compatible behavior.
    // Returns 1 collation as a single string.
    // All words are "correct" per the dictionary, but this collation would
    // return no results if tried.
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(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");
    String singleCollation = (String) collationHolder.get("collation");
    assertEquals("lowerfilt:(+faith +homer +loaves)", singleCollation);
    // Testing backwards-compatible response format but will only return a
    // collation that would return results.
    params.remove(SpellingParams.SPELLCHECK_BUILD);
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
    handler = core.getRequestHandler("spellCheckCompRH");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    singleCollation = (String) collationHolder.get("collation");
    assertEquals("lowerfilt:(+faith +hope +loaves)", singleCollation);
    // Testing returning multiple collations if more than one valid
    // combination exists.
    params.remove(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES);
    params.remove(SpellingParams.SPELLCHECK_MAX_COLLATIONS);
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "2");
    handler = core.getRequestHandler("spellCheckCompRH");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size() == 2);
    for (String multipleCollation : collations) {
        assertTrue(multipleCollation.equals("lowerfilt:(+faith +hope +love)") || multipleCollation.equals("lowerfilt:(+faith +hope +loaves)"));
    }
    // Testing return multiple collations with expanded collation response
    // format.
    params.add(SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true");
    handler = core.getRequestHandler("spellCheckCompRH");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    values = rsp.getValues();
    spellCheck = (NamedList) values.get("spellcheck");
    collationHolder = (NamedList) spellCheck.get("collations");
    List<NamedList> expandedCollationList = collationHolder.getAll("collation");
    Set<String> usedcollations = new HashSet<>();
    assertTrue(expandedCollationList.size() == 2);
    for (NamedList expandedCollation : expandedCollationList) {
        String multipleCollation = (String) expandedCollation.get("collationQuery");
        assertTrue(multipleCollation.equals("lowerfilt:(+faith +hope +love)") || multipleCollation.equals("lowerfilt:(+faith +hope +loaves)"));
        assertTrue(!usedcollations.contains(multipleCollation));
        usedcollations.add(multipleCollation);
        int hits = (Integer) expandedCollation.get("hits");
        assertTrue(hits == 1);
        NamedList misspellingsAndCorrections = (NamedList) expandedCollation.get("misspellingsAndCorrections");
        assertTrue(misspellingsAndCorrections.size() == 3);
        String correctionForFauth = (String) misspellingsAndCorrections.get("fauth");
        String correctionForHome = (String) misspellingsAndCorrections.get("home");
        String correctionForLoane = (String) misspellingsAndCorrections.get("loane");
        assertTrue(correctionForFauth.equals("faith"));
        assertTrue(correctionForHome.equals("hope"));
        assertTrue(correctionForLoane.equals("love") || correctionForLoane.equals("loaves"));
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SearchComponent(org.apache.solr.handler.component.SearchComponent) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollationWithHypens.

@Test
public void testCollationWithHypens() 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(CommonParams.Q, "lowerfilt:(hypenated-wotd)");
    {
        SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
        SolrQueryResponse rsp = new SolrQueryResponse();
        rsp.addResponseHeader(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();
        assertTrue("Incorrect collation: " + collation, "lowerfilt:(hyphenated-word)".equals(collation));
    }
    params.remove(CommonParams.Q);
    params.add("defType", "dismax");
    params.add("qf", "lowerfilt");
    params.add(CommonParams.Q, "hypenated-wotd");
    {
        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();
        assertTrue("Incorrect collation: " + collation, "hyphenated-word".equals(collation));
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 5 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollationWithRangeQuery.

@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.addResponseHeader(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));
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Aggregations

SearchComponent (org.apache.solr.handler.component.SearchComponent)12 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)11 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)11 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)11 NamedList (org.apache.solr.common.util.NamedList)10 Test (org.junit.Test)10 SolrCore (org.apache.solr.core.SolrCore)9 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)8 List (java.util.List)4 ResponseBuilder (org.apache.solr.handler.component.ResponseBuilder)3 ArrayList (java.util.ArrayList)2 IndexReader (org.apache.lucene.index.IndexReader)2 SolrParams (org.apache.solr.common.params.SolrParams)2 QueryComponent (org.apache.solr.handler.component.QueryComponent)2 EarlyTerminatingCollectorException (org.apache.solr.search.EarlyTerminatingCollectorException)2 HashSet (java.util.HashSet)1 Term (org.apache.lucene.index.Term)1 SpanPayloadCheckQuery (org.apache.lucene.queries.payloads.SpanPayloadCheckQuery)1