Search in sources :

Example 46 with QueryResponse

use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.

the class FullSolrCloudDistribCmdsTest method testOptimisticUpdate.

private void testOptimisticUpdate(QueryResponse results) throws Exception {
    SolrDocument doc = results.getResults().get(0);
    Long version = (Long) doc.getFieldValue(VERSION_FIELD);
    Integer theDoc = (Integer) doc.getFieldValue("id");
    UpdateRequest uReq = new UpdateRequest();
    SolrInputDocument doc1 = new SolrInputDocument();
    uReq.setParams(new ModifiableSolrParams());
    uReq.getParams().set(VERSION_FIELD, Long.toString(version));
    addFields(doc1, "id", theDoc, t1, "theupdatestuff");
    uReq.add(doc1);
    uReq.process(cloudClient);
    uReq.process(controlClient);
    commit();
    // updating the old version should fail...
    SolrInputDocument doc2 = new SolrInputDocument();
    uReq = new UpdateRequest();
    uReq.setParams(new ModifiableSolrParams());
    uReq.getParams().set(VERSION_FIELD, Long.toString(version));
    addFields(doc2, "id", theDoc, t1, "thenewupdatestuff");
    uReq.add(doc2);
    uReq.process(cloudClient);
    uReq.process(controlClient);
    commit();
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", t1 + ":thenewupdatestuff");
    QueryResponse res = clients.get(0).query(params);
    assertEquals(0, res.getResults().getNumFound());
    params = new ModifiableSolrParams();
    params.add("q", t1 + ":theupdatestuff");
    res = clients.get(0).query(params);
    assertEquals(1, res.getResults().getNumFound());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 47 with QueryResponse

use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.

the class FullSolrCloudDistribCmdsTest method testConcurrentIndexing.

private long testConcurrentIndexing(long docId) throws Exception {
    QueryResponse results = query(cloudClient);
    long beforeCount = results.getResults().getNumFound();
    int cnt = TEST_NIGHTLY ? 2933 : 313;
    try (ConcurrentUpdateSolrClient concurrentClient = getConcurrentUpdateSolrClient(((HttpSolrClient) clients.get(0)).getBaseURL(), 10, 2)) {
        concurrentClient.setConnectionTimeout(120000);
        for (int i = 0; i < cnt; i++) {
            index_specific(concurrentClient, id, docId++, "text_t", "some text so that it not's negligent work to parse this doc, even though it's still a pretty short doc");
        }
        concurrentClient.blockUntilFinished();
        commit();
        checkShardConsistency();
        assertDocCounts(VERBOSE);
    }
    results = query(cloudClient);
    assertEquals(beforeCount + cnt, results.getResults().getNumFound());
    return docId;
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)

Example 48 with QueryResponse

use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.

the class SegmentTerminateEarlyTestState method queryTimestampAscendingSegmentTerminateEarlyYes.

void queryTimestampAscendingSegmentTerminateEarlyYes(CloudSolrClient cloudSolrClient) throws Exception {
    TestMiniSolrCloudCluster.assertFalse(minTimestampDocKeys.isEmpty());
    TestMiniSolrCloudCluster.assertTrue("numDocs=" + numDocs + " is not even", (numDocs % 2) == 0);
    final Long oddFieldValue = new Long(minTimestampDocKeys.iterator().next().intValue() % 2);
    final SolrQuery query = new SolrQuery(ODD_FIELD + ":" + oddFieldValue);
    // a sort order that is _not_ compatible with the merge sort order
    query.setSort(TIMESTAMP_FIELD, SolrQuery.ORDER.asc);
    query.setFields(KEY_FIELD, ODD_FIELD, TIMESTAMP_FIELD);
    query.setRows(1);
    query.set(CommonParams.SEGMENT_TERMINATE_EARLY, true);
    final QueryResponse rsp = cloudSolrClient.query(query);
    // check correctness of the results count
    TestMiniSolrCloudCluster.assertEquals("numFound", numDocs / 2, rsp.getResults().getNumFound());
    // check correctness of the first result
    if (rsp.getResults().getNumFound() > 0) {
        final SolrDocument solrDocument0 = rsp.getResults().get(0);
        TestMiniSolrCloudCluster.assertTrue(KEY_FIELD + " of (" + solrDocument0 + ") is not in minTimestampDocKeys(" + minTimestampDocKeys + ")", minTimestampDocKeys.contains(solrDocument0.getFieldValue(KEY_FIELD)));
        TestMiniSolrCloudCluster.assertEquals(ODD_FIELD, oddFieldValue, solrDocument0.getFieldValue(ODD_FIELD));
    }
    // check segmentTerminatedEarly flag
    TestMiniSolrCloudCluster.assertNotNull("responseHeader.segmentTerminatedEarly missing in " + rsp.getResponseHeader(), rsp.getResponseHeader().get(SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY));
    // segmentTerminateEarly cannot be used with incompatible sort orders
    TestMiniSolrCloudCluster.assertTrue("responseHeader.segmentTerminatedEarly missing/true in " + rsp.getResponseHeader(), Boolean.FALSE.equals(rsp.getResponseHeader().get(SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY)));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 49 with QueryResponse

use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.

the class SegmentTerminateEarlyTestState method queryTimestampDescending.

void queryTimestampDescending(CloudSolrClient cloudSolrClient) throws Exception {
    TestMiniSolrCloudCluster.assertFalse(maxTimestampDocKeys.isEmpty());
    TestMiniSolrCloudCluster.assertTrue("numDocs=" + numDocs + " is not even", (numDocs % 2) == 0);
    final Long oddFieldValue = new Long(maxTimestampDocKeys.iterator().next().intValue() % 2);
    final SolrQuery query = new SolrQuery(ODD_FIELD + ":" + oddFieldValue);
    query.setSort(TIMESTAMP_FIELD, SolrQuery.ORDER.desc);
    query.setFields(KEY_FIELD, ODD_FIELD, TIMESTAMP_FIELD);
    query.setRows(1);
    // CommonParams.SEGMENT_TERMINATE_EARLY parameter intentionally absent
    final QueryResponse rsp = cloudSolrClient.query(query);
    // check correctness of the results count
    TestMiniSolrCloudCluster.assertEquals("numFound", numDocs / 2, rsp.getResults().getNumFound());
    // check correctness of the first result
    if (rsp.getResults().getNumFound() > 0) {
        final SolrDocument solrDocument0 = rsp.getResults().get(0);
        TestMiniSolrCloudCluster.assertTrue(KEY_FIELD + " of (" + solrDocument0 + ") is not in maxTimestampDocKeys(" + maxTimestampDocKeys + ")", maxTimestampDocKeys.contains(solrDocument0.getFieldValue(KEY_FIELD)));
        TestMiniSolrCloudCluster.assertEquals(ODD_FIELD, oddFieldValue, solrDocument0.getFieldValue(ODD_FIELD));
    }
    // check segmentTerminatedEarly flag
    TestMiniSolrCloudCluster.assertNull("responseHeader.segmentTerminatedEarly present in " + rsp.getResponseHeader(), rsp.getResponseHeader().get(SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 50 with QueryResponse

use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.

the class ShardRoutingTest method doAtomicUpdate.

public void doAtomicUpdate() throws Exception {
    log.info("### STARTING doAtomicUpdate");
    int nClients = clients.size();
    assertEquals(8, nClients);
    int expectedVal = 0;
    for (SolrClient client : clients) {
        client.add(sdoc("id", "b!doc", "foo_i", map("inc", 1)));
        expectedVal++;
        QueryResponse rsp = client.query(params("qt", "/get", "id", "b!doc"));
        Object val = ((Map) rsp.getResponse().get("doc")).get("foo_i");
        assertEquals((Integer) expectedVal, val);
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Map(java.util.Map)

Aggregations

QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)293 SolrQuery (org.apache.solr.client.solrj.SolrQuery)129 Test (org.junit.Test)111 SolrDocument (org.apache.solr.common.SolrDocument)81 SolrInputDocument (org.apache.solr.common.SolrInputDocument)67 SolrDocumentList (org.apache.solr.common.SolrDocumentList)61 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)58 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)56 SolrServerException (org.apache.solr.client.solrj.SolrServerException)47 ArrayList (java.util.ArrayList)41 IOException (java.io.IOException)39 NamedList (org.apache.solr.common.util.NamedList)32 SolrParams (org.apache.solr.common.params.SolrParams)28 SolrClient (org.apache.solr.client.solrj.SolrClient)27 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)27 ErrorTrackingConcurrentUpdateSolrClient (org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient)25 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)25 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)23 HashMap (java.util.HashMap)22 List (java.util.List)20