class CouchRest::Model::Base
Execute a cloudant search query. if you are not using the :include_docs option then your indexes must be named to match document properties otherwise they cannot be casted into document models.
Public Class Methods
search(index, query, options={})
click to toggle source
# File lib/couchrest_model_cloudant.rb, line 48 def self.search(index, query, options={}) if options[:sort] options[:sort] = '"' + options[:sort] + '"' end if options['sort'] options['sort'] = '"' + options['sort'] + '"' end ret = self.database.search(self.to_s, index, query, options) rows = ret['rows'] if options[:include_docs] == true || options['include_docs'] == true objects = rows.map {|r| obj = self.new(r['doc']) } else objects = rows.map {|r| obj = self.new(r['fields']); obj.id = r['id']; obj } end CouchRest::Model::SearchResults.new(ret['total_rows'], ret['bookmark'], objects) end