Module: ElasticRecord::Relation::SearchMethods
- Included in:
- ElasticRecord::Relation
- Defined in:
- lib/elastic_record/relation/search_methods.rb
Instance Method Summary collapse
- #as_elastic ⇒ Object
- #extending(*modules, &block) ⇒ Object
- #extending!(*modules, &block) ⇒ Object
- #facet(facet_or_name, options = {}) ⇒ Object
- #facet!(name_or_facet, options = {}) ⇒ Object
- #filter(*args) ⇒ Object
- #filter!(*args) ⇒ Object
- #find_by(*args) ⇒ Object
- #find_by!(*args) ⇒ Object
- #limit(value) ⇒ Object
- #limit!(value) ⇒ Object
- #none ⇒ Object
- #offset(value) ⇒ Object
- #offset!(value) ⇒ Object
- #order(*args) ⇒ Object
-
#order!(*args) ⇒ Object
:nodoc:.
- #query(value) ⇒ Object
- #query!(value) ⇒ Object
-
#reverse_order ⇒ Object
Reverse the existing order clause on the relation.
-
#reverse_order! ⇒ Object
:nodoc:.
- #select(*args, &block) ⇒ Object
- #select!(*args) ⇒ Object
Instance Method Details
#as_elastic ⇒ Object
133 134 135 |
# File 'lib/elastic_record/relation/search_methods.rb', line 133 def as_elastic build_search.as_elastic end |
#extending(*modules, &block) ⇒ Object
125 126 127 |
# File 'lib/elastic_record/relation/search_methods.rb', line 125 def extending(*modules, &block) clone.extending!(*modules, &block) end |
#extending!(*modules, &block) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/elastic_record/relation/search_methods.rb', line 116 def extending!(*modules, &block) modules << Module.new(&block) if block_given? self.extending_values += modules.flatten extend(*extending_values) self end |
#facet(facet_or_name, options = {}) ⇒ Object
91 92 93 |
# File 'lib/elastic_record/relation/search_methods.rb', line 91 def facet(facet_or_name, = {}) clone.facet! facet_or_name, end |
#facet!(name_or_facet, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/elastic_record/relation/search_methods.rb', line 81 def facet!(name_or_facet, = {}) if name_or_facet.is_a?(String) self.facet_values += [arelastic.facet[name_or_facet].terms(name_or_facet, )] else self.facet_values += [name_or_facet] end self end |
#filter(*args) ⇒ Object
38 39 40 |
# File 'lib/elastic_record/relation/search_methods.rb', line 38 def filter(*args) clone.filter!(*args) end |
#filter!(*args) ⇒ Object
33 34 35 36 |
# File 'lib/elastic_record/relation/search_methods.rb', line 33 def filter!(*args) self.filter_values += args self end |
#find_by(*args) ⇒ Object
42 43 44 |
# File 'lib/elastic_record/relation/search_methods.rb', line 42 def find_by(*args) filter(*args).first end |
#find_by!(*args) ⇒ Object
46 47 48 |
# File 'lib/elastic_record/relation/search_methods.rb', line 46 def find_by!(*args) filter(*args).first! end |
#limit(value) ⇒ Object
55 56 57 |
# File 'lib/elastic_record/relation/search_methods.rb', line 55 def limit(value) clone.limit!(value) end |
#limit!(value) ⇒ Object
50 51 52 53 |
# File 'lib/elastic_record/relation/search_methods.rb', line 50 def limit!(value) self.limit_value = value self end |
#none ⇒ Object
129 130 131 |
# File 'lib/elastic_record/relation/search_methods.rb', line 129 def none extending(None) end |
#offset(value) ⇒ Object
64 65 66 |
# File 'lib/elastic_record/relation/search_methods.rb', line 64 def offset(value) clone.offset! value end |
#offset!(value) ⇒ Object
59 60 61 62 |
# File 'lib/elastic_record/relation/search_methods.rb', line 59 def offset!(value) self.offset_value = value self end |
#order(*args) ⇒ Object
100 101 102 |
# File 'lib/elastic_record/relation/search_methods.rb', line 100 def order(*args) clone.order! *args end |
#order!(*args) ⇒ Object
:nodoc:
95 96 97 98 |
# File 'lib/elastic_record/relation/search_methods.rb', line 95 def order!(*args) # :nodoc: self.order_values += args.flatten self end |
#query(value) ⇒ Object
29 30 31 |
# File 'lib/elastic_record/relation/search_methods.rb', line 29 def query(value) clone.query! value end |
#query!(value) ⇒ Object
24 25 26 27 |
# File 'lib/elastic_record/relation/search_methods.rb', line 24 def query!(value) self.query_value = value self end |
#reverse_order ⇒ Object
Reverse the existing order clause on the relation.
User.order('name').reverse_order # generated search has 'sort: {'name' => :desc}
107 108 109 |
# File 'lib/elastic_record/relation/search_methods.rb', line 107 def reverse_order clone.reverse_order! end |
#reverse_order! ⇒ Object
:nodoc:
111 112 113 114 |
# File 'lib/elastic_record/relation/search_methods.rb', line 111 def reverse_order! # :nodoc: self.reverse_order_value = !reverse_order_value self end |
#select(*args, &block) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/elastic_record/relation/search_methods.rb', line 73 def select(*args, &block) if block_given? to_a.select(&block) else clone.select! *args end end |
#select!(*args) ⇒ Object
68 69 70 71 |
# File 'lib/elastic_record/relation/search_methods.rb', line 68 def select!(*args) self.select_values += args.flatten self end |