use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method showCounts.
public void showCounts() {
Set<String> theShards = shardToJetty.keySet();
for (String shard : theShards) {
List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
for (CloudJettyRunner cjetty : solrJetties) {
ZkNodeProps props = cjetty.info;
System.err.println("PROPS:" + props);
try {
SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", // "tests" is just a
"checkShardConsistency");
// tag that won't do
// anything except be
// echoed in logs
long num = cjetty.client.solrClient.query(query).getResults().getNumFound();
System.err.println("DOCS:" + num);
} catch (SolrServerException | SolrException | IOException e) {
System.err.println("error contacting client: " + e.getMessage() + "\n");
continue;
}
boolean live = false;
String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
live = true;
}
System.err.println(" live:" + live);
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testGlobsRTG.
public void testGlobsRTG() throws Exception {
// behavior shouldn't matter if we are committed or uncommitted
for (String id : Arrays.asList("42", "99")) {
SolrDocument doc = getRandClient(random()).getById(id, params("fl", "val_*"));
String msg = id + ": fl=val_* => " + doc;
assertEquals(msg, 1, doc.size());
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertEquals(msg, 1, doc.getFieldValue("val_i"));
for (SolrParams p : Arrays.asList(params("fl", "val_*,subj*,ss*"), params("fl", "val_*", "fl", "subj*,ss*"))) {
doc = getRandClient(random()).getById(id, p);
msg = id + ": " + p + " => " + doc;
assertEquals(msg, 3, doc.size());
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertEquals(msg, 1, doc.getFieldValue("val_i"));
assertTrue(msg, doc.getFieldValue("subject") instanceof String);
// NOTE: 'subject' is diff between two docs
// TODO: val_ss: List<String>
assertTrue(msg, doc.getFieldValue("ssto") instanceof String);
assertEquals(msg, "X", doc.getFieldValue("ssto"));
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestSQLHandler method testMixedCaseFields.
private void testMixedCaseFields() throws Exception {
try {
CloudJettyRunner jetty = this.cloudJettys.get(0);
del("*:*");
commit();
indexDoc(sdoc("id", "1", "Text_t", "XXXX XXXX", "Str_s", "a", "Field_i", "7"));
indexDoc(sdoc("id", "2", "Text_t", "XXXX XXXX", "Str_s", "b", "Field_i", "8"));
indexDoc(sdoc("id", "3", "Text_t", "XXXX XXXX", "Str_s", "a", "Field_i", "20"));
indexDoc(sdoc("id", "4", "Text_t", "XXXX XXXX", "Str_s", "b", "Field_i", "11"));
indexDoc(sdoc("id", "5", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "30"));
indexDoc(sdoc("id", "6", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "40"));
indexDoc(sdoc("id", "7", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "50"));
indexDoc(sdoc("id", "8", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "60"));
commit();
SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select id, Field_i, Str_s from collection1 where Text_t='XXXX' order by Field_i desc");
SolrStream solrStream = new SolrStream(jetty.url, sParams);
List<Tuple> tuples = getTuples(solrStream);
assert (tuples.size() == 8);
Tuple tuple;
tuple = tuples.get(0);
assert (tuple.getLong("id") == 8);
assert (tuple.getLong("Field_i") == 60);
assert (tuple.get("Str_s").equals("c"));
tuple = tuples.get(1);
assert (tuple.getLong("id") == 7);
assert (tuple.getLong("Field_i") == 50);
assert (tuple.get("Str_s").equals("c"));
tuple = tuples.get(2);
assert (tuple.getLong("id") == 6);
assert (tuple.getLong("Field_i") == 40);
assert (tuple.get("Str_s").equals("c"));
tuple = tuples.get(3);
assert (tuple.getLong("id") == 5);
assert (tuple.getLong("Field_i") == 30);
assert (tuple.get("Str_s").equals("c"));
tuple = tuples.get(4);
assert (tuple.getLong("id") == 3);
assert (tuple.getLong("Field_i") == 20);
assert (tuple.get("Str_s").equals("a"));
tuple = tuples.get(5);
assert (tuple.getLong("id") == 4);
assert (tuple.getLong("Field_i") == 11);
assert (tuple.get("Str_s").equals("b"));
tuple = tuples.get(6);
assert (tuple.getLong("id") == 2);
assert (tuple.getLong("Field_i") == 8);
assert (tuple.get("Str_s").equals("b"));
tuple = tuples.get(7);
assert (tuple.getLong("id") == 1);
assert (tuple.getLong("Field_i") == 7);
assert (tuple.get("Str_s").equals("a"));
// TODO get sum(Field_i) as named one
sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select Str_s, sum(Field_i) from collection1 where id='(1 8)' group by Str_s having (sum(Field_i) = 7 OR sum(Field_i) = 60) order by sum(Field_i) desc");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 2);
tuple = tuples.get(0);
assert (tuple.get("Str_s").equals("c"));
assert (tuple.getDouble("EXPR$1") == 60);
tuple = tuples.get(1);
assert (tuple.get("Str_s").equals("a"));
assert (tuple.getDouble("EXPR$1") == 7);
sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select Str_s, sum(Field_i) from collection1 where id='(1 8)' group by Str_s having (sum(Field_i) = 7 OR sum(Field_i) = 60) order by sum(Field_i) desc");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 2);
tuple = tuples.get(0);
assert (tuple.get("Str_s").equals("c"));
assert (tuple.getDouble("EXPR$1") == 60);
tuple = tuples.get(1);
assert (tuple.get("Str_s").equals("a"));
assert (tuple.getDouble("EXPR$1") == 7);
} finally {
delete();
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestSQLHandler method testParallelSelectDistinct.
private void testParallelSelectDistinct() throws Exception {
try {
CloudJettyRunner jetty = this.cloudJettys.get(0);
del("*:*");
commit();
indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "1");
indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "2");
indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20");
indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "2");
indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50");
indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60");
commit();
SolrParams sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s asc, field_i asc");
SolrStream solrStream = new SolrStream(jetty.url, sParams);
List<Tuple> tuples = getTuples(solrStream);
assert (tuples.size() == 6);
Tuple tuple;
tuple = tuples.get(0);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 1);
tuple = tuples.get(1);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 20);
tuple = tuples.get(2);
assert (tuple.get("str_s").equals("b"));
assert (tuple.getLong("field_i") == 2);
tuple = tuples.get(3);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 30);
tuple = tuples.get(4);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 50);
tuple = tuples.get(5);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 60);
//reverse the sort
sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s desc, field_i desc");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 6);
tuple = tuples.get(0);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 60);
tuple = tuples.get(1);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 50);
tuple = tuples.get(2);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 30);
tuple = tuples.get(3);
assert (tuple.get("str_s").equals("b"));
assert (tuple.getLong("field_i") == 2);
tuple = tuples.get(4);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 20);
tuple = tuples.get(5);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 1);
//reverse the sort
sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s as myString, field_i from collection1 order by myString desc, field_i desc");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 6);
tuple = tuples.get(0);
assert (tuple.get("myString").equals("c"));
assert (tuple.getLong("field_i") == 60);
tuple = tuples.get(1);
assert (tuple.get("myString").equals("c"));
assert (tuple.getLong("field_i") == 50);
tuple = tuples.get(2);
assert (tuple.get("myString").equals("c"));
assert (tuple.getLong("field_i") == 30);
tuple = tuples.get(3);
assert (tuple.get("myString").equals("b"));
assert (tuple.getLong("field_i") == 2);
tuple = tuples.get(4);
assert (tuple.get("myString").equals("a"));
assert (tuple.getLong("field_i") == 20);
tuple = tuples.get(5);
assert (tuple.get("myString").equals("a"));
assert (tuple.getLong("field_i") == 1);
//test with limit
sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s desc, field_i desc limit 2");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 2);
tuple = tuples.get(0);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 60);
tuple = tuples.get(1);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 50);
// Test without a sort. Sort should be asc by default.
sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 6);
tuple = tuples.get(0);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 1);
tuple = tuples.get(1);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 20);
tuple = tuples.get(2);
assert (tuple.get("str_s").equals("b"));
assert (tuple.getLong("field_i") == 2);
tuple = tuples.get(3);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 30);
tuple = tuples.get(4);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 50);
tuple = tuples.get(5);
assert (tuple.get("str_s").equals("c"));
assert (tuple.getLong("field_i") == 60);
// Test with a predicate.
sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 where str_s = 'a'");
solrStream = new SolrStream(jetty.url, sParams);
tuples = getTuples(solrStream);
assert (tuples.size() == 2);
tuple = tuples.get(0);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 1);
tuple = tuples.get(1);
assert (tuple.get("str_s").equals("a"));
assert (tuple.getLong("field_i") == 20);
} finally {
delete();
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestJsonFacets method testQureyJoinBooksAndPages.
/**
* Similar to {@link #testBlockJoin} but uses query time joining.
* <p>
* (asserts are slightly diff because if a query matches multiple types of documents, blockJoin domain switches
* to parent/child domains preserve any existing parent/children from the original domain - eg: when q=*:*)
* </p>
*/
public void testQureyJoinBooksAndPages() throws Exception {
final Client client = Client.localClient();
final SolrParams p = params("rows", "0");
client.deleteByQuery("*:*", null);
// build up a list of the docs we want to test with
List<SolrInputDocument> docsToAdd = new ArrayList<>(10);
docsToAdd.add(sdoc("id", "1", "type_s", "book", "book_s", "A", "v_t", "q"));
docsToAdd.add(sdoc("id", "2", "type_s", "book", "book_s", "B", "v_t", "q w"));
docsToAdd.add(sdoc("book_id_s", "2", "id", "2.1", "type_s", "page", "page_s", "a", "v_t", "x y z"));
docsToAdd.add(sdoc("book_id_s", "2", "id", "2.2", "type_s", "page", "page_s", "b", "v_t", "x y "));
docsToAdd.add(sdoc("book_id_s", "2", "id", "2.3", "type_s", "page", "page_s", "c", "v_t", " y z"));
docsToAdd.add(sdoc("id", "3", "type_s", "book", "book_s", "C", "v_t", "q w e"));
docsToAdd.add(sdoc("book_id_s", "3", "id", "3.1", "type_s", "page", "page_s", "d", "v_t", "x "));
docsToAdd.add(sdoc("book_id_s", "3", "id", "3.2", "type_s", "page", "page_s", "e", "v_t", " y "));
docsToAdd.add(sdoc("book_id_s", "3", "id", "3.3", "type_s", "page", "page_s", "f", "v_t", " z"));
docsToAdd.add(sdoc("id", "4", "type_s", "book", "book_s", "D", "v_t", "e"));
// shuffle the docs since order shouldn't matter
Collections.shuffle(docsToAdd, random());
for (SolrInputDocument doc : docsToAdd) {
client.add(doc, null);
}
client.commit();
// the domains we'll be testing, initially setup for block join
final String toChildren = "join: { from:'id', to:'book_id_s' }";
final String toParents = "join: { from:'book_id_s', to:'id' }";
final String toBogusChildren = "join: { from:'id', to:'does_not_exist' }";
final String toBogusParents = "join: { from:'book_id_s', to:'does_not_exist' }";
client.testJQ(params(p, "q", "*:*", "json.facet", "{ " + "pages:{ type:query, domain:{" + toChildren + "} , facet:{ x:{field:v_t} } }" + ",pages2:{type:terms, field:v_t, domain:{" + toChildren + "} }" + ",books:{ type:query, domain:{" + toParents + "} , facet:{ x:{field:v_t} } }" + ",books2:{type:terms, field:v_t, domain:{" + toParents + "} }" + ",pageof3:{ type:query, q:'id:3', facet : { x : { type:terms, field:page_s, domain:{" + toChildren + "}}} }" + ",bookof22:{ type:query, q:'id:2.2', facet : { x : { type:terms, field:book_s, domain:{" + toParents + "}}} }" + ",missing_Parents:{ type:query, domain:{" + toBogusParents + "} }" + ",missing_Children:{ type:query, domain:{" + toBogusChildren + "} }" + "}"), "facets=={ count:10" + ", pages:{count:6 , x:{buckets:[ {val:y,count:4},{val:x,count:3},{val:z,count:3} ]} }" + ", pages2:{ buckets:[ {val:y,count:4},{val:x,count:3},{val:z,count:3} ] }" + ", books:{count:2 , x:{buckets:[ {val:q,count:2},{val:w,count:2},{val:e,count:1} ]} }" + ", books2:{ buckets:[ {val:q,count:2},{val:w,count:2},{val:e,count:1} ] }" + ", pageof3:{count:1 , x:{buckets:[ {val:d,count:1},{val:e,count:1},{val:f,count:1} ]} }" + ", bookof22:{count:1 , x:{buckets:[ {val:B,count:1} ]} }" + ", missing_Parents:{count:0}" + ", missing_Children:{count:0}" + "}");
// no matches in base query
client.testJQ(params("q", "no_match_s:NO_MATCHES", "json.facet", "{ processEmpty:true," + "pages:{ type:query, domain:{" + toChildren + "} }" + ",books:{ type:query, domain:{" + toParents + "} }" + "}"), "facets=={ count:0" + ", pages:{count:0}" + ", books:{count:0}" + "}");
// test facet on children nested under terms facet on parents
client.testJQ(params("q", "*:*", "json.facet", "{" + "books:{ type:terms, field:book_s, facet:{ pages:{type:terms, field:v_t, domain:{" + toChildren + "}} } }" + "}"), "facets=={ count:10" + ", books:{buckets:[{val:A,count:1,pages:{buckets:[]}}" + " ,{val:B,count:1,pages:{buckets:[{val:y,count:3},{val:x,count:2},{val:z,count:2}]}}" + " ,{val:C,count:1,pages:{buckets:[{val:x,count:1},{val:y,count:1},{val:z,count:1}]}}" + " ,{val:D,count:1,pages:{buckets:[]}}" + "] }" + "}");
// test filter after join
client.testJQ(params(p, "q", "*:*", "json.facet", "{ " + "pages1:{type:terms, field:v_t, domain:{" + toChildren + ", filter:'*:*'} }" + ",pages2:{type:terms, field:v_t, domain:{" + toChildren + ", filter:'-id:3.1'} }" + ",books:{type:terms, field:v_t, domain:{" + toParents + ", filter:'*:*'} }" + ",books2:{type:terms, field:v_t, domain:{" + toParents + ", filter:'id:2'} }" + "}"), "facets=={ count:10" + ", pages1:{ buckets:[ {val:y,count:4},{val:x,count:3},{val:z,count:3} ] }" + ", pages2:{ buckets:[ {val:y,count:4},{val:z,count:3},{val:x,count:2} ] }" + ", books:{ buckets:[ {val:q,count:2},{val:w,count:2},{val:e,count:1} ] }" + ", books2:{ buckets:[ {val:q,count:1}, {val:w,count:1} ] }" + "}");
// test other various ways to get filters
client.testJQ(params(p, "q", "*:*", "f1", "-id:3.1", "f2", "id:2", "json.facet", "{ " + "pages1:{type:terms, field:v_t, domain:{" + toChildren + ", filter:[]} }" + ",pages2:{type:terms, field:v_t, domain:{" + toChildren + ", filter:{param:f1} } }" + ",books:{type:terms, field:v_t, domain:{" + toParents + ", filter:[{param:q},{param:missing_param}]} }" + ",books2:{type:terms, field:v_t, domain:{" + toParents + ", filter:[{param:f2}] } }" + "}"), "facets=={ count:10" + ", pages1:{ buckets:[ {val:y,count:4},{val:x,count:3},{val:z,count:3} ] }" + ", pages2:{ buckets:[ {val:y,count:4},{val:z,count:3},{val:x,count:2} ] }" + ", books:{ buckets:[ {val:q,count:2},{val:w,count:2},{val:e,count:1} ] }" + ", books2:{ buckets:[ {val:q,count:1}, {val:w,count:1} ] }" + "}");
}
Aggregations