Search in sources :

Example 71 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.

the class TestBinaryResponseWriter method testUUID.

/**
   * Tests known types implementation by asserting correct encoding/decoding of UUIDField
   */
public void testUUID() throws Exception {
    String s = UUID.randomUUID().toString().toLowerCase(Locale.ROOT);
    assertU(adoc("id", "101", "uuid", s));
    assertU(commit());
    LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*");
    SolrQueryResponse rsp = h.queryAndResponse(req.getParams().get(CommonParams.QT), req);
    BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter) h.getCore().getQueryResponseWriter("javabin");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    writer.write(baos, req, rsp);
    NamedList res = (NamedList) new JavaBinCodec().unmarshal(new ByteArrayInputStream(baos.toByteArray()));
    SolrDocumentList docs = (SolrDocumentList) res.get("response");
    for (Object doc : docs) {
        SolrDocument document = (SolrDocument) doc;
        assertEquals("Returned object must be a string", "java.lang.String", document.getFieldValue("uuid").getClass().getName());
        assertEquals("Wrong UUID string returned", s, document.getFieldValue("uuid"));
    }
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) NamedList(org.apache.solr.common.util.NamedList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SolrDocumentList(org.apache.solr.common.SolrDocumentList) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec)

Example 72 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.

the class TestJavabinTupleStreamParser method testSolrDocumentList.

public void testSolrDocumentList() throws IOException {
    SolrQueryResponse response = new SolrQueryResponse();
    SolrDocumentList l = constructSolrDocList(response);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new JavaBinCodec().marshal(response.getValues(), baos);
    byte[] bytes = serialize(response.getValues());
    Object o = new JavaBinCodec().unmarshal(new ByteArrayInputStream(bytes));
    List list = new ArrayList<>();
    Map m = null;
    JavabinTupleStreamParser parser = new JavabinTupleStreamParser(new ByteArrayInputStream(bytes), false);
    while ((m = parser.next()) != null) {
        list.add(m);
    }
    assertEquals(l.size(), list.size());
    for (int i = 0; i < list.size(); i++) {
        compareSolrDocument(l.get(i), new SolrDocument((Map<String, Object>) list.get(i)));
    }
}
Also used : ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec) SolrDocument(org.apache.solr.common.SolrDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) SmileWriterTest.constructSolrDocList(org.apache.solr.response.SmileWriterTest.constructSolrDocList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) JavabinTupleStreamParser(org.apache.solr.client.solrj.io.stream.JavabinTupleStreamParser)

Example 73 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList in project jackrabbit-oak by apache.

the class LMSEstimatorTest method testMultipleUpdates.

@Test
public void testMultipleUpdates() throws Exception {
    LMSEstimator lmsEstimator = new LMSEstimator();
    Filter filter = mock(Filter.class);
    FullTextExpression fte = new FullTextTerm("foo", "bar", false, false, "");
    when(filter.getFullTextConstraint()).thenReturn(fte);
    SolrDocumentList docs = new SolrDocumentList();
    lmsEstimator.update(filter, docs);
    long actualCount = 10;
    docs.setNumFound(actualCount);
    long estimate = lmsEstimator.estimate(filter);
    long diff = actualCount - estimate;
    // update causes weights adjustment
    lmsEstimator.update(filter, docs);
    long estimate2 = lmsEstimator.estimate(filter);
    long diff2 = actualCount - estimate2;
    // new estimate is more accurate than previous one
    assertTrue(diff2 < diff);
    // update doesn't cause weight adjustments therefore estimates stays unchanged
    lmsEstimator.update(filter, docs);
    long estimate3 = lmsEstimator.estimate(filter);
    assertEquals(estimate3, estimate2);
}
Also used : FullTextTerm(org.apache.jackrabbit.oak.query.fulltext.FullTextTerm) Filter(org.apache.jackrabbit.oak.spi.query.Filter) FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Test(org.junit.Test)

Example 74 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList in project jackrabbit-oak by apache.

the class LMSEstimatorTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    LMSEstimator lmsEstimator = new LMSEstimator();
    Filter filter = mock(Filter.class);
    SolrDocumentList docs = mock(SolrDocumentList.class);
    lmsEstimator.update(filter, docs);
}
Also used : Filter(org.apache.jackrabbit.oak.spi.query.Filter) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Test(org.junit.Test)

Example 75 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList in project play-cookbook by spinscale.

the class SolrSearchTest method simpleUserTest.

@Test
public void simpleUserTest() throws Exception {
    SolrQuery query = new SolrQuery();
    query.setQuery("name:alex");
    QueryResponse rp = server.query(query);
    SolrDocumentList results = rp.getResults();
    assertEquals(1, results.size());
    assertEquals("alex", results.get(0).getFieldValue("name"));
    User u = User.find("byName", "alex").first();
    assertEquals(u.getClass().getName() + ":" + u.id.toString(), results.get(0).getFieldValue("id"));
}
Also used : User(models.User) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UnitTest(play.test.UnitTest) 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