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);
}
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);
}
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));
}
}
}
}
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));
}
}
}
}
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);
}
Aggregations