Search in sources :

Example 76 with SolrQueryResponse

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

the class CoreAdminCreateDiscoverTest method testCreateSavesRegProps.

@Test
public void testCreateSavesRegProps() throws Exception {
    setupCore(coreNormal, true);
    // create a new core (using CoreAdminHandler) w/ properties
    // Just to be sure it's NOT written to the core.properties file
    File workDir = new File(solrHomeDirectory, coreNormal);
    File data = new File(workDir, "data");
    SolrQueryResponse resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.NAME, coreNormal, CoreAdminParams.INSTANCE_DIR, workDir.getAbsolutePath(), CoreAdminParams.CONFIG, "solrconfig_ren.xml", CoreAdminParams.SCHEMA, "schema_ren.xml", CoreAdminParams.DATA_DIR, data.getAbsolutePath()), resp);
    assertNull("Exception on create", resp.getException());
    // verify props are in persisted file
    Properties props = new Properties();
    File propFile = new File(solrHomeDirectory, coreNormal + "/" + CorePropertiesLocator.PROPERTIES_FILENAME);
    FileInputStream is = new FileInputStream(propFile);
    try {
        props.load(new InputStreamReader(is, StandardCharsets.UTF_8));
    } finally {
        org.apache.commons.io.IOUtils.closeQuietly(is);
    }
    assertEquals("Unexpected value preserved in properties file " + propFile.getAbsolutePath(), props.getProperty(CoreAdminParams.NAME), coreNormal);
    assertEquals("Unexpected value preserved in properties file " + propFile.getAbsolutePath(), props.getProperty(CoreAdminParams.CONFIG), "solrconfig_ren.xml");
    assertEquals("Unexpected value preserved in properties file " + propFile.getAbsolutePath(), props.getProperty(CoreAdminParams.SCHEMA), "schema_ren.xml");
    assertEquals("Unexpected value preserved in properties file " + propFile.getAbsolutePath(), props.getProperty(CoreAdminParams.DATA_DIR), data.getAbsolutePath());
    assertEquals(props.size(), 4);
    //checkOnlyKnown(propFile);
    // For the other 3 vars, we couldn't get past creating the core if dereferencing didn't work correctly.
    // Should have segments in the directory pointed to by the ${DATA_TEST}.
    File test = new File(data, "index");
    assertTrue("Should have found index dir at " + test.getAbsolutePath(), test.exists());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) InputStreamReader(java.io.InputStreamReader) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 77 with SolrQueryResponse

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

the class TestScoreJoinQPNoScore method testJoinQueryType.

public void testJoinQueryType() throws SyntaxError, IOException {
    SolrQueryRequest req = null;
    try {
        final String score = whateverScore();
        req = req("{!join from=dept_id_s to=dept_ss" + score + "}text_t:develop");
        SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        {
            final Query query = QParser.getParser(req.getParams().get("q"), req).getQuery();
            final Query rewrittenQuery = query.rewrite(req.getSearcher().getIndexReader());
            assertEquals(rewrittenQuery + " is expected to be from Solr", ScoreJoinQParserPlugin.class.getPackage().getName(), rewrittenQuery.getClass().getPackage().getName());
        }
        {
            final Query query = QParser.getParser("{!join from=dept_id_s to=dept_ss}text_t:develop", req).getQuery();
            final Query rewrittenQuery = query.rewrite(req.getSearcher().getIndexReader());
            assertEquals(rewrittenQuery + " is expected to be from Solr", JoinQParserPlugin.class.getPackage().getName(), rewrittenQuery.getClass().getPackage().getName());
        }
    } finally {
        if (req != null) {
            req.close();
        }
        SolrRequestInfo.clearRequestInfo();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Query(org.apache.lucene.search.Query) JoinQParserPlugin(org.apache.solr.search.JoinQParserPlugin) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Example 78 with SolrQueryResponse

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

the class UpdateParamsTest method testUpdateProcessorParamDeprecationRemoved.

/**
   * Tests that only update.chain and not update.processor works (SOLR-2105)
   */
public void testUpdateProcessorParamDeprecationRemoved() throws Exception {
    SolrCore core = h.getCore();
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    params.getMap().put("update.processor", "nonexistant");
    // Add a single document
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    // First check that the old param behaves as it should
    try {
        handler.handleRequestBody(req, rsp);
        assertTrue("Old param update.processor should not have any effect anymore", true);
    } catch (Exception e) {
        assertFalse("Got wrong exception while testing update.chain", e.getMessage().equals("unknown UpdateRequestProcessorChain: nonexistant"));
    }
    // Then check that the new param behaves correctly
    params.getMap().remove("update.processor");
    params.getMap().put(UpdateParams.UPDATE_CHAIN, "nonexistant");
    req.setParams(params);
    try {
        handler.handleRequestBody(req, rsp);
        assertFalse("Faulty update.chain parameter not causing an error - i.e. it is not detected", true);
    } catch (Exception e) {
        assertEquals("Got wrong exception while testing update.chain", e.getMessage(), "unknown UpdateRequestProcessorChain: nonexistant");
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler)

Example 79 with SolrQueryResponse

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

the class ClassificationUpdateProcessorFactoryTest method init_unsupportedFilterQuery_shouldThrowExceptionWithDetailedMessage.

@Test
public void init_unsupportedFilterQuery_shouldThrowExceptionWithDetailedMessage() {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    SolrQueryRequest mockRequest = mock(SolrQueryRequest.class);
    SolrQueryResponse mockResponse = mock(SolrQueryResponse.class);
    args.add("knn.filterQuery", "not supported query");
    try {
        cFactoryToTest.init(args);
        /* parsing failure happens because of the mocks, fine enough to check a proper exception propagation */
        cFactoryToTest.getInstance(mockRequest, mockResponse, mockProcessor);
    } catch (SolrException e) {
        assertEquals("Classification UpdateProcessor Training Filter Query: 'not supported query' is not supported", e.getMessage());
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 80 with SolrQueryResponse

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

the class CSVRequestHandlerTest method testCommitWithin.

@Test
public void testCommitWithin() throws Exception {
    String csvString = "id;name\n123;hello";
    SolrQueryRequest req = req("separator", ";", "commitWithin", "200");
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    CSVLoader loader = new CSVLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream.StringStream(csvString), p);
    AddUpdateCommand add = p.addCommands.get(0);
    assertEquals(200, add.commitWithin);
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) CSVLoader(org.apache.solr.handler.loader.CSVLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) 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