Search in sources :

Example 66 with QueryResponse

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

the class DistributedFacetExistsSmallTest method checkWithMinCountEqOne.

private void checkWithMinCountEqOne() throws Exception {
    final ModifiableSolrParams params = buildParams("facet.mincount", "1");
    QueryResponse rsp = query(params);
    assertResponse(rsp);
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 67 with QueryResponse

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

the class DistributedFacetExistsSmallTest method checkBasicRequest.

private void checkBasicRequest() throws Exception {
    final ModifiableSolrParams params = buildParams();
    QueryResponse rsp = query(params);
    assertResponse(rsp);
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 68 with QueryResponse

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

the class TestDistribIDF method testSimpleQuery.

@Test
public void testSimpleQuery() throws Exception {
    //3 shards. 3rd shard won't have any data.
    createCollection("onecollection", "conf1", ImplicitDocRouter.NAME);
    createCollection("onecollection_local", "conf2", ImplicitDocRouter.NAME);
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", 1);
    doc.setField("cat", "football");
    doc.addField(ShardParams._ROUTE_, "a");
    solrCluster.getSolrClient().add("onecollection", doc);
    solrCluster.getSolrClient().add("onecollection_local", doc);
    doc = new SolrInputDocument();
    doc.setField("id", 2);
    doc.setField("cat", "football");
    doc.addField(ShardParams._ROUTE_, "b");
    solrCluster.getSolrClient().add("onecollection", doc);
    solrCluster.getSolrClient().add("onecollection_local", doc);
    int nDocs = TestUtil.nextInt(random(), 10, 100);
    for (int i = 0; i < nDocs; i++) {
        doc = new SolrInputDocument();
        doc.setField("id", 3 + i);
        String cat = TestUtil.randomSimpleString(random());
        if (!cat.equals("football")) {
            //Making sure no other document has the query term in it.
            doc.setField("cat", cat);
            if (rarely()) {
                //Put most documents in shard b so that 'football' becomes 'rare' in shard b
                doc.addField(ShardParams._ROUTE_, "a");
            } else {
                doc.addField(ShardParams._ROUTE_, "b");
            }
            solrCluster.getSolrClient().add("onecollection", doc);
            solrCluster.getSolrClient().add("onecollection_local", doc);
        }
    }
    solrCluster.getSolrClient().commit("onecollection");
    solrCluster.getSolrClient().commit("onecollection_local");
    //Test against all nodes
    for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) {
        try (SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) {
            try (SolrClient solrClient_local = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) {
                SolrQuery query = new SolrQuery("cat:football");
                query.setFields("*,score");
                QueryResponse queryResponse = solrClient.query("onecollection", query);
                assertEquals(2, queryResponse.getResults().getNumFound());
                float score1 = (float) queryResponse.getResults().get(0).get("score");
                float score2 = (float) queryResponse.getResults().get(1).get("score");
                assertEquals("Doc1 score=" + score1 + " Doc2 score=" + score2, 0, Float.compare(score1, score2));
                query = new SolrQuery("cat:football");
                query.setShowDebugInfo(true);
                query.setFields("*,score");
                queryResponse = solrClient_local.query("onecollection_local", query);
                assertEquals(2, queryResponse.getResults().getNumFound());
                assertEquals(2, queryResponse.getResults().get(0).get("id"));
                assertEquals(1, queryResponse.getResults().get(1).get("id"));
                float score1_local = (float) queryResponse.getResults().get(0).get("score");
                float score2_local = (float) queryResponse.getResults().get(1).get("score");
                assertEquals("Doc1 score=" + score1_local + " Doc2 score=" + score2_local, 1, Float.compare(score1_local, score2_local));
            }
        }
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 69 with QueryResponse

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

the class TestDistribIDF method testMultiCollectionQuery.

@Test
public void testMultiCollectionQuery() throws Exception {
    // collection1 and collection2 are collections which have distributed idf enabled
    // collection1_local and collection2_local don't have distributed idf available
    // Only one doc has cat:football in each collection
    // When doing queries across collections we want to test that the query takes into account
    // distributed idf for the collection=collection1,collection2 query.
    // The way we verify is that score should be the same when querying across collection1 and collection2
    // But should be different when querying across collection1_local and collection2_local
    // since the idf is calculated per shard
    createCollection("collection1", "conf1");
    createCollection("collection1_local", "conf2");
    createCollection("collection2", "conf1");
    createCollection("collection2_local", "conf2");
    addDocsRandomly();
    //Test against all nodes
    for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) {
        try (SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) {
            try (SolrClient solrClient_local = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) {
                SolrQuery query = new SolrQuery("cat:football");
                query.setFields("*,score").add("collection", "collection1,collection2");
                QueryResponse queryResponse = solrClient.query("collection1", query);
                assertEquals(2, queryResponse.getResults().getNumFound());
                float score1 = (float) queryResponse.getResults().get(0).get("score");
                float score2 = (float) queryResponse.getResults().get(1).get("score");
                assertEquals("Doc1 score=" + score1 + " Doc2 score=" + score2, 0, Float.compare(score1, score2));
                query = new SolrQuery("cat:football");
                query.setFields("*,score").add("collection", "collection1_local,collection2_local");
                queryResponse = solrClient_local.query("collection1_local", query);
                assertEquals(2, queryResponse.getResults().getNumFound());
                assertEquals(2, queryResponse.getResults().get(0).get("id"));
                assertEquals(1, queryResponse.getResults().get(1).get("id"));
                float score1_local = (float) queryResponse.getResults().get(0).get("score");
                float score2_local = (float) queryResponse.getResults().get(1).get("score");
                assertEquals("Doc1 score=" + score1_local + " Doc2 score=" + score2_local, 1, Float.compare(score1_local, score2_local));
            }
        }
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 70 with QueryResponse

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

the class TestDefaultStatsCache method dfQuery.

protected void dfQuery(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());
    }
    final QueryResponse controlRsp = controlClient.query(params);
    // query a random server
    params.set("shards", shards);
    int which = r.nextInt(clients.size());
    SolrClient client = clients.get(which);
    QueryResponse rsp = client.query(params);
    checkResponse(controlRsp, rsp);
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

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