use of org.apache.solr.common.SolrDocumentList in project Xponents by OpenSextant.
the class TaxonMatcher method search.
public static List<Taxon> search(SolrServer index, SolrParams qparams) throws SolrServerException {
QueryResponse response = index.query(qparams, SolrRequest.METHOD.GET);
List<Taxon> taxons = new ArrayList<>();
SolrDocumentList docList = response.getResults();
for (SolrDocument solrDoc : docList) {
taxons.add(createTaxon(solrDoc));
}
return taxons;
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class JSONWriterTest method testJSONSolrDocument.
@Test
public void testJSONSolrDocument() throws IOException {
SolrQueryRequest req = req(CommonParams.WT, "json", CommonParams.FL, "id,score");
SolrQueryResponse rsp = new SolrQueryResponse();
JSONResponseWriter w = new JSONResponseWriter();
ReturnFields returnFields = new SolrReturnFields(req);
rsp.setReturnFields(returnFields);
StringWriter buf = new StringWriter();
SolrDocument solrDoc = new SolrDocument();
solrDoc.addField("id", "1");
solrDoc.addField("subject", "hello2");
solrDoc.addField("title", "hello3");
solrDoc.addField("score", "0.7");
SolrDocumentList list = new SolrDocumentList();
list.setNumFound(1);
list.setStart(0);
list.setMaxScore(0.7f);
list.add(solrDoc);
rsp.addResponse(list);
w.write(buf, req, rsp);
String result = buf.toString();
assertFalse("response contains unexpected fields: " + result, result.contains("hello") || result.contains("\"subject\"") || result.contains("\"title\""));
assertTrue("response doesn't contain expected fields: " + result, result.contains("\"id\"") && result.contains("\"score\""));
req.close();
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class SmileWriterTest method testJSONSolrDocument.
@Test
public void testJSONSolrDocument() throws IOException {
SolrQueryRequest req = req(CommonParams.WT, "json", CommonParams.FL, "id,score");
SolrQueryResponse rsp = new SolrQueryResponse();
SmileResponseWriter w = new SmileResponseWriter();
ReturnFields returnFields = new SolrReturnFields(req);
rsp.setReturnFields(returnFields);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
SolrDocument solrDoc = new SolrDocument();
solrDoc.addField("id", "1");
solrDoc.addField("subject", "hello2");
solrDoc.addField("title", "hello3");
solrDoc.addField("score", "0.7");
SolrDocumentList list = new SolrDocumentList();
list.setNumFound(1);
list.setStart(0);
list.setMaxScore(0.7f);
list.add(solrDoc);
rsp.addResponse(list);
w.write(buf, req, rsp);
byte[] bytes = buf.toByteArray();
Map m = (Map) decodeSmile(new ByteArrayInputStream(bytes));
m = (Map) m.get("response");
List l = (List) m.get("docs");
Map doc = (Map) l.get(0);
assertFalse(doc.containsKey("subject"));
assertFalse(doc.containsKey("title"));
assertTrue(doc.containsKey("id"));
assertTrue(doc.containsKey("score"));
req.close();
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class SmileWriterTest method test10Docs.
@Test
public void test10Docs() throws IOException {
SolrQueryResponse response = new SolrQueryResponse();
SolrDocumentList l = constructSolrDocList(response);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new SmileResponseWriter().write(baos, new LocalSolrQueryRequest(null, new ModifiableSolrParams()), response);
byte[] bytes = baos.toByteArray();
Map m = (Map) decodeSmile(new ByteArrayInputStream(bytes, 0, bytes.length));
m = (Map) m.get("results");
List lst = (List) m.get("docs");
assertEquals(lst.size(), 10);
for (int i = 0; i < lst.size(); i++) {
m = (Map) lst.get(i);
SolrDocument d = new SolrDocument();
d.putAll(m);
compareSolrDocument(l.get(i), d);
}
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class TestSubQueryTransformer method testJustJohnJavabin.
@SuppressWarnings("unchecked")
@Test
public void testJustJohnJavabin() throws Exception {
final SolrQueryRequest johnTwoFL = req(johnAndNancyParams);
ModifiableSolrParams params = new ModifiableSolrParams(johnTwoFL.getParams());
params.set("q", "name_s:john");
params.set("wt", "javabin");
johnTwoFL.setParams(params);
final NamedList<Object> unmarshalled;
{
SolrCore core = johnTwoFL.getCore();
SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(johnTwoFL, rsp));
SolrQueryResponse response = h.queryAndResponse(johnTwoFL.getParams().get(CommonParams.QT), johnTwoFL);
BinaryQueryResponseWriter responseWriter = (BinaryQueryResponseWriter) core.getQueryResponseWriter(johnTwoFL);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
responseWriter.write(bytes, johnTwoFL, response);
unmarshalled = (NamedList<Object>) new JavaBinCodec().unmarshal(new ByteArrayInputStream(bytes.toByteArray()));
johnTwoFL.close();
SolrRequestInfo.clearRequestInfo();
}
SolrDocumentList resultDocs = (SolrDocumentList) (unmarshalled.get("response"));
{
Map<String, String> engText = new HashMap<>();
engText.put("text_t", "These guys develop stuff");
Map<String, String> engId = new HashMap<>();
engId.put("text_t", "These guys develop stuff");
engId.put("dept_id_s_dv", "Engineering");
for (int docNum : new int[] { 0, peopleMultiplier - 1 }) {
SolrDocument employeeDoc = resultDocs.get(docNum);
assertEquals("john", employeeDoc.getFieldValue("name_s_dv"));
for (String subResult : new String[] { "depts", "depts_i" }) {
SolrDocumentList subDoc = (SolrDocumentList) employeeDoc.getFieldValue(subResult);
for (int deptNum : new int[] { 0, deptMultiplier - 1 }) {
SolrDocument deptDoc = subDoc.get(deptNum);
Object expectedDept = (subResult.equals("depts") ? engText : engId);
assertTrue("" + expectedDept + " equals to " + deptDoc, expectedDept.equals(deptDoc));
}
}
}
}
}
Aggregations