Module: ClusterPoint::FinderMethods
- Included in:
- Document
- Defined in:
- lib/cluster_point/finder_methods.rb
Instance Method Summary collapse
- #all(ordering = {string: {id: :ascending}}) ⇒ Object
- #find(*ids) ⇒ Object
- #get(id) ⇒ Object
- #where(conditions = {}, ordering = {string: {id: :ascending}}, docs = 20, offset = 0) ⇒ Object
Instance Method Details
#all(ordering = {string: {id: :ascending}}) ⇒ Object
5 6 7 |
# File 'lib/cluster_point/finder_methods.rb', line 5 def all(ordering={string: {id: :ascending}}) respToArray(JSON.parse(get_cp.where({type: self.to_s.upcase}, ordering))) end |
#find(*ids) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cluster_point/finder_methods.rb', line 14 def find(*ids) expects_array = ids.first.kind_of?(Array) return ids.first if expects_array && ids.first.empty? ids = ids.flatten.compact.uniq case ids.size when 0 raise when 1 result = get(ids.first) expects_array ? [ result ] : result else get_some(ids) end end |
#get(id) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/cluster_point/finder_methods.rb', line 32 def get(id) result = JSON.parse(get_cp.where({id: id, type: self.to_s.upcase})) if result["found"].to_i > 0 self.from_hash(result["documents"][0], self) else raise RecordNotFound end end |
#where(conditions = {}, ordering = {string: {id: :ascending}}, docs = 20, offset = 0) ⇒ Object
9 10 11 12 |
# File 'lib/cluster_point/finder_methods.rb', line 9 def where(conditions={}, ordering={string: {id: :ascending}}, docs=20, offset=0) conditions.merge!({type: self.to_s.upcase}) respToArray(JSON.parse(get_cp.where(conditions, ordering, docs, offset))) end |