use of org.apache.solr.client.solrj.impl.BinaryResponseParser 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();
}
use of org.apache.solr.client.solrj.impl.BinaryResponseParser in project lucene-solr by apache.
the class TestWriterPerf method doPerf.
void doPerf(String writerName, SolrQueryRequest req, int encIter, int decIter) throws Exception {
SolrQueryResponse rsp = getResponse(req);
QueryResponseWriter w = h.getCore().getQueryResponseWriter(writerName);
ByteArrayOutputStream out = null;
System.gc();
RTimer timer = new RTimer();
for (int i = 0; i < encIter; i++) {
if (w instanceof BinaryQueryResponseWriter) {
BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) w;
out = new ByteArrayOutputStream();
binWriter.write(out, req, rsp);
out.close();
} else {
out = new ByteArrayOutputStream();
// to be fair, from my previous tests, much of the performance will be sucked up
// by java's UTF-8 encoding/decoding, not the actual writing
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
w.write(writer, req, rsp);
writer.close();
}
}
double encodeTime = timer.getTime();
byte[] arr = out.toByteArray();
timer = new RTimer();
writerName = writerName.intern();
for (int i = 0; i < decIter; i++) {
ResponseParser rp = null;
if (writerName == "xml") {
rp = new XMLResponseParser();
} else if (writerName == "javabin") {
rp = new BinaryResponseParser();
} else {
break;
}
ByteArrayInputStream in = new ByteArrayInputStream(arr);
rp.processResponse(in, "UTF-8");
}
double decodeTime = timer.getTime();
log.info("writer " + writerName + ", size=" + out.size() + ", encodeRate=" + (encIter * 1000L / encodeTime) + ", decodeRate=" + (decIter * 1000L / decodeTime));
req.close();
}
use of org.apache.solr.client.solrj.impl.BinaryResponseParser in project lucene-solr by apache.
the class TestRawResponseWriter method testStructuredDataViaBaseWriters.
/**
* When no real ContentStream is specified, each base writer should be used for formatting
*/
public void testStructuredDataViaBaseWriters() throws IOException {
SolrQueryResponse rsp = new SolrQueryResponse();
// Don't send a ContentStream back, this will fall back to the configured base writer.
// But abuse the CONTENT key to ensure writer is also checking type
rsp.add(RawResponseWriter.CONTENT, "test");
rsp.add("foo", "bar");
// check Content-Type against each writer
assertEquals("application/xml; charset=UTF-8", writerNoBase.getContentType(req(), rsp));
assertEquals("application/xml; charset=UTF-8", writerXmlBase.getContentType(req(), rsp));
assertEquals("application/json; charset=UTF-8", writerJsonBase.getContentType(req(), rsp));
assertEquals("application/octet-stream", writerBinBase.getContentType(req(), rsp));
// check response against each writer
// xml & none (default behavior same as XML)
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n<str name=\"content\">test</str><str name=\"foo\">bar</str>\n</response>\n";
StringWriter xmlSout = new StringWriter();
writerXmlBase.write(xmlSout, req(), rsp);
assertEquals(xml, xmlSout.toString());
ByteArrayOutputStream xmlBout = new ByteArrayOutputStream();
writerXmlBase.write(xmlBout, req(), rsp);
assertEquals(xml, xmlBout.toString(StandardCharsets.UTF_8.toString()));
//
StringWriter noneSout = new StringWriter();
writerNoBase.write(noneSout, req(), rsp);
assertEquals(xml, noneSout.toString());
ByteArrayOutputStream noneBout = new ByteArrayOutputStream();
writerNoBase.write(noneBout, req(), rsp);
assertEquals(xml, noneBout.toString(StandardCharsets.UTF_8.toString()));
// json
String json = "{\"content\":\"test\",\"foo\":\"bar\"}\n";
StringWriter jsonSout = new StringWriter();
writerJsonBase.write(jsonSout, req(), rsp);
assertEquals(json, jsonSout.toString());
ByteArrayOutputStream jsonBout = new ByteArrayOutputStream();
writerJsonBase.write(jsonBout, req(), rsp);
assertEquals(json, jsonBout.toString(StandardCharsets.UTF_8.toString()));
// javabin
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
writerBinBase.write(bytes, req(), rsp);
BinaryResponseParser parser = new BinaryResponseParser();
NamedList<Object> out = parser.processResponse(new ByteArrayInputStream(bytes.toByteArray()), /* encoding irrelevant */
null);
assertEquals(RawResponseWriter.CONTENT, out.getName(0));
assertEquals("test", out.getVal(0));
assertEquals("foo", out.getName(1));
assertEquals("bar", out.getVal(1));
}
use of org.apache.solr.client.solrj.impl.BinaryResponseParser in project lucene-solr by apache.
the class DistributedQueryElevationComponentTest method test.
@Test
@ShardsFixed(num = 3)
public void test() throws Exception {
del("*:*");
indexr(id, "1", "int_i", "1", "text", "XXXX XXXX", "field_t", "anything");
indexr(id, "2", "int_i", "2", "text", "YYYY YYYY", "plow_t", "rake");
indexr(id, "3", "int_i", "3", "text", "ZZZZ ZZZZ");
indexr(id, "4", "int_i", "4", "text", "XXXX XXXX");
indexr(id, "5", "int_i", "5", "text", "ZZZZ ZZZZ ZZZZ");
indexr(id, "6", "int_i", "6", "text", "ZZZZ");
index_specific(2, id, "7", "int_i", "7", "text", "solr");
commit();
handle.put("explain", SKIPVAL);
handle.put("debug", SKIPVAL);
handle.put("maxScore", SKIPVAL);
handle.put("timestamp", SKIPVAL);
handle.put("score", SKIPVAL);
handle.put("wt", SKIP);
handle.put("distrib", SKIP);
handle.put("shards.qt", SKIP);
handle.put("shards", SKIP);
handle.put("q", SKIP);
handle.put("qt", SKIP);
query("q", "*:*", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", "sort", "id desc", CommonParams.FL, "id, score, [elevated]");
query("q", "ZZZZ", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "int_i desc");
query("q", "solr", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "int_i asc");
query("q", "ZZZZ", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "id desc");
// See SOLR-4854 for background on following test code
// Uses XML response format by default
QueryResponse response = query("q", "XXXX", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "id, [elevated]", "enableElevation", "true", "forceElevation", "true", "elevateIds", "6", "sort", "id desc");
assertTrue(response.getResults().getNumFound() > 0);
SolrDocument document = response.getResults().get(0);
assertEquals(6.0f, document.getFieldValue("id"));
assertEquals(true, document.getFieldValue("[elevated]"));
// Force javabin format
final String clientUrl = ((HttpSolrClient) clients.get(0)).getBaseURL();
HttpSolrClient client = getHttpSolrClient(clientUrl);
client.setParser(new BinaryResponseParser());
SolrQuery solrQuery = new SolrQuery("XXXX").setParam("qt", "/elevate").setParam("shards.qt", "/elevate").setRows(500).setFields("id,[elevated]").setParam("enableElevation", "true").setParam("forceElevation", "true").setParam("elevateIds", "6", "wt", "javabin").setSort("id", SolrQuery.ORDER.desc);
setDistributedParams(solrQuery);
response = client.query(solrQuery);
client.close();
assertTrue(response.getResults().getNumFound() > 0);
document = response.getResults().get(0);
assertEquals(6.0f, document.getFieldValue("id"));
assertEquals(true, document.getFieldValue("[elevated]"));
}
use of org.apache.solr.client.solrj.impl.BinaryResponseParser in project lucene-solr by apache.
the class SolrExampleTests method testRealtimeGet.
@Test
public void testRealtimeGet() throws Exception {
SolrClient client = getSolrClient();
// Empty the database...
// delete everything!
client.deleteByQuery("*:*");
// Now add something...
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "DOCID");
doc.addField("name", "hello");
client.add(doc);
// Since the transaction log is disabled in the example, we need to commit
client.commit();
SolrQuery q = new SolrQuery();
q.setRequestHandler("/get");
q.set("id", "DOCID");
q.set("fl", "id,name,aaa:[value v=aaa]");
// First Try with the BinaryResponseParser
QueryRequest req = new QueryRequest(q);
req.setResponseParser(new BinaryResponseParser());
QueryResponse rsp = req.process(client);
SolrDocument out = (SolrDocument) rsp.getResponse().get("doc");
assertEquals("DOCID", out.get("id"));
assertEquals("hello", out.get("name"));
assertEquals("aaa", out.get("aaa"));
// Then with the XMLResponseParser
req.setResponseParser(new XMLResponseParser());
rsp = req.process(client);
out = (SolrDocument) rsp.getResponse().get("doc");
assertEquals("DOCID", out.get("id"));
assertEquals("hello", out.get("name"));
assertEquals("aaa", out.get("aaa"));
}
Aggregations