Search in sources :

Example 26 with SolrRequestHandler

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

the class SolrTestCaseJ4 method updateJ.

/** Send JSON update commands */
public static String updateJ(String json, SolrParams args) throws Exception {
    SolrCore core = h.getCore();
    if (args == null) {
        args = params("wt", "json", "indent", "true");
    } else {
        ModifiableSolrParams newArgs = new ModifiableSolrParams(args);
        if (newArgs.get("wt") == null)
            newArgs.set("wt", "json");
        if (newArgs.get("indent") == null)
            newArgs.set("indent", "true");
        args = newArgs;
    }
    DirectSolrConnection connection = new DirectSolrConnection(core);
    SolrRequestHandler handler = core.getRequestHandler("/update/json");
    if (handler == null) {
        handler = new UpdateRequestHandler();
        handler.init(null);
    }
    return connection.request(handler, args, json);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) DirectSolrConnection(org.apache.solr.servlet.DirectSolrConnection) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Example 27 with SolrRequestHandler

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

the class EmptyRequestHandler method testRefCount.

@Test
public void testRefCount() throws Exception {
    SolrCore core = h.getCore();
    assertTrue("Refcount != 1", core.getOpenCount() == 1);
    final CoreContainer cores = h.getCoreContainer();
    SolrCore c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
    assertTrue("Refcount != 2", core.getOpenCount() == 2);
    ClosingRequestHandler handler1 = new ClosingRequestHandler();
    handler1.inform(core);
    String path = "/this/is A path /that won't be registered!";
    SolrRequestHandler old = core.registerRequestHandler(path, handler1);
    // should not be anything...
    assertNull(old);
    assertEquals(core.getRequestHandlers().get(path), handler1);
    SolrCore c2 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
    c1.close();
    assertTrue("Refcount < 1", core.getOpenCount() >= 1);
    assertTrue("Handler is closed", handler1.closed == false);
    c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
    assertTrue("Refcount < 2", core.getOpenCount() >= 2);
    assertTrue("Handler is closed", handler1.closed == false);
    c2.close();
    assertTrue("Refcount < 1", core.getOpenCount() >= 1);
    assertTrue("Handler is closed", handler1.closed == false);
    c1.close();
    cores.shutdown();
    assertTrue("Refcount != 0", core.getOpenCount() == 0);
    assertTrue("Handler not closed", core.isClosed() && handler1.closed == true);
}
Also used : SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 28 with SolrRequestHandler

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

the class EmptyRequestHandler method testRefCountMT.

@Test
public void testRefCountMT() throws Exception {
    SolrCore core = h.getCore();
    assertTrue("Refcount != 1", core.getOpenCount() == 1);
    final ClosingRequestHandler handler1 = new ClosingRequestHandler();
    handler1.inform(core);
    String path = "/this/is A path /that won't be registered!";
    SolrRequestHandler old = core.registerRequestHandler(path, handler1);
    // should not be anything...
    assertNull(old);
    assertEquals(core.getRequestHandlers().get(path), handler1);
    final int LOOP = 100;
    final int MT = 16;
    ExecutorService service = ExecutorUtil.newMDCAwareFixedThreadPool(MT, new DefaultSolrThreadFactory("refCountMT"));
    List<Callable<Integer>> callees = new ArrayList<>(MT);
    final CoreContainer cores = h.getCoreContainer();
    for (int i = 0; i < MT; ++i) {
        Callable<Integer> call = new Callable<Integer>() {

            void yield(int n) {
                try {
                    Thread.sleep(0, (n % 13 + 1) * 10);
                } catch (InterruptedException xint) {
                }
            }

            @Override
            public Integer call() {
                SolrCore core = null;
                int r = 0;
                try {
                    for (int l = 0; l < LOOP; ++l) {
                        r += 1;
                        core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
                        // sprinkle concurrency hinting...
                        yield(l);
                        assertTrue("Refcount < 1", core.getOpenCount() >= 1);
                        yield(l);
                        assertTrue("Refcount > 17", core.getOpenCount() <= 17);
                        yield(l);
                        assertTrue("Handler is closed", handler1.closed == false);
                        yield(l);
                        core.close();
                        core = null;
                        yield(l);
                    }
                    return r;
                } finally {
                    if (core != null)
                        core.close();
                }
            }
        };
        callees.add(call);
    }
    List<Future<Integer>> results = service.invokeAll(callees);
    for (Future<Integer> result : results) {
        assertTrue("loop=" + result.get() + " < " + LOOP, result.get() >= LOOP);
    }
    cores.shutdown();
    assertTrue("Refcount != 0", core.getOpenCount() == 0);
    assertTrue("Handler not closed", core.isClosed() && handler1.closed == true);
    service.shutdown();
    assertTrue("Running for too long...", service.awaitTermination(60, TimeUnit.SECONDS));
}
Also used : ArrayList(java.util.ArrayList) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) Callable(java.util.concurrent.Callable) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 29 with SolrRequestHandler

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

the class SpellCheckComponentTest method testThresholdTokenFrequency.

@Test
public void testThresholdTokenFrequency() throws Exception {
    //"document" is in 2 documents but "another" is only in 1.
    //So with a threshold of 29%, "another" is absent from the dictionary
    //while "document" is present.
    assertJQ(req("qt", rh, SpellCheckComponent.COMPONENT_NAME, "true", "q", "documenq", SpellingParams.SPELLCHECK_DICT, "threshold", SpellingParams.SPELLCHECK_COUNT, "5", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true"), "/spellcheck/suggestions/[1]/suggestion==[{'word':'document','freq':2}]");
    assertJQ(req("qt", rh, SpellCheckComponent.COMPONENT_NAME, "true", "q", "documenq", SpellingParams.SPELLCHECK_DICT, "threshold_direct", SpellingParams.SPELLCHECK_COUNT, "5", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true"), "/spellcheck/suggestions/[1]/suggestion==[{'word':'document','freq':2}]");
    //TODO:  how do we make this into a 1-liner using "assertQ()" ???
    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_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_DICT, "threshold");
    params.add(SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true");
    params.add(CommonParams.Q, "anotheq");
    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 suggestions = (NamedList) spellCheck.get("suggestions");
    assertTrue(suggestions.get("suggestion") == null);
    assertTrue((Boolean) spellCheck.get("correctlySpelled") == false);
    params.remove(SpellingParams.SPELLCHECK_DICT);
    params.add(SpellingParams.SPELLCHECK_DICT, "threshold_direct");
    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");
    suggestions = (NamedList) spellCheck.get("suggestions");
    assertTrue(suggestions.get("suggestion") == null);
    assertTrue((Boolean) spellCheck.get("correctlySpelled") == false);
}
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) 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 30 with SolrRequestHandler

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

the class TestIndexSearcher method addDummyDoc.

private void addDummyDoc(SolrCore core) throws Exception {
    DirectSolrConnection connection = new DirectSolrConnection(core);
    SolrRequestHandler handler = core.getRequestHandler("/update");
    connection.request(handler, null, adoc("id", "1"));
}
Also used : DirectSolrConnection(org.apache.solr.servlet.DirectSolrConnection) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

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