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_options(options) ⇒ Object
- #search_options!(options) ⇒ Object
- #search_type(type) ⇒ Object
- #search_type!(type) ⇒ Object
- #select(*args, &block) ⇒ Object
- #select!(*args) ⇒ Object
Instance Method Details
#aggregate(aggregation) ⇒ Object
140 141 142 |
# File 'lib/elastic_record/relation/search_methods.rb', line 140 def aggregate(aggregation) clone.aggregate! aggregation end |
#aggregate!(aggregation) ⇒ Object
135 136 137 138 |
# File 'lib/elastic_record/relation/search_methods.rb', line 135 def aggregate!(aggregation) self.aggregation_values += [aggregation] self end |
#as_elastic ⇒ Object
182 183 184 |
# File 'lib/elastic_record/relation/search_methods.rb', line 182 def as_elastic build_search.as_elastic end |
#extending(*modules, &block) ⇒ Object
174 175 176 |
# File 'lib/elastic_record/relation/search_methods.rb', line 174 def extending(*modules, &block) clone.extending!(*modules, &block) end |
#extending!(*modules, &block) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/elastic_record/relation/search_methods.rb', line 165 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
178 179 180 |
# File 'lib/elastic_record/relation/search_methods.rb', line 178 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
149 150 151 |
# File 'lib/elastic_record/relation/search_methods.rb', line 149 def order(*args) clone.order! *args end |
#order!(*args) ⇒ Object
:nodoc:
144 145 146 147 |
# File 'lib/elastic_record/relation/search_methods.rb', line 144 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}
156 157 158 |
# File 'lib/elastic_record/relation/search_methods.rb', line 156 def reverse_order clone.reverse_order! end |
#reverse_order! ⇒ Object
:nodoc:
160 161 162 163 |
# File 'lib/elastic_record/relation/search_methods.rb', line 160 def reverse_order! # :nodoc: self.reverse_order_value = !reverse_order_value self end |
#search_options(options) ⇒ Object
118 119 120 |
# File 'lib/elastic_record/relation/search_methods.rb', line 118 def () clone.() end |
#search_options!(options) ⇒ Object
112 113 114 115 116 |
# File 'lib/elastic_record/relation/search_methods.rb', line 112 def () self. ||= {} self..merge! self end |
#search_type(type) ⇒ Object
131 132 133 |
# File 'lib/elastic_record/relation/search_methods.rb', line 131 def search_type(type) clone.search_type! type end |
#search_type!(type) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/elastic_record/relation/search_methods.rb', line 122 def search_type!(type) if type == :count # TODO: Deprecate support limit! 0 else self.search_type_value = type self end 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 |