Search in sources :

Example 16 with SolrQueryResponse

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

the class HttpSolrCall method sendError.

protected void sendError(Throwable ex) throws IOException {
    Exception exp = null;
    SolrCore localCore = null;
    try {
        SolrQueryResponse solrResp = new SolrQueryResponse();
        if (ex instanceof Exception) {
            solrResp.setException((Exception) ex);
        } else {
            solrResp.setException(new RuntimeException(ex));
        }
        localCore = core;
        if (solrReq == null) {
            final SolrParams solrParams;
            if (req != null) {
                // use GET parameters if available:
                solrParams = SolrRequestParsers.parseQueryString(req.getQueryString());
            } else {
                // we have no params at all, use empty ones:
                solrParams = new MapSolrParams(Collections.<String, String>emptyMap());
            }
            solrReq = new SolrQueryRequestBase(core, solrParams) {
            };
        }
        QueryResponseWriter writer = core.getQueryResponseWriter(solrReq);
        writeResponse(solrResp, writer, Method.GET);
    } catch (Exception e) {
        // This error really does not matter
        exp = e;
    } finally {
        try {
            if (exp != null) {
                SimpleOrderedMap info = new SimpleOrderedMap();
                int code = ResponseUtils.getErrorInfo(ex, info, log);
                sendError(code, info.toString());
            }
        } finally {
            if (core == null && localCore != null) {
                localCore.close();
            }
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) EOFException(java.io.EOFException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper.KeeperException)

Example 17 with SolrQueryResponse

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

the class HttpSolrCall method autoCreateSystemColl.

protected void autoCreateSystemColl(String corename) throws Exception {
    if (core == null && SYSTEM_COLL.equals(corename) && "POST".equals(req.getMethod()) && !cores.getZkController().getClusterState().hasCollection(SYSTEM_COLL)) {
        log.info("Going to auto-create .system collection");
        SolrQueryResponse rsp = new SolrQueryResponse();
        String repFactor = String.valueOf(Math.min(3, cores.getZkController().getClusterState().getLiveNodes().size()));
        cores.getCollectionsHandler().handleRequestBody(new LocalSolrQueryRequest(null, new ModifiableSolrParams().add(ACTION, CREATE.toString()).add(NAME, SYSTEM_COLL).add(REPLICATION_FACTOR, repFactor)), rsp);
        if (rsp.getValues().get("success") == null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Could not auto-create .system collection: " + Utils.toJSONString(rsp.getValues()));
        }
        TimeOut timeOut = new TimeOut(3, TimeUnit.SECONDS);
        for (; ; ) {
            if (cores.getZkController().getClusterState().getCollectionOrNull(SYSTEM_COLL) != null) {
                break;
            } else {
                if (timeOut.hasTimedOut()) {
                    throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find .system collection even after 3 seconds");
                }
                Thread.sleep(50);
            }
        }
        action = RETRY;
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) TimeOut(org.apache.solr.util.TimeOut) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 18 with SolrQueryResponse

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

the class TestGroupingSearch method testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin.

@Test
public void testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin() throws Exception {
    assertU(add(doc("id", "1", "nullfirst", "1")));
    assertU(add(doc("id", "2", "nullfirst", "1")));
    assertU(add(doc("id", "3", "nullfirst", "2")));
    assertU(add(doc("id", "4", "nullfirst", "2")));
    assertU(add(doc("id", "5", "nullfirst", "2")));
    assertU(add(doc("id", "6", "nullfirst", "3")));
    assertU(commit());
    SolrQueryRequest request = req("q", "*:*", "group", "true", "group.field", "nullfirst", "group.main", "true", "wt", "javabin", "start", "4", "rows", "10");
    SolrQueryResponse response = new SolrQueryResponse();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(request, response));
        String handlerName = request.getParams().get(CommonParams.QT);
        h.getCore().execute(h.getCore().getRequestHandler(handlerName), request, response);
        BinaryResponseWriter responseWriter = new BinaryResponseWriter();
        responseWriter.write(out, request, response);
    } finally {
        request.close();
        SolrRequestInfo.clearRequestInfo();
    }
    assertEquals(6, ((ResultContext) response.getResponse()).getDocList().matches());
    new BinaryResponseParser().processResponse(new ByteArrayInputStream(out.toByteArray()), "");
    out.close();
}
Also used : ResultContext(org.apache.solr.response.ResultContext) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 19 with SolrQueryResponse

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

the class BasicFunctionalityTest method testXMLWriter.

@Test
public void testXMLWriter() throws Exception {
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.add("\"quoted\"", "\"value\"");
    StringWriter writer = new StringWriter(32000);
    SolrQueryRequest req = req("foo");
    XMLWriter.writeResponse(writer, req, rsp);
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    builder.parse(new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)));
    req.close();
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 20 with SolrQueryResponse

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

the class BasicFunctionalityTest method testNotLazyField.

@Test
public void testNotLazyField() throws IOException {
    assertU(adoc("id", "7777", "title", "keyword", "test_hlt", mkstr(20000)));
    assertU(commit());
    SolrCore core = h.getCore();
    SolrQueryRequest req = req("q", "id:7777", "fl", "id,title,test_hlt");
    SolrQueryResponse rsp = new SolrQueryResponse();
    core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
    DocList dl = ((ResultContext) rsp.getResponse()).getDocList();
    Document d = req.getSearcher().doc(dl.iterator().nextDoc());
    // ensure field in fl is not lazy
    assertFalse(((Field) d.getField("test_hlt")).getClass().getSimpleName().equals("LazyField"));
    assertFalse(((Field) d.getField("title")).getClass().getSimpleName().equals("LazyField"));
    req.close();
}
Also used : ResultContext(org.apache.solr.response.ResultContext) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrCore(org.apache.solr.core.SolrCore) LazyDocument(org.apache.lucene.document.LazyDocument) Document(org.apache.lucene.document.Document) DocList(org.apache.solr.search.DocList) 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