Module: ElasticRecord::Relation::SearchMethods
- Included in:
- ElasticRecord::Relation
- Defined in:
- lib/elastic_record/relation/search_methods.rb
Defined Under Namespace
Classes: FilterChain
Instance Method Summary collapse
- #aggregate(aggregation) ⇒ Object
- #aggregate!(aggregation) ⇒ Object
- #as_elastic ⇒ Object
- #extending(*modules, &block) ⇒ Object
- #extending!(*modules, &block) ⇒ Object
- #filter(opts = :chain, *rest) ⇒ 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:.
- #search_type(type) ⇒ Object
- #search_type!(type) ⇒ Object
- #select(*args, &block) ⇒ Object
- #select!(*args) ⇒ Object
Instance Method Details
#aggregate(aggregation) ⇒ Object
126 127 128 |
# File 'lib/elastic_record/relation/search_methods.rb', line 126 def aggregate(aggregation) clone.aggregate! aggregation end |
#aggregate!(aggregation) ⇒ Object
121 122 123 124 |
# File 'lib/elastic_record/relation/search_methods.rb', line 121 def aggregate!(aggregation) self.aggregation_values += [aggregation] self end |
#as_elastic ⇒ Object
168 169 170 |
# File 'lib/elastic_record/relation/search_methods.rb', line 168 def as_elastic build_search.as_elastic end |
#extending(*modules, &block) ⇒ Object
160 161 162 |
# File 'lib/elastic_record/relation/search_methods.rb', line 160 def extending(*modules, &block) clone.extending!(*modules, &block) end |
#extending!(*modules, &block) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/elastic_record/relation/search_methods.rb', line 151 def extending!(*modules, &block) modules << Module.new(&block) if block_given? self.extending_values += modules.flatten extend(*extending_values) self end |
#filter(opts = :chain, *rest) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/elastic_record/relation/search_methods.rb', line 65 def filter(opts = :chain, *rest) if opts == :chain FilterChain.new(clone) else clone.filter!(opts, *rest) end end |
#filter!(*args) ⇒ Object
60 61 62 63 |
# File 'lib/elastic_record/relation/search_methods.rb', line 60 def filter!(*args) self.filter_values += args self end |
#find_by(*args) ⇒ Object
73 74 75 |
# File 'lib/elastic_record/relation/search_methods.rb', line 73 def find_by(*args) filter(*args).first end |
#find_by!(*args) ⇒ Object
77 78 79 |
# File 'lib/elastic_record/relation/search_methods.rb', line 77 def find_by!(*args) filter(*args).first! end |
#limit(value) ⇒ Object
86 87 88 |
# File 'lib/elastic_record/relation/search_methods.rb', line 86 def limit(value) clone.limit!(value) end |
#limit!(value) ⇒ Object
81 82 83 84 |
# File 'lib/elastic_record/relation/search_methods.rb', line 81 def limit!(value) self.limit_value = value self end |
#none ⇒ Object
164 165 166 |
# File 'lib/elastic_record/relation/search_methods.rb', line 164 def none extending(None) end |
#offset(value) ⇒ Object
95 96 97 |
# File 'lib/elastic_record/relation/search_methods.rb', line 95 def offset(value) clone.offset! value end |
#offset!(value) ⇒ Object
90 91 92 93 |
# File 'lib/elastic_record/relation/search_methods.rb', line 90 def offset!(value) self.offset_value = value self end |
#order(*args) ⇒ Object
135 136 137 |
# File 'lib/elastic_record/relation/search_methods.rb', line 135 def order(*args) clone.order! *args end |
#order!(*args) ⇒ Object
:nodoc:
130 131 132 133 |
# File 'lib/elastic_record/relation/search_methods.rb', line 130 def order!(*args) # :nodoc: self.order_values += args.flatten self end |
#query(value) ⇒ Object
56 57 58 |
# File 'lib/elastic_record/relation/search_methods.rb', line 56 def query(value) clone.query! value end |
#query!(value) ⇒ Object
51 52 53 54 |
# File 'lib/elastic_record/relation/search_methods.rb', line 51 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}
142 143 144 |
# File 'lib/elastic_record/relation/search_methods.rb', line 142 def reverse_order clone.reverse_order! end |
#reverse_order! ⇒ Object
:nodoc:
146 147 148 149 |
# File 'lib/elastic_record/relation/search_methods.rb', line 146 def reverse_order! # :nodoc: self.reverse_order_value = !reverse_order_value self end |
#search_type(type) ⇒ Object
117 118 119 |
# File 'lib/elastic_record/relation/search_methods.rb', line 117 def search_type(type) clone.search_type! type end |
#search_type!(type) ⇒ Object
112 113 114 115 |
# File 'lib/elastic_record/relation/search_methods.rb', line 112 def search_type!(type) self.search_type_value = type self end |
#select(*args, &block) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/elastic_record/relation/search_methods.rb', line 104 def select(*args, &block) if block_given? to_a.select(&block) else clone.select! *args end end |
#select!(*args) ⇒ Object
99 100 101 102 |
# File 'lib/elastic_record/relation/search_methods.rb', line 99 def select!(*args) self.select_values += args.flatten self end |