This week the “MyCouch.Cloudant NuGet” package was released. Since Cloudant is almost 100% compatible with CouchDb, the plain MyCouch package is working nicely with Cloudant. However, there are some great features in Cloudant which are not implemented in CouchDb, hence the birth of MyCouch.Cloudant. The first feature out, is support for Searches. Tag along and I’ll show you how to use it.

Searches is a way for you to run ad-hoc queries against your Cloudant data, using Lucene. The way you do this is by creating a search index and then you start querying it. Simple! I know. Except from passing expressions, you can sort the output, you can limit the size of the result set and use this in conjunction with a bookmark to page through the data. But lets stop talking and lets see how this is consumed in MyCouch.

Did you catch the coding error? I did misspell omnivore hence one query was empty in the response. The full code (corrected) looks like this:

var uri = new MyCouchUriBuilder("https://myaccount.cloudant.com/")
  .SetDbName("animaldb")
  .SetBasicCredentials("key", "pwd")
  .Build();

using (var client = new CloudantClient(uri))
{
  var elephant = client.Searches.SearchAsync("views101", "animals",
    q => q.Expression("elephant"));

  var omnivores = client.Searches.SearchAsync("views101", "animals",
    q => q.Expression("class:omnivore"));

  var mediumSizedHerbivores = client.Searches.SearchAsync("views101", "animals",
    q => q.Expression("min_length:[1 TO 3] AND diet:herbivore").Sort("min_length"));

  Task.WaitAll(
    QuichSearchDemo.DumpAnimals(elephant),
    QuichSearchDemo.DumpAnimals(omnivores),
    QuichSearchDemo.DumpAnimals(mediumSizedHerbivores));
}

If you are looking for more info about MyCouch, just head over to the GitHub repository or ping me and I’ll attend your question as soon as possible.

Cheers,

//Daniel

Category:
CouchDb & Cloudant, Development, MyCouch, NoSQL
Tags:
, , ,

Join the conversation! 5 Comments

  1. The search API exposed with MyCouchclient.Searches seems to be building all queries using query string params. Does it support using POST (e.g. {“query”:”class:bird”, “limit”:100}), if yes, how can we specify that?
    Also, how can one specify facet search criteria? Is it done via Expressions?

    Reply
  2. What is this line of code??
    QuichSearchDemo.DumpAnimals <–

    Reply
    • Just a simple helper method in the demo console app that writes information from the response about the animals to the console. So it’s no animals taking a dump or being dumped ;-)

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: