couchrest_model_cloudant¶ ↑
Extends couchrest_model adding support for the Cloudant Search API
cloudant.com/for-developers/search/
Install¶ ↑
Gem¶ ↑
$ sudo gem install couchrest_model_cloudant
Bundler¶ ↑
If you’re using bundler, define a line similar to the following in your project’s Gemfile:
gem 'couchrest_model_cloudant'
General Usage¶ ↑
Define an index
require 'couchrest_model_cloudant' class User < CouchRest::Model::Base property :email, String property :gender, String, :default => 'f' design do index :users, :index => 'function(doc){ index("email", doc.email, {"store": "yes"}); index("gender", doc.gender); }' end end
Query an index getting back casted models
@users = User.search('users', 'gender:Female', :limit => 20, :sort => 'email<string>', :include_docs => true) @users.size => 20 @users.total_rows => 99 @users.bookmark => 'loripepsomdkjdfkdfjdfjkdfjkdfj' @users.first.class => User
It’s also possible to query an index getting back raw results parsed directly from the JSON without casting
res = User.database.search("User", "users", "gender:Female", :limit => 20) res['total_rows'] => 99
Development¶ ↑
Testing¶ ↑
couchrest_model_cloudant comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:
bundle install
That should set everything up for rake
to be run correctly which will launch the test suite.
Contact¶ ↑
Please post bugs, suggestions and patches to the bug tracker at github.com/gxbe/couchrest_model_cloudant/issues.