Search in sources :

Example 16 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 17 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 18 with SolrRequestHandler

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

the class TestInitParams method testComponentWithInitParams.

@Test
public void testComponentWithInitParams() {
    for (String s : Arrays.asList("/dump1", "/dump3", "/root/dump5", "/root1/anotherlevel/dump6")) {
        SolrRequestHandler handler = h.getCore().getRequestHandler(s);
        SolrQueryResponse rsp = new SolrQueryResponse();
        handler.handleRequest(req("initArgs", "true"), rsp);
        NamedList nl = (NamedList) rsp.getValues().get("initArgs");
        NamedList def = (NamedList) nl.get(PluginInfo.DEFAULTS);
        assertEquals("A", def.get("a"));
        def = (NamedList) nl.get(PluginInfo.INVARIANTS);
        assertEquals("B", def.get("b"));
        def = (NamedList) nl.get(PluginInfo.APPENDS);
        assertEquals("C", def.get("c"));
    }
    InitParams initParams = h.getCore().getSolrConfig().getInitParams().get("a");
    PluginInfo pluginInfo = new PluginInfo("requestHandler", new HashMap<String, String>(), new NamedList<>(singletonMap("defaults", new NamedList(Utils.makeMap("a", "A1")))), null);
    initParams.apply(pluginInfo);
    assertEquals("A", initParams.defaults.get("a"));
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NamedList(org.apache.solr.common.util.NamedList) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 19 with SolrRequestHandler

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

Example 20 with SolrRequestHandler

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

the class SpellCheckCollatorTest method testWithCursorMark.

@Test
public void testWithCursorMark() 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, "2");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    params.add(CommonParams.SORT, "id asc");
    params.add(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START);
    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 collationList = (NamedList) spellCheck.get("collations");
    List<?> collations = (List<?>) collationList.getAll("collation");
    assertTrue(collations.size() == 1);
}
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

SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)35 Test (org.junit.Test)20 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)19 NamedList (org.apache.solr.common.util.NamedList)16 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)15 SolrCore (org.apache.solr.core.SolrCore)15 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)11 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 HashMap (java.util.HashMap)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 SolrParams (org.apache.solr.common.params.SolrParams)2 CoreContainer (org.apache.solr.core.CoreContainer)2 Counter (com.codahale.metrics.Counter)1 InputStream (java.io.InputStream)1