Search in sources :

Example 86 with SolrDocumentList

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;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Taxon(org.opensextant.data.Taxon) ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 87 with SolrDocumentList

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) SolrReturnFields(org.apache.solr.search.SolrReturnFields) ReturnFields(org.apache.solr.search.ReturnFields) StringWriter(java.io.StringWriter) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrReturnFields(org.apache.solr.search.SolrReturnFields) Test(org.junit.Test)

Example 88 with SolrDocumentList

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) SolrReturnFields(org.apache.solr.search.SolrReturnFields) ReturnFields(org.apache.solr.search.ReturnFields) ByteArrayInputStream(java.io.ByteArrayInputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SolrReturnFields(org.apache.solr.search.SolrReturnFields) Test(org.junit.Test)

Example 89 with SolrDocumentList

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);
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 90 with SolrDocumentList

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));
                }
            }
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) BinaryQueryResponseWriter(org.apache.solr.response.BinaryQueryResponseWriter) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SolrDocumentList (org.apache.solr.common.SolrDocumentList)161 SolrDocument (org.apache.solr.common.SolrDocument)89 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)52 Test (org.junit.Test)52 NamedList (org.apache.solr.common.util.NamedList)36 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)33 SolrQuery (org.apache.solr.client.solrj.SolrQuery)32 ArrayList (java.util.ArrayList)29 SolrParams (org.apache.solr.common.params.SolrParams)28 SolrServerException (org.apache.solr.client.solrj.SolrServerException)20 SolrInputDocument (org.apache.solr.common.SolrInputDocument)18 IOException (java.io.IOException)15 Map (java.util.Map)14 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)14 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)13 HashMap (java.util.HashMap)12 List (java.util.List)10 Date (java.util.Date)8 LinkedHashMap (java.util.LinkedHashMap)8 SolrClient (org.apache.solr.client.solrj.SolrClient)8