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();
}
}
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();
}
}
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();
}
}
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();
}
}
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]);
}
}
}
Aggregations