use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testAugmentersAndExplicitRTG.
public void testAugmentersAndExplicitRTG() throws Exception {
// behavior shouldn't matter if we are committed or uncommitted
for (String id : Arrays.asList("42", "99")) {
for (SolrParams p : Arrays.asList(params("fl", "id,[docid],[explain],x_alias:[value v=10 t=int]"), params("fl", "id,[docid]", "fl", "[explain],x_alias:[value v=10 t=int]"), params("fl", "id", "fl", "[docid]", "fl", "[explain]", "fl", "x_alias:[value v=10 t=int]"))) {
SolrDocument doc = getRandClient(random()).getById(id, p);
String msg = id + ": " + p + " => " + doc;
assertEquals(msg, 3, doc.size());
assertTrue(msg, doc.getFieldValue("id") instanceof String);
// RTG: [explain] should be missing (ignored)
assertTrue(msg, doc.getFieldValue("x_alias") instanceof Integer);
assertEquals(msg, 10, doc.getFieldValue("x_alias"));
assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testAugmentersRTG.
public void testAugmentersRTG() throws Exception {
// behavior shouldn't matter if we are committed or uncommitted
for (String id : Arrays.asList("42", "99")) {
for (SolrParams p : Arrays.asList(params("fl", "[docid],[shard],[explain],x_alias:[value v=10 t=int]"), params("fl", "[docid],[shard]", "fl", "[explain],x_alias:[value v=10 t=int]"), params("fl", "[docid]", "fl", "[shard]", "fl", "[explain]", "fl", "x_alias:[value v=10 t=int]"))) {
SolrDocument doc = getRandClient(random()).getById(id, p);
String msg = id + ": " + p + " => " + doc;
assertEquals(msg, 3, doc.size());
assertTrue(msg, doc.getFieldValue("[shard]") instanceof String);
// RTG: [explain] should be ignored
assertTrue(msg, doc.getFieldValue("x_alias") instanceof Integer);
assertEquals(msg, 10, doc.getFieldValue("x_alias"));
assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testFunctionsAndExplicit.
public void testFunctionsAndExplicit() throws Exception {
for (SolrParams p : Arrays.asList(params("q", "*:*", "rows", "1", "fl", "log(val_i),val_i"), params("q", "*:*", "rows", "1", "fl", "log(val_i)", "fl", "val_i"))) {
SolrDocumentList docs = assertSearch(p);
assertEquals(p + " => " + docs, 5, docs.getNumFound());
// doesn't really matter which one
SolrDocument doc = docs.get(0);
assertEquals(p + " => " + doc, 2, doc.size());
assertTrue(p + " => " + doc, doc.getFieldValue("log(val_i)") instanceof Double);
assertTrue(p + " => " + doc, doc.getFieldValue("val_i") instanceof Integer);
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestSmileRequest method testDistribJsonRequest.
@Test
public void testDistribJsonRequest() throws Exception {
initServers();
SolrTestCaseHS.Client client = servers.getClient(random().nextInt());
client.tester = new SolrTestCaseHS.Client.Tester() {
@Override
public void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
((HttpSolrClient) client).setParser(SmileResponseParser.inst);
QueryRequest query = new QueryRequest(args);
String path = args.get("qt");
if (path != null) {
query.setPath(path);
}
NamedList<Object> rsp = client.request(query);
Map m = rsp.asMap(5);
String jsonStr = Utils.toJSONString(m);
SolrTestCaseHS.matchJSON(jsonStr, tests);
}
};
client.queryDefaults().set("shards", servers.getShards());
TestJsonRequest.doJsonRequest(client);
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class StreamingTest method testMergeStream.
@Test
public void testMergeStream() throws Exception {
new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0").add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0").add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3").add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4").add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
StreamContext streamContext = new StreamContext();
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
try {
//Test ascending
SolrParams sParamsA = mapParams("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i asc");
CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
SolrParams sParamsB = mapParams("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i asc");
CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
MergeStream mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));
mstream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(mstream);
assertEquals(5, tuples.size());
assertOrder(tuples, 0, 1, 2, 3, 4);
//Test descending
sParamsA = mapParams("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i desc");
streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
sParamsB = mapParams("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i desc");
streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));
mstream.setStreamContext(streamContext);
tuples = getTuples(mstream);
assertEquals(5, tuples.size());
assertOrder(tuples, 4, 3, 2, 1, 0);
//Test compound sort
sParamsA = mapParams("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
sParamsB = mapParams("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
mstream = new MergeStream(streamA, streamB, new MultipleFieldComparator(new FieldComparator("a_f", ComparatorOrder.ASCENDING), new FieldComparator("a_i", ComparatorOrder.ASCENDING)));
mstream.setStreamContext(streamContext);
tuples = getTuples(mstream);
assertEquals(5, tuples.size());
assertOrder(tuples, 0, 2, 1, 3, 4);
sParamsA = mapParams("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
sParamsB = mapParams("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
mstream = new MergeStream(streamA, streamB, new MultipleFieldComparator(new FieldComparator("a_f", ComparatorOrder.ASCENDING), new FieldComparator("a_i", ComparatorOrder.DESCENDING)));
mstream.setStreamContext(streamContext);
tuples = getTuples(mstream);
assertEquals(5, tuples.size());
assertOrder(tuples, 2, 0, 1, 3, 4);
} finally {
solrClientCache.close();
}
}
Aggregations