Search in sources :

Example 1 with SolrRequestInfo

use of org.apache.solr.request.SolrRequestInfo 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 2 with SolrRequestInfo

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

the class UpdateProcessorTestBase method processAdd.

/**
   * Runs a document through the specified chain, and returns the final
   * document used when the chain is completed (NOTE: some chains may
   * modify the document in place
   */
protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, final SolrInputDocument docIn) 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, requestParams);
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docIn;
        UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
        if (null != processor) {
            // test chain might be empty or short circuited.
            processor.processAdd(cmd);
        }
        return cmd.solrDoc;
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
}
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) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 3 with SolrRequestInfo

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

the class TestHarness method query.

/**
   * Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the end.
   *
   * @param handler the name of the request handler to process the request
   * @param req the Query to process, will be closed.
   * @return The XML response to the query
   * @exception Exception any exception in the response.
   * @exception IOException if there is a problem writing the XML
   * @see LocalSolrQueryRequest
   */
public String query(String handler, SolrQueryRequest req) throws Exception {
    try {
        SolrCore core = req.getCore();
        SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        core.execute(core.getRequestHandler(handler), req, rsp);
        if (rsp.getException() != null) {
            throw rsp.getException();
        }
        QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
        if (responseWriter instanceof BinaryQueryResponseWriter) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(32000);
            BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter) responseWriter;
            writer.write(byteArrayOutputStream, req, rsp);
            return new String(byteArrayOutputStream.toByteArray(), "UTF-8");
        } else {
            StringWriter sw = new StringWriter(32000);
            responseWriter.write(sw, req, rsp);
            return sw.toString();
        }
    } finally {
        req.close();
        SolrRequestInfo.clearRequestInfo();
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) StringWriter(java.io.StringWriter) SolrCore(org.apache.solr.core.SolrCore) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) BinaryQueryResponseWriter(org.apache.solr.response.BinaryQueryResponseWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinaryQueryResponseWriter(org.apache.solr.response.BinaryQueryResponseWriter)

Example 4 with SolrRequestInfo

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

the class TestSchemalessBufferedUpdates method processAdd.

private SolrInputDocument processAdd(final SolrInputDocument docIn) throws IOException {
    UpdateRequestProcessorChain processorChain = h.getCore().getUpdateProcessingChain(UPDATE_CHAIN);
    assertNotNull("Undefined URP chain '" + UPDATE_CHAIN + "'", processorChain);
    List<UpdateRequestProcessorFactory> factoriesUpToDUP = new ArrayList<>();
    for (UpdateRequestProcessorFactory urpFactory : processorChain.getProcessors()) {
        factoriesUpToDUP.add(urpFactory);
        if (urpFactory.getClass().equals(DistributedUpdateProcessorFactory.class))
            break;
    }
    UpdateRequestProcessorChain chainUpToDUP = new UpdateRequestProcessorChain(factoriesUpToDUP, h.getCore());
    assertNotNull("URP chain '" + UPDATE_CHAIN + "'", chainUpToDUP);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = req();
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docIn;
        UpdateRequestProcessor processor = chainUpToDUP.createProcessor(req, rsp);
        processor.processAdd(cmd);
        if (cmd.solrDoc.get("f_dt").getValue() instanceof Date) {
            // Non-JSON types (Date in this case) aren't handled properly in noggit-0.6.  Although this is fixed in 
            // https://github.com/yonik/noggit/commit/ec3e732af7c9425e8f40297463cbe294154682b1 to call obj.toString(), 
            // Date::toString produces a Date representation that Solr doesn't like, so we convert using Instant::toString
            cmd.solrDoc.get("f_dt").setValue(((Date) cmd.solrDoc.get("f_dt").getValue()).toInstant().toString());
        }
        return cmd.solrDoc;
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ArrayList(java.util.ArrayList) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Date(java.util.Date)

Example 5 with SolrRequestInfo

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

the class QueryEqualityTest method assertQueryEquals.

/**
   * NOTE: defType is not only used to pick the parser, but, if non-null it is 
   * also to record the parser being tested for coverage sanity checking
   *
   * @see QueryUtils#check
   * @see QueryUtils#checkEqual
   * @see #testParserCoverage
   */
protected void assertQueryEquals(final String defType, final SolrQueryRequest req, final String... inputs) throws Exception {
    if (null != defType)
        qParsersTested.add(defType);
    final Query[] queries = new Query[inputs.length];
    try {
        SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        for (int i = 0; i < inputs.length; i++) {
            queries[i] = (QParser.getParser(inputs[i], defType, req).getQuery());
        }
    } finally {
        SolrRequestInfo.clearRequestInfo();
    }
    for (int i = 0; i < queries.length; i++) {
        QueryUtils.check(queries[i]);
        // of which caller/callee is used.
        for (int j = 0; j < queries.length; j++) {
            QueryUtils.checkEqual(queries[i], queries[j]);
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Query(org.apache.lucene.search.Query) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Aggregations

SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)29 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)22 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)16 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)9 SolrCore (org.apache.solr.core.SolrCore)9 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)8 Map (java.util.Map)5 QueryResponseWriter (org.apache.solr.response.QueryResponseWriter)5 Query (org.apache.lucene.search.Query)4 SolrException (org.apache.solr.common.SolrException)4 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 HashMap (java.util.HashMap)3 JavaBinCodec (org.apache.solr.common.util.JavaBinCodec)3 NamedList (org.apache.solr.common.util.NamedList)3 BinaryResponseWriter (org.apache.solr.response.BinaryResponseWriter)3 ResultContext (org.apache.solr.response.ResultContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2