use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class BasicFunctionalityTest method testLocalSolrQueryRequestParams.
@Test
public void testLocalSolrQueryRequestParams() {
HashMap args = new HashMap();
args.put("string", "string value");
args.put("array", new String[] { "array", "value" });
SolrQueryRequest req = new LocalSolrQueryRequest(null, null, null, 0, 20, args);
assertEquals("string value", req.getParams().get("string"));
assertEquals("array", req.getParams().get("array"));
String[] stringParams = req.getParams().getParams("string");
assertEquals(1, stringParams.length);
assertEquals("string value", stringParams[0]);
String[] arrayParams = req.getParams().getParams("array");
assertEquals(2, arrayParams.length);
assertEquals("array", arrayParams[0]);
assertEquals("value", arrayParams[1]);
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class SmileWriterTest method testJSON.
@Test
public void testJSON() throws IOException {
SolrQueryRequest req = req("wt", "json", "json.nl", "arrarr");
SolrQueryResponse rsp = new SolrQueryResponse();
SmileResponseWriter w = new SmileResponseWriter();
ByteArrayOutputStream buf = new ByteArrayOutputStream();
NamedList nl = new NamedList();
// make sure that 2028 and 2029 are both escaped (they are illegal in javascript)
nl.add("data1", "he
llo
!");
nl.add(null, 42);
rsp.add("nl", nl);
rsp.add("byte", Byte.valueOf((byte) -3));
rsp.add("short", Short.valueOf((short) -4));
String expected = "{\"nl\":[[\"data1\",\"he\\u2028llo\\u2029!\"],[null,42]],byte:-3,short:-4}";
w.write(buf, req, rsp);
Map m = (Map) decodeSmile(new ByteArrayInputStream(buf.toByteArray()));
Map o2 = (Map) new ObjectBuilder(new JSONParser(new StringReader(expected))).getObject();
assertEquals(Utils.toJSONString(m), Utils.toJSONString(o2));
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestSubQueryTransformer method testExceptionPropagation.
@Test
public void testExceptionPropagation() throws Exception {
final SolrQueryRequest r = req("q", "name_s:dave", "indent", "true", "fl", "depts:[subquery]", "rows", "" + (peopleMultiplier), "depts.q", "{!lucene}(", "depts.fl", "text_t", "depts.indent", "true", "depts.rows", "" + (deptMultiplier * 2), "depts.logParamsList", "q,fl,rows,subq1.row.dept_ss_dv");
// System.out.println(h.query(r));
assertQEx("wrong subquery", r, ErrorCode.BAD_REQUEST);
assertQEx("", req("q", "name_s:dave", "indent", "true", "fl", "depts:[subquery]", "rows", "1", "depts.q", "{!lucene}", "depts.fl", "text_t", "depts.indent", "true", "depts.rows", "NAN", "depts.logParamsList", "q,fl,rows,subq1.row.dept_ss_dv"), ErrorCode.BAD_REQUEST);
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestPHPSerializedResponseWriter method testSolrDocuments.
@Test
public void testSolrDocuments() throws IOException {
SolrQueryRequest req = req("q", "*:*");
SolrQueryResponse rsp = new SolrQueryResponse();
QueryResponseWriter w = new PHPSerializedResponseWriter();
StringWriter buf = new StringWriter();
SolrDocument d = new SolrDocument();
SolrDocument d1 = d;
d.addField("id", "1");
d.addField("data1", "hello");
d.addField("data2", 42);
d.addField("data3", true);
// multivalued fields:
// extremely odd edge case: value is a map
// we use LinkedHashMap because we are doing a string comparison
// later and we need predictible ordering
LinkedHashMap<String, String> nl = new LinkedHashMap<>();
nl.put("data4.1", "hashmap");
nl.put("data4.2", "hello");
d.addField("data4", nl);
// array value
d.addField("data5", Arrays.asList("data5.1", "data5.2", "data5.3"));
// adding one more document to test array indexes
d = new SolrDocument();
SolrDocument d2 = d;
d.addField("id", "2");
SolrDocumentList sdl = new SolrDocumentList();
sdl.add(d1);
sdl.add(d2);
rsp.addResponse(sdl);
w.write(buf, req, rsp);
assertEquals("a:1:{s:8:\"response\";a:3:{s:8:\"numFound\";i:0;s:5:\"start\";i:0;s:4:\"docs\";a:2:{i:0;a:6:{s:2:\"id\";s:1:\"1\";s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;s:5:\"data4\";a:2:{s:7:\"data4.1\";s:7:\"hashmap\";s:7:\"data4.2\";s:5:\"hello\";}s:5:\"data5\";a:3:{i:0;s:7:\"data5.1\";i:1;s:7:\"data5.2\";i:2;s:7:\"data5.3\";}}i:1;a:1:{s:2:\"id\";s:1:\"2\";}}}}", buf.toString());
req.close();
}
use of org.apache.solr.request.SolrQueryRequest 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']");
}
Aggregations