Search in sources :

Example 31 with QueryResponse

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

the class TestDistributedSearch method queryRandomUpServer.

protected QueryResponse queryRandomUpServer(ModifiableSolrParams params, List<SolrClient> upClients) throws SolrServerException, IOException {
    // query a random "up" server
    int which = r.nextInt(upClients.size());
    SolrClient client = upClients.get(which);
    QueryResponse rsp = client.query(params);
    return rsp;
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse)

Example 32 with QueryResponse

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

the class TestDistributedSearch method queryPartialResults.

protected void queryPartialResults(final List<String> upShards, final List<SolrClient> upClients, Object... q) throws Exception {
    final ModifiableSolrParams params = new ModifiableSolrParams();
    for (int i = 0; i < q.length; i += 2) {
        params.add(q[i].toString(), q[i + 1].toString());
    }
    // TODO: look into why passing true causes fails
    params.set("distrib", "false");
    final QueryResponse controlRsp = controlClient.query(params);
    // if time.allowed is specified then even a control response can return a partialResults header
    if (params.get(CommonParams.TIME_ALLOWED) == null) {
        validateControlData(controlRsp);
    }
    params.remove("distrib");
    setDistributedParams(params);
    QueryResponse rsp = queryRandomUpServer(params, upClients);
    comparePartialResponses(rsp, controlRsp, upShards);
    if (stress > 0) {
        log.info("starting stress...");
        Thread[] threads = new Thread[nThreads];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread() {

                @Override
                public void run() {
                    for (int j = 0; j < stress; j++) {
                        int which = r.nextInt(upClients.size());
                        SolrClient client = upClients.get(which);
                        try {
                            QueryResponse rsp = client.query(new ModifiableSolrParams(params));
                            if (verifyStress) {
                                comparePartialResponses(rsp, controlRsp, upShards);
                            }
                        } catch (SolrServerException | IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            };
            threads[i].start();
        }
        for (Thread thread : threads) {
            thread.join();
        }
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 33 with QueryResponse

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

the class TestDistributedSearch method queryAndCompareUIF.

/** comparing results with facet.method=uif */
private void queryAndCompareUIF(Object... params) throws Exception {
    final QueryResponse expect = query(params);
    final Object[] newParams = Arrays.copyOf(params, params.length + 2);
    newParams[newParams.length - 2] = "facet.method";
    newParams[newParams.length - 1] = "uif";
    final QueryResponse uifResult = query(newParams);
    compareResponses(expect, uifResult);
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse)

Example 34 with QueryResponse

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

the class TestHighlightDedupGrouping method randomizedTest.

private void randomizedTest() throws Exception {
    del("*:*");
    commit();
    handle.clear();
    handle.put("timestamp", SKIPVAL);
    // distrib grouping doesn't guarantee order of top level group commands
    handle.put("grouped", UNORDERED);
    int numDocs = TestUtil.nextInt(random(), 100, 1000);
    int numGroups = TestUtil.nextInt(random(), 1, numDocs / 50);
    int[] docsInGroup = new int[numGroups + 1];
    int percentDuplicates = TestUtil.nextInt(random(), 1, 25);
    for (int docid = 0; docid < numDocs; ++docid) {
        int group = TestUtil.nextInt(random(), 1, numGroups);
        ++docsInGroup[group];
        boolean makeDuplicate = 0 == TestUtil.nextInt(random(), 0, numDocs / percentDuplicates);
        if (makeDuplicate) {
            for (int shard = 0; shard < getShardCount(); ++shard) {
                addDoc(docid, group, shard);
            }
        } else {
            int shard = TestUtil.nextInt(random(), 0, getShardCount() - 1);
            addDoc(docid, group, shard);
        }
    }
    for (int shard = 0; shard < getShardCount(); ++shard) {
        clients.get(shard).commit();
    }
    for (int group = 1; group <= numGroups; ++group) {
        QueryResponse rsp = queryServer(params("q", group_ti1 + ":" + group + " AND " + id_s1 + ":[* TO *]", "start", "0", "rows", "" + numDocs, "fl", id_s1 + "," + shard_i1, "sort", id_s1 + " asc", "shards", shards, "group", "true", "group.field", id_s1, "group.limit", "" + numDocs, "hl", "true", "hl.fl", "*", "hl.requireFieldMatch", "true"));
        // The number of highlit documents should be the same as the de-duplicated docs for this group
        assertEquals(docsInGroup[group], rsp.getHighlighting().values().size());
    }
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse)

Example 35 with QueryResponse

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

the class DistributedIntervalFacetingTest method testSolrJ.

private void testSolrJ() throws Exception {
    indexr("id", "0", "test_i_dv", "0", "test_s_dv", "AAA");
    indexr("id", "1", "test_i_dv", "1", "test_s_dv", "BBB");
    indexr("id", "2", "test_i_dv", "2", "test_s_dv", "AAA");
    indexr("id", "3", "test_i_dv", "3", "test_s_dv", "CCC");
    commit();
    QueryResponse response = controlClient.query(new SolrQuery("*:*"));
    assertEquals(4, response.getResults().getNumFound());
    SolrQuery q = new SolrQuery("*:*");
    String[] intervals = new String[] { "[0,1)", "[1,2)", "[2,3)", "[3,*)" };
    q.addIntervalFacets("test_i_dv", intervals);
    response = controlClient.query(q);
    assertEquals(1, response.getIntervalFacets().size());
    assertEquals("test_i_dv", response.getIntervalFacets().get(0).getField());
    assertEquals(4, response.getIntervalFacets().get(0).getIntervals().size());
    for (int i = 0; i < response.getIntervalFacets().get(0).getIntervals().size(); i++) {
        Count count = response.getIntervalFacets().get(0).getIntervals().get(i);
        assertEquals(intervals[i], count.getKey());
        assertEquals(1, count.getCount());
    }
    q = new SolrQuery("*:*");
    q.addIntervalFacets("test_i_dv", intervals);
    q.addIntervalFacets("test_s_dv", new String[] { "{!key='AAA'}[AAA,AAA]", "{!key='BBB'}[BBB,BBB]", "{!key='CCC'}[CCC,CCC]" });
    response = controlClient.query(q);
    assertEquals(2, response.getIntervalFacets().size());
    int stringIntervalIndex = "test_s_dv".equals(response.getIntervalFacets().get(0).getField()) ? 0 : 1;
    assertEquals("test_i_dv", response.getIntervalFacets().get(1 - stringIntervalIndex).getField());
    assertEquals("test_s_dv", response.getIntervalFacets().get(stringIntervalIndex).getField());
    for (int i = 0; i < response.getIntervalFacets().get(1 - stringIntervalIndex).getIntervals().size(); i++) {
        Count count = response.getIntervalFacets().get(1 - stringIntervalIndex).getIntervals().get(i);
        assertEquals(intervals[i], count.getKey());
        assertEquals(1, count.getCount());
    }
    List<Count> stringIntervals = response.getIntervalFacets().get(stringIntervalIndex).getIntervals();
    assertEquals(3, stringIntervals.size());
    assertEquals("AAA", stringIntervals.get(0).getKey());
    assertEquals(2, stringIntervals.get(0).getCount());
    assertEquals("BBB", stringIntervals.get(1).getKey());
    assertEquals(1, stringIntervals.get(1).getCount());
    assertEquals("CCC", stringIntervals.get(2).getKey());
    assertEquals(1, stringIntervals.get(2).getCount());
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Count(org.apache.solr.client.solrj.response.IntervalFacet.Count) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

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