Search in sources :

Example 51 with QueryResponse

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

the class TestTolerantUpdateProcessorRandomCloud method allDocs.

/** uses a Cursor to iterate over every doc in the index, recording the 'id_i' value in a BitSet */
private static final BitSet allDocs(final SolrClient c, final int maxDocIdExpected) throws Exception {
    BitSet docs = new BitSet(maxDocIdExpected + 1);
    String cursorMark = CURSOR_MARK_START;
    int docsOnThisPage = Integer.MAX_VALUE;
    while (0 < docsOnThisPage) {
        final SolrParams p = params("q", "*:*", "rows", "100", // note: not numeric, but we don't actual care about the order
        "sort", "id asc", CURSOR_MARK_PARAM, cursorMark);
        QueryResponse rsp = c.query(p);
        cursorMark = rsp.getNextCursorMark();
        docsOnThisPage = 0;
        for (SolrDocument doc : rsp.getResults()) {
            docsOnThisPage++;
            int id_i = ((Integer) doc.get("id_i")).intValue();
            assertTrue("found id_i bigger then expected " + maxDocIdExpected + ": " + id_i, id_i <= maxDocIdExpected);
            docs.set(id_i);
        }
        cursorMark = rsp.getNextCursorMark();
    }
    return docs;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) BitSet(java.util.BitSet) SolrParams(org.apache.solr.common.params.SolrParams)

Example 52 with QueryResponse

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

the class TriLevelCompositeIdRoutingTest method doQueryGetUniqueIdKeys.

Set<String> doQueryGetUniqueIdKeys(String... queryParams) throws Exception {
    QueryResponse rsp = cloudClient.query(params(queryParams));
    Set<String> obtainedIdKeys = new HashSet<>();
    for (SolrDocument doc : rsp.getResults()) {
        obtainedIdKeys.add(getKey((String) doc.get("id")));
    }
    return obtainedIdKeys;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) HashSet(java.util.HashSet)

Example 53 with QueryResponse

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

the class TestReplicationHandler method getSlaveDetails.

private String getSlaveDetails(String keyName) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.QT, "/replication");
    params.set("command", "details");
    QueryResponse response = slaveClient.query(params);
    System.out.println("SHALIN: " + response.getResponse());
    // details/slave/timesIndexReplicated
    NamedList<Object> details = (NamedList<Object>) response.getResponse().get("details");
    NamedList<Object> slave = (NamedList<Object>) details.get("slave");
    Object o = slave.get(keyName);
    return o != null ? o.toString() : null;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 54 with QueryResponse

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

the class TestReplicationHandler method query.

NamedList query(String query, SolrClient s) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", query);
    params.add("sort", "id desc");
    QueryResponse qres = s.query(params);
    return qres.getResponse();
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 55 with QueryResponse

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

the class MergeStrategyTest method test.

@Test
@ShardsFixed(num = 3)
public void test() throws Exception {
    del("*:*");
    index_specific(0, "id", "1", "sort_i", "5");
    index_specific(0, "id", "2", "sort_i", "50");
    index_specific(1, "id", "5", "sort_i", "4");
    index_specific(1, "id", "6", "sort_i", "10");
    index_specific(0, "id", "7", "sort_i", "1");
    index_specific(1, "id", "8", "sort_i", "2");
    index_specific(2, "id", "9", "sort_i", "1000");
    index_specific(2, "id", "10", "sort_i", "1500");
    index_specific(2, "id", "11", "sort_i", "1300");
    index_specific(1, "id", "12", "sort_i", "15");
    index_specific(1, "id", "13", "sort_i", "16");
    commit();
    handle.put("explain", SKIPVAL);
    handle.put("timestamp", SKIPVAL);
    handle.put("score", SKIPVAL);
    handle.put("wt", SKIP);
    handle.put("distrib", SKIP);
    handle.put("shards.qt", SKIP);
    handle.put("shards", SKIP);
    handle.put("q", SKIP);
    handle.put("maxScore", SKIPVAL);
    handle.put("_version_", SKIP);
    //Test mergeStrategy that uses score
    query("rq", "{!rank}", "q", "*:*", "rows", "12", "sort", "sort_i asc", "fl", "*,score");
    //Test without mergeStrategy
    query("q", "*:*", "rows", "12", "sort", "sort_i asc");
    //Test mergeStrategy1 that uses a sort field.
    query("rq", "{!rank mergeStrategy=1}", "q", "*:*", "rows", "12", "sort", "sort_i asc");
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("rows", "12");
    params.add("rq", "{!rank}");
    params.add("sort", "sort_i asc");
    params.add("fl", "*,score");
    setDistributedParams(params);
    QueryResponse rsp = queryServer(params);
    assertOrder(rsp, "10", "11", "9", "2", "13", "12", "6", "1", "5", "8", "7");
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("rows", "12");
    params.add("sort", "sort_i asc");
    params.add("fl", "*,score");
    setDistributedParams(params);
    rsp = queryServer(params);
    assertOrder(rsp, "7", "8", "5", "1", "6", "12", "13", "2", "9", "11", "10");
    MergeStrategy m1 = new MergeStrategy() {

        @Override
        public void merge(ResponseBuilder rb, ShardRequest sreq) {
        }

        public boolean mergesIds() {
            return true;
        }

        public boolean handlesMergeFields() {
            return false;
        }

        public void handleMergeFields(ResponseBuilder rb, SolrIndexSearcher searcher) {
        }

        @Override
        public int getCost() {
            return 1;
        }
    };
    MergeStrategy m2 = new MergeStrategy() {

        @Override
        public void merge(ResponseBuilder rb, ShardRequest sreq) {
        }

        public boolean mergesIds() {
            return true;
        }

        public boolean handlesMergeFields() {
            return false;
        }

        public void handleMergeFields(ResponseBuilder rb, SolrIndexSearcher searcher) {
        }

        @Override
        public int getCost() {
            return 100;
        }
    };
    MergeStrategy m3 = new MergeStrategy() {

        @Override
        public void merge(ResponseBuilder rb, ShardRequest sreq) {
        }

        public boolean mergesIds() {
            return false;
        }

        public boolean handlesMergeFields() {
            return false;
        }

        public void handleMergeFields(ResponseBuilder rb, SolrIndexSearcher searcher) {
        }

        @Override
        public int getCost() {
            return 50;
        }
    };
    MergeStrategy[] merges = { m1, m2, m3 };
    Arrays.sort(merges, MergeStrategy.MERGE_COMP);
    assert (merges[0].getCost() == 1);
    assert (merges[1].getCost() == 50);
    assert (merges[2].getCost() == 100);
}
Also used : MergeStrategy(org.apache.solr.handler.component.MergeStrategy) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ShardRequest(org.apache.solr.handler.component.ShardRequest) ResponseBuilder(org.apache.solr.handler.component.ResponseBuilder) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

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