Search in sources :

Example 1 with SolrRequestHandler

use of org.apache.solr.request.SolrRequestHandler 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 SolrRequestHandler

use of org.apache.solr.request.SolrRequestHandler in project lucene-solr by apache.

the class RequestHandlerBase method getRequestHandler.

/**
   * Get the request handler registered to a given name.
   *
   * This function is thread safe.
   */
public static SolrRequestHandler getRequestHandler(String handlerName, PluginBag<SolrRequestHandler> reqHandlers) {
    if (handlerName == null)
        return null;
    SolrRequestHandler handler = reqHandlers.get(handlerName);
    int idx = 0;
    if (handler == null) {
        for (; ; ) {
            idx = handlerName.indexOf('/', idx + 1);
            if (idx > 0) {
                String firstPart = handlerName.substring(0, idx);
                handler = reqHandlers.get(firstPart);
                if (handler == null)
                    continue;
                if (handler instanceof NestedRequestHandler) {
                    return ((NestedRequestHandler) handler).getSubHandler(handlerName.substring(idx));
                }
            } else {
                break;
            }
        }
    }
    return handler;
}
Also used : SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Example 3 with SolrRequestHandler

use of org.apache.solr.request.SolrRequestHandler in project lucene-solr by apache.

the class TestCrossCoreJoin method update.

public static String update(SolrCore core, String xml) throws Exception {
    DirectSolrConnection connection = new DirectSolrConnection(core);
    SolrRequestHandler handler = core.getRequestHandler("/update");
    return connection.request(handler, null, xml);
}
Also used : DirectSolrConnection(org.apache.solr.servlet.DirectSolrConnection) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Example 4 with SolrRequestHandler

use of org.apache.solr.request.SolrRequestHandler in project lucene-solr by apache.

the class TestSubQueryTransformerCrossCore method update.

public static String update(SolrCore core, String xml) throws Exception {
    DirectSolrConnection connection = new DirectSolrConnection(core);
    SolrRequestHandler handler = core.getRequestHandler("/update");
    return connection.request(handler, null, xml);
}
Also used : DirectSolrConnection(org.apache.solr.servlet.DirectSolrConnection) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Example 5 with SolrRequestHandler

use of org.apache.solr.request.SolrRequestHandler 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)

Aggregations

SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)38 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)22 Test (org.junit.Test)20 NamedList (org.apache.solr.common.util.NamedList)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)18 SolrCore (org.apache.solr.core.SolrCore)15 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)14 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)13 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 SearchComponent (org.apache.solr.handler.component.SearchComponent)9 SolrException (org.apache.solr.common.SolrException)6 DirectSolrConnection (org.apache.solr.servlet.DirectSolrConnection)6 IOException (java.io.IOException)5 List (java.util.List)4 SolrDocumentList (org.apache.solr.common.SolrDocumentList)3 HashMap (java.util.HashMap)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 SolrDocument (org.apache.solr.common.SolrDocument)2 SolrParams (org.apache.solr.common.params.SolrParams)2 CoreContainer (org.apache.solr.core.CoreContainer)2