Search in sources :

Example 91 with SolrDocument

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

the class TestTlogReplica method testOutOfOrderDBQWithInPlaceUpdates.

public void testOutOfOrderDBQWithInPlaceUpdates() throws Exception {
    createAndWaitForCollection(1, 0, 2, 0);
    assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").indexed());
    assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").stored());
    assertTrue(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").hasDocValues());
    List<UpdateRequest> updates = new ArrayList<>();
    // full update
    updates.add(simulatedUpdateRequest(null, "id", 1, "title_s", "title0_new", "inplace_updatable_int", 5, "_version_", 1L));
    updates.add(simulatedDBQ("inplace_updatable_int:5", 3L));
    updates.add(simulatedUpdateRequest(1L, "id", 1, "inplace_updatable_int", 6, "_version_", 2L));
    for (JettySolrRunner solrRunner : getSolrRunner(false)) {
        try (SolrClient client = solrRunner.newClient()) {
            for (UpdateRequest up : updates) {
                up.process(client, collectionName);
            }
        }
    }
    JettySolrRunner oldLeaderJetty = getSolrRunner(true).get(0);
    ChaosMonkey.kill(oldLeaderJetty);
    waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
    ChaosMonkey.start(oldLeaderJetty);
    waitForState("Replica not added", collectionName, activeReplicaCount(0, 2, 0));
    checkRTG(1, 1, cluster.getJettySolrRunners());
    SolrDocument doc = cluster.getSolrClient().getById(collectionName, "1");
    assertNotNull(doc.get("title_s"));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ArrayList(java.util.ArrayList)

Example 92 with SolrDocument

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

the class TopicStream method getPersistedCheckpoints.

private void getPersistedCheckpoints() throws IOException {
    ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
    Collection<Slice> slices = CloudSolrStream.getSlices(checkpointCollection, zkStateReader, false);
    ClusterState clusterState = zkStateReader.getClusterState();
    Set<String> liveNodes = clusterState.getLiveNodes();
    OUTER: for (Slice slice : slices) {
        Collection<Replica> replicas = slice.getReplicas();
        for (Replica replica : replicas) {
            if (replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) {
                HttpSolrClient httpClient = streamContext.getSolrClientCache().getHttpSolrClient(replica.getCoreUrl());
                try {
                    SolrDocument doc = httpClient.getById(id);
                    if (doc != null) {
                        List<String> checkpoints = (List<String>) doc.getFieldValue("checkpoint_ss");
                        for (String checkpoint : checkpoints) {
                            String[] pair = checkpoint.split("~");
                            this.checkpoints.put(pair[0], Long.parseLong(pair[1]));
                        }
                    }
                } catch (Exception e) {
                    throw new IOException(e);
                }
                break OUTER;
            }
        }
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) IOException(java.io.IOException) Replica(org.apache.solr.common.cloud.Replica) IOException(java.io.IOException) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrDocument(org.apache.solr.common.SolrDocument) Slice(org.apache.solr.common.cloud.Slice) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 93 with SolrDocument

use of org.apache.solr.common.SolrDocument 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 94 with SolrDocument

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

the class TestBinaryResponseWriter method testResolverSolrDocumentPartialFields.

public void testResolverSolrDocumentPartialFields() throws Exception {
    LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*", "fl", "id,xxx,ddd_s");
    SolrDocument in = new SolrDocument();
    in.addField("id", 345);
    in.addField("aaa_s", "aaa");
    in.addField("bbb_s", "bbb");
    in.addField("ccc_s", "ccc");
    in.addField("ddd_s", "ddd");
    in.addField("eee_s", "eee");
    Resolver r = new Resolver(req, new SolrReturnFields(req));
    Object o = r.resolve(in, new JavaBinCodec());
    assertNotNull("obj is null", o);
    assertTrue("obj is not doc", o instanceof SolrDocument);
    SolrDocument out = new SolrDocument();
    for (Map.Entry<String, Object> e : in) {
        if (r.isWritable(e.getKey()))
            out.put(e.getKey(), e.getValue());
    }
    assertTrue("id not found", out.getFieldNames().contains("id"));
    assertTrue("ddd_s not found", out.getFieldNames().contains("ddd_s"));
    assertEquals("Wrong number of fields found", 2, out.getFieldNames().size());
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) Resolver(org.apache.solr.response.BinaryResponseWriter.Resolver) Map(java.util.Map) SolrReturnFields(org.apache.solr.search.SolrReturnFields) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec)

Example 95 with SolrDocument

use of org.apache.solr.common.SolrDocument 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)

Aggregations

SolrDocument (org.apache.solr.common.SolrDocument)230 SolrDocumentList (org.apache.solr.common.SolrDocumentList)93 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)81 ArrayList (java.util.ArrayList)50 SolrQuery (org.apache.solr.client.solrj.SolrQuery)47 Test (org.junit.Test)46 SolrParams (org.apache.solr.common.params.SolrParams)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)35 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)35 IOException (java.io.IOException)32 SolrInputDocument (org.apache.solr.common.SolrInputDocument)28 HashMap (java.util.HashMap)26 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)24 NamedList (org.apache.solr.common.util.NamedList)21 Map (java.util.Map)20 List (java.util.List)18 SolrClient (org.apache.solr.client.solrj.SolrClient)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)12 SolrException (org.apache.solr.common.SolrException)12