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("")
  .SetBasicCredentials("key", "pwd")

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"));


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.



CouchDB & Cloudant, Data storage, Development
, , ,

Join the conversation! 6 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?

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

    • 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 ;-)

  3. Hey with your latest changes the code above doesn’t work.
    You added in the SearchIndexRequest object so now it looks kind of :

    using (var client = new MyCouchCloudantClient(uri))
    var searchRequest = new SearchIndexRequest(“designDocumentName”, “searchIndexName”)
    Expression = searchString

    var temp = client.Searches.SearchAsync(searchRequest);
    var searchResult = temp.Result;



Leave a Reply

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

You are commenting using your 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


Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: