public void SearchingWithSimpleFluentQueryWorksCorrectly() { Client.Put(new RiakObject(Bucket, RiakSearchKey, RiakSearchDoc, RiakConstants.ContentTypes.ApplicationJson)); var req = new RiakSearchRequest { Query = new RiakFluentSearch("riak_search_bucket", "name").Search("Alyssa").Build() }; var result = Client.Search(req); result.ShouldNotBeNull(); result.NumFound.ShouldEqual(1u); result.Documents.Count.ShouldEqual(1); result.Documents[0].Fields.Count.ShouldEqual(5); result.Documents[0].Id.Value.ShouldEqual("a.hacker"); }
public void SearchingWithMoreComplexFluentQueryWorksCorrectly() { Client.Put(new RiakObject(Bucket, RiakSearchKey, RiakSearchDoc, RiakConstants.ContentTypes.ApplicationJson)); Client.Put(new RiakObject(Bucket, RiakSearchKey2, RiakSearchDoc2, RiakConstants.ContentTypes.ApplicationJson)); var req = new RiakSearchRequest { Query = new RiakFluentSearch("riak_search_bucket", "bio") }; req.Query.Search("awesome") .And("an") .And("mathematician", t => t.Or("favorites_ablum", "Fame")); var result = Client.Search(req); result.ShouldNotBeNull(); result.NumFound.ShouldEqual(1u); result.Documents.Count.ShouldEqual(1); result.Documents[0].Fields.Count.ShouldEqual(5); result.Documents[0].Id.Value.ShouldEqual("a.public"); }
public void NumberSearch() { Console.WriteLine("Beginning NumberSearch:"); Console.WriteLine("\tAdding 10 items with ages between 21 and 30"); 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 }); batch.Put(doc); } }); Console.WriteLine("\tSearching for items between the ages of 19 and 25 (exclusive)"); var request = new RiakSearchRequest { Query = new RiakFluentSearch(bucket, "age_int").Between("19", "25").Build() }; var result = Client.Search(request); Console.WriteLine("\tNumberSearch is a success: {0}", result.IsSuccess); Console.WriteLine("\tWe found {0} items", result.Value.Documents.Count); Client.DeleteBucket(bucket); }
public void SearchingWithWildcardFluentQueryWorksCorrectly() { Client.Put(new RiakObject(Bucket, RiakSearchKey, RiakSearchDoc, RiakConstants.ContentTypes.ApplicationJson)); Client.Put(new RiakObject(Bucket, RiakSearchKey2, RiakSearchDoc2, RiakConstants.ContentTypes.ApplicationJson)); var req = new RiakSearchRequest { Query = new RiakFluentSearch("riak_search_bucket", "name").Search(Token.StartsWith("Al")).Build() }; var result = Client.Search(req); result.ShouldNotBeNull(); result.NumFound.ShouldEqual(2u); result.Documents.Count.ShouldEqual(2); }
public void SettingFieldListReturnsOnlyFieldsSpecified() { Client.Put(new RiakObject(Bucket, RiakSearchKey, RiakSearchDoc, RiakConstants.ContentTypes.ApplicationJson)); Client.Put(new RiakObject(Bucket, RiakSearchKey2, RiakSearchDoc2, RiakConstants.ContentTypes.ApplicationJson)); var req = new RiakSearchRequest { Query = new RiakFluentSearch("riak_search_bucket", "bio"), PreSort = PreSort.Key, DefaultOperation = DefaultOperation.Or, ReturnFields = new List<string> { "bio", "favorites_album" } }; req.Query.Search("awesome") .And("an") .And("mathematician", t => t.Or("favorites_ablum", "Fame")); var result = Client.Search(req); result.ShouldNotBeNull(); result.NumFound.ShouldEqual(1u); result.Documents.Count.ShouldEqual(1); // "id" field is always returned result.Documents[0].Fields.Count.ShouldEqual(3); result.Documents[0].Id.ShouldNotBeNull(); }
public void SettingSearchOnRiakBucketMakesBucketSearchable() { var bucket = string.Format("{0}_{1}", Bucket, Guid.NewGuid()); var key = Guid.NewGuid().ToString(); var props = Client.GetBucketProperties(bucket); props.SetSearch(true); var setResult = Client.SetBucketProperties(bucket, props); setResult.ShouldBeTrue(); var obj = new RiakObject(bucket, key, new { name = "OJ", age = 34 }); var putResult = Client.Put(obj); putResult.ShouldNotBeNull(); var q = new RiakFluentSearch(bucket, "name") .Search("OJ") .And("age", "34") .Build(); var search = new RiakSearchRequest { Query = q }; var searchResult = Client.Search(search); searchResult.ShouldNotBeNull(); searchResult.NumFound.ShouldEqual(1u); searchResult.Documents[0].Fields.Count.ShouldEqual(3); searchResult.Documents[0].Fields.First(x => x.Key == "id").Value.ShouldEqual(key); }
public void DateSearch() { Console.WriteLine("Beginning DateSearch:"); Console.WriteLine("\tAdding 10 items with dates between 10 days ago and yesterday"); 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 }); batch.Put(doc); } }); var start = DateTime.Now.AddDays(-4); var end = DateTime.Now.AddDays(-2); Console.WriteLine("\tSearching for items NOT between the aget of 19 and 25 (exclusive)"); 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("\tDateSearch is a success: {0}", result.IsSuccess); Console.WriteLine("\tWe found {0} items", result.Value.Documents.Count); Client.DeleteBucket(bucket); }