Assume.assumeTrue(testBucketType);
// First we have to create an index and attach it to a bucket
// and the 'default' bucket type can't be used for search
YokozunaIndex index = new YokozunaIndex("test_mr_index");
StoreIndex ssi = new StoreIndex.Builder(index).build();
client.execute(ssi);
assertTrue("Index not created", assureIndexExists("test_mr_index"));
Namespace ns = new Namespace(bucketType.toString(), mrBucketName);
StoreBucketProperties sbp = new StoreBucketProperties.Builder(ns)
.withSearchIndex(index.getName())
.build();
client.execute(sbp);
RiakObject ro = new RiakObject()
.setContentType("application/json")
.setValue(BinaryValue.create("{\"name_s\":\"Lion-o\", \"age_i\":30, \"leader_b\":true}"));
Location location = new Location(ns, "liono");
StoreValue sv = new StoreValue.Builder(ro).withLocation(location).build();
client.execute(sv);
ro = new RiakObject()
.setContentType("application/json")
.setValue(BinaryValue.create("{\"name_s\":\"Cheetara\", \"age_i\":28, \"leader_b\":false}"));
location = new Location(ns, "cheetara");
sv = new StoreValue.Builder(ro).withLocation(location).build();
client.execute(sv);
ro = new RiakObject()
.setContentType("application/json")
.setValue(BinaryValue.create("{\"name_s\":\"Snarf\", \"age_i\":43}"));
location = new Location(ns, "snarf");
sv = new StoreValue.Builder(ro).withLocation(location).build();
client.execute(sv);
ro = new RiakObject()
.setContentType("application/json")
.setValue(BinaryValue.create("{\"name_s\":\"Panthro\", \"age_i\":36}"));
location = new Location(ns, "panthro");
sv = new StoreValue.Builder(ro).withLocation(location).build();
client.execute(sv);
// Sleep some more or ... yeah, it doesn't work.
Thread.sleep(3000);
SearchMapReduce smr = new SearchMapReduce.Builder()
.withIndex(index.getName())
.withQuery("NOT leader_b:true")
.withMapPhase(Function.newAnonymousJsFunction("function(v) { return [1]; }"), false)
.withReducePhase(Function.newNamedJsFunction("Riak.reduceSum"), true)
.build();