Search in sources :

Example 56 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse 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 57 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class IgnoreCommitOptimizeUpdateProcessorFactoryTest method processCommit.

SolrQueryResponse processCommit(final String chain, boolean optimize, Boolean commitEndPoint) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
    if (commitEndPoint != null) {
        ((ModifiableSolrParams) req.getParams()).set(DistributedUpdateProcessor.COMMIT_END_POINT, commitEndPoint.booleanValue());
    }
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
        cmd.optimize = optimize;
        UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
        processor.processCommit(cmd);
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
    return rsp;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 58 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class IgnoreCommitOptimizeUpdateProcessorFactoryTest method testIgnoreCommit.

public void testIgnoreCommit() throws Exception {
    // verify that the processor returns an error if it receives a commit
    SolrQueryResponse rsp = processCommit("ignore-commit-from-client-403", false);
    assertNotNull("Sending a commit should have resulted in an exception in the response", rsp.getException());
    rsp = processCommit("ignore-commit-from-client-200", false);
    Exception shouldBeNull = rsp.getException();
    assertNull("Sending a commit should NOT have resulted in an exception in the response: " + shouldBeNull, shouldBeNull);
    rsp = processCommit("ignore-optimize-only-from-client-403", true);
    assertNotNull("Sending an optimize should have resulted in an exception in the response", rsp.getException());
    // commit should happen if DistributedUpdateProcessor.COMMIT_END_POINT == true
    rsp = processCommit("ignore-commit-from-client-403", false, new Boolean(true));
    shouldBeNull = rsp.getException();
    assertNull("Sending a commit should NOT have resulted in an exception in the response: " + shouldBeNull, shouldBeNull);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) IOException(java.io.IOException)

Example 59 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class SkipExistingDocumentsProcessorFactoryTest method testSkipInsertsFalseIfInInitArgs.

@Test
public void testSkipInsertsFalseIfInInitArgs() {
    SkipExistingDocumentsProcessorFactory factory = new SkipExistingDocumentsProcessorFactory();
    NamedList<Object> initArgs = new NamedList<>();
    initArgs.add("skipInsertIfExists", false);
    factory.init(initArgs);
    UpdateRequestProcessor next = Mockito.mock(DistributedUpdateProcessor.class);
    SkipExistingDocumentsUpdateProcessor processor = factory.getInstance(defaultRequest, new SolrQueryResponse(), next);
    assertFalse("Expected skipInsertIfExists to be false", processor.isSkipInsertIfExists());
    assertTrue("Expected skipUpdateIfMissing to be true", processor.isSkipUpdateIfMissing());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NamedList(org.apache.solr.common.util.NamedList) SkipExistingDocumentsUpdateProcessor(org.apache.solr.update.processor.SkipExistingDocumentsProcessorFactory.SkipExistingDocumentsUpdateProcessor) Test(org.junit.Test)

Example 60 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class SkipExistingDocumentsProcessorFactoryTest method testSkipInsertsAndUpdatesDefaultToTrueIfNotConfigured.

@Test
public void testSkipInsertsAndUpdatesDefaultToTrueIfNotConfigured() {
    SkipExistingDocumentsProcessorFactory factory = new SkipExistingDocumentsProcessorFactory();
    NamedList<Object> initArgs = new NamedList<>();
    factory.init(initArgs);
    UpdateRequestProcessor next = Mockito.mock(DistributedUpdateProcessor.class);
    SkipExistingDocumentsUpdateProcessor processor = factory.getInstance(defaultRequest, new SolrQueryResponse(), next);
    assertTrue("Expected skipInsertIfExists to be true", processor.isSkipInsertIfExists());
    assertTrue("Expected skipUpdateIfMissing to be true", processor.isSkipUpdateIfMissing());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NamedList(org.apache.solr.common.util.NamedList) SkipExistingDocumentsUpdateProcessor(org.apache.solr.update.processor.SkipExistingDocumentsProcessorFactory.SkipExistingDocumentsUpdateProcessor) Test(org.junit.Test)

Aggregations

SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)258 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)128 Test (org.junit.Test)100 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)80 NamedList (org.apache.solr.common.util.NamedList)68 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)58 SolrCore (org.apache.solr.core.SolrCore)52 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)40 SolrException (org.apache.solr.common.SolrException)32 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)29 ArrayList (java.util.ArrayList)26 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)22 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)21 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)20 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)20 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)16