use of org.apache.solr.common.params.MapSolrParams 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();
}
}
}
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class DirectSolrConnection method request.
/**
* For example:
*
* String json = solr.request( "/select?qt=dismax&wt=json&q=...", null );
* String xml = solr.request( "/update", "<add><doc><field ..." );
*/
public String request(String pathAndParams, String body) throws Exception {
String path = null;
SolrParams params = null;
int idx = pathAndParams.indexOf('?');
if (idx > 0) {
path = pathAndParams.substring(0, idx);
params = SolrRequestParsers.parseQueryString(pathAndParams.substring(idx + 1));
} else {
path = pathAndParams;
params = new MapSolrParams(new HashMap<String, String>());
}
return request(path, params, body);
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class CopyFieldTest method testCopyFieldFunctionality.
@Test
public void testCopyFieldFunctionality() {
SolrCore core = h.getCore();
assertU(adoc("id", "5", "title", "test copy field", "text_en", "this is a simple test of the copy field functionality"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "text_en:simple");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("Make sure they got in", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']");
args = new HashMap<>();
args.put(CommonParams.Q, "highlight:simple");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic source", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']", "//result/doc[1]/arr[@name='highlight']/str[.='this is a simple test of ']");
args = new HashMap<>();
args.put(CommonParams.Q, "text_en:functionality");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("Make sure they got in", req, "//*[@numFound='1']");
args = new HashMap<>();
args.put(CommonParams.Q, "highlight:functionality");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic source", req, "//*[@numFound='0']");
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class TestMaxScoreQueryParser method parse.
//
// Helper methods
//
private Query parse(String q, String... params) {
try {
ModifiableSolrParams p = new ModifiableSolrParams();
ArrayList<String> al = new ArrayList<>(Arrays.asList(params));
while (al.size() >= 2) {
p.add(al.remove(0), al.remove(0));
}
return new MaxScoreQParser(q, p, new MapSolrParams(Collections.singletonMap("df", "text")), req(q)).parse();
} catch (SyntaxError syntaxError) {
fail("Failed with exception " + syntaxError.getMessage());
}
fail("Parse failed");
return null;
}
use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.
the class HardAutoCommitTest method testCommitWithin.
public void testCommitWithin() throws Exception {
SolrCore core = h.getCore();
NewSearcherListener trigger = new NewSearcherListener();
core.registerNewSearcherListener(trigger);
DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
CommitTracker tracker = updater.commitTracker;
tracker.setTimeUpperBound(0);
tracker.setDocsUpperBound(-1);
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
// Add a single document with commitWithin == 2 second
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};
req.setContentStreams(AutoCommitTest.toContentStreams(adoc(2000, "id", "529", "field_t", "what's inside?", "subject", "info"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Check it isn't in the index
assertQ("shouldn't find any", req("id:529"), "//result[@numFound=0]");
// Wait longer than the commitWithin time
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
// Add one document without commitWithin
req.setContentStreams(AutoCommitTest.toContentStreams(adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Check it isn't in the index
assertQ("shouldn't find any", req("id:530"), "//result[@numFound=0]");
// Delete one document with commitWithin
trigger.pause();
req.setContentStreams(AutoCommitTest.toContentStreams(delI("529", "commitWithin", "1000"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Now make sure we can find it
assertQ("should find one", req("id:529"), "//result[@numFound=1]");
trigger.unpause();
// Wait for the commit to happen
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
// Now we shouldn't find it
assertQ("should find none", req("id:529"), "//result[@numFound=0]");
// ... but we should find the new one
assertQ("should find one", req("id:530"), "//result[@numFound=1]");
trigger.reset();
// now make the call 10 times really fast and make sure it
// only commits once
req.setContentStreams(AutoCommitTest.toContentStreams(adoc(2000, "id", "500"), null));
for (int i = 0; i < 10; i++) {
handler.handleRequest(req, rsp);
}
assertQ("should not be there yet", req("id:500"), "//result[@numFound=0]");
// the same for the delete
req.setContentStreams(AutoCommitTest.toContentStreams(delI("530", "commitWithin", "1000"), null));
for (int i = 0; i < 10; i++) {
handler.handleRequest(req, rsp);
}
assertQ("should be there", req("id:530"), "//result[@numFound=1]");
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
assertQ("should be there", req("id:500"), "//result[@numFound=1]");
assertQ("should not be there", req("id:530"), "//result[@numFound=0]");
assertEquals(3, tracker.getCommitCount());
}
Aggregations