use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class BasicFunctionalityTest method testSolrParams.
@Test
public void testSolrParams() throws Exception {
NamedList nl = new NamedList();
nl.add("i", 555);
nl.add("s", "bbb");
nl.add("bt", "true");
nl.add("bf", "false");
Map<String, String> m = new HashMap<>();
m.put("f.field1.i", "1000");
m.put("s", "BBB");
m.put("ss", "SSS");
LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, nl);
SolrParams p = req.getParams();
assertEquals(p.get("i"), "555");
assertEquals(p.getInt("i").intValue(), 555);
assertEquals(p.getInt("i", 5), 555);
assertEquals(p.getInt("iii", 5), 5);
assertEquals(p.getFieldParam("field1", "i"), "555");
req.setParams(SolrParams.wrapDefaults(p, new MapSolrParams(m)));
p = req.getParams();
assertEquals(req.getOriginalParams().get("s"), "bbb");
assertEquals(p.get("i"), "555");
assertEquals(p.getInt("i").intValue(), 555);
assertEquals(p.getInt("i", 5), 555);
assertEquals(p.getInt("iii", 5), 5);
assertEquals(p.getFieldParam("field1", "i"), "1000");
assertEquals(p.get("s"), "bbb");
assertEquals(p.get("ss"), "SSS");
assertEquals(!!p.getBool("bt"), !p.getBool("bf"));
assertEquals(p.getBool("foo", true), true);
assertEquals(p.getBool("foo", false), false);
assertEquals(!!p.getBool("bt"), !p.getBool("bf"));
NamedList more = new NamedList();
more.add("s", "aaa");
more.add("s", "ccc");
more.add("ss", "YYY");
more.add("xx", "XXX");
p = SolrParams.wrapAppended(p, SolrParams.toSolrParams(more));
assertEquals(3, p.getParams("s").length);
assertEquals("bbb", p.getParams("s")[0]);
assertEquals("aaa", p.getParams("s")[1]);
assertEquals("ccc", p.getParams("s")[2]);
assertEquals(3, p.getParams("s").length);
assertEquals("SSS", p.get("ss"));
assertEquals("XXX", p.get("xx"));
req.close();
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class SolrIndexSearcher method warm.
/**
* Warm this searcher based on an old one (primarily for auto-cache warming).
*/
public void warm(SolrIndexSearcher old) {
// Make sure this is first! filters can help queryResults execute!
long warmingStartTime = System.nanoTime();
// warm the caches in order...
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("warming", "true");
for (int i = 0; i < cacheList.length; i++) {
if (log.isDebugEnabled()) {
log.debug("autowarming [{}] from [{}]\n\t{}", this, old, old.cacheList[i]);
}
final SolrQueryRequest req = new LocalSolrQueryRequest(core, params) {
@Override
public SolrIndexSearcher getSearcher() {
return SolrIndexSearcher.this;
}
@Override
public void close() {
}
};
final SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.clearRequestInfo();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
try {
cacheList[i].warm(this, old.cacheList[i]);
} finally {
try {
req.close();
} finally {
SolrRequestInfo.clearRequestInfo();
}
}
if (log.isDebugEnabled()) {
log.debug("autowarming result for [{}]\n\t{}", this, cacheList[i]);
}
}
warmupTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - warmingStartTime, TimeUnit.NANOSECONDS);
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class BasicZkTest method request.
public SolrQueryRequest request(String... q) {
LocalSolrQueryRequest req = lrf.makeRequest(q);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(req.getParams());
params.set("distrib", false);
req.setParams(params);
return req;
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class FieldAnalysisRequestHandlerTest method testNoDefaultField.
@Test(expected = Exception.class)
public void testNoDefaultField() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(CommonParams.Q, "fox brown");
SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params);
handler.resolveAnalysisRequest(req);
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class TestCollectionAPIs method makeCall.
public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag, String path, final SolrRequest.METHOD method, final String payload, final CoreContainer cc) throws Exception {
SolrParams queryParams = new MultiMapSolrParams(Collections.emptyMap());
if (path.indexOf('?') > 0) {
String queryStr = path.substring(path.indexOf('?') + 1);
path = path.substring(0, path.indexOf('?'));
queryParams = SolrRequestParsers.parseQueryString(queryStr);
}
final HashMap<String, String> parts = new HashMap<>();
Api api = apiBag.lookup(path, method.toString(), parts);
if (api == null)
throw new RuntimeException("No handler at path :" + path);
SolrQueryResponse rsp = new SolrQueryResponse();
LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams) {
@Override
public List<CommandOperation> getCommands(boolean validateInput) {
if (payload == null)
return Collections.emptyList();
return ApiBag.getCommandOperations(new StringReader(payload), api.getCommandSchema(), true);
}
@Override
public Map<String, String> getPathTemplateValues() {
return parts;
}
@Override
public String getHttpMethod() {
return method.toString();
}
};
try {
api.call(req, rsp);
} catch (ApiBag.ExceptionWithErrObject e) {
throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);
}
return new Pair<>(req, rsp);
}
Aggregations