Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using CorrugatedIron;
using CorrugatedIron.Models;
using CorrugatedIron.Models.Search;
using CorrugatedIron.Models.MapReduce;
using CorrugatedIron.Util;
namespace MiscellaneousSamples
{
public class RiakSearch
{
public void NumberSearch() {
var Cluster = RiakCluster.FromConfig("riakConfig");
var Client = Cluster.CreateClient();
var bucket = "rsds";
var props = new RiakBucketProperties()
.SetSearch(true);
var setResult = Client.SetBucketProperties(bucket, props);
Client.Batch(batch =>
{
for (var i = 1; i < 11; i++)
{
var d = DateTime.Now.AddDays(0 - i);
var doc = new RiakObject(bucket, i.ToString(), new { value = i, created_date = d, age_int = 20 + i });
Console.WriteLine(d.ToString("s"));
batch.Put(doc);
}
});
var request = new RiakSearchRequest
{
Query = new RiakFluentSearch(bucket, "age_int").Between("19", "25").Build()
};
var result = Client.Search(request);
Console.WriteLine("search is a success: {0}", result.IsSuccess);
Client.DeleteBucket(bucket);
}
public void DateSearch() {
var Cluster = RiakCluster.FromConfig("riakConfig");
var Client = Cluster.CreateClient();
var bucket = "rsds";
var props = new RiakBucketProperties()
.SetSearch(true);
var setResult = Client.SetBucketProperties(bucket, props);
Client.Batch(batch =>
{
for (var i = 1; i < 11; i++)
{
var d = DateTime.Now.AddDays(0 - i);
var doc = new RiakObject(bucket, i.ToString(), new { value = i, created_date = d });
Console.WriteLine(d.ToString("s"));
batch.Put(doc);
}
});
Console.WriteLine("Sleeping for the indexing");
System.Threading.Thread.Sleep(500);
var start = DateTime.Now.AddDays(-4);
var end = DateTime.Now.AddDays(-2);
var request = new RiakSearchRequest
{
Query = new RiakFluentSearch(bucket, "created_date").Between(start.ToString("s"), end.ToString("s")).Build()
};
var result = Client.Search(request);
Console.WriteLine("search is a success: {0}", result.IsSuccess);
Client.DeleteBucket(bucket);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment