Module: ElasticRecord::Relation::SearchMethods
- Included in:
- ElasticRecord::Relation
- Defined in:
- lib/elastic_record/relation/search_methods.rb
Instance Method Summary collapse
- #as_elastic ⇒ Object
- #eager_load(*args) ⇒ Object
- #eager_load!(*args) ⇒ 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
142 143 144 |
# File 'lib/elastic_record/relation/search_methods.rb', line 142 def as_elastic build_search.as_elastic end |
#eager_load(*args) ⇒ Object
55 56 57 |
# File 'lib/elastic_record/relation/search_methods.rb', line 55 def eager_load(*args) clone.eager_load! *args end |
#eager_load!(*args) ⇒ Object
50 51 52 53 |
# File 'lib/elastic_record/relation/search_methods.rb', line 50 def eager_load!(*args) self.eager_load_values += args.flatten self end |
#extending(*modules, &block) ⇒ Object
134 135 136 |
# File 'lib/elastic_record/relation/search_methods.rb', line 134 def extending(*modules, &block) clone.extending!(*modules, &block) end |
#extending!(*modules, &block) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/elastic_record/relation/search_methods.rb', line 125 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
100 101 102 |
# File 'lib/elastic_record/relation/search_methods.rb', line 100 def facet(facet_or_name, = {}) clone.facet! facet_or_name, end |
#facet!(name_or_facet, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/elastic_record/relation/search_methods.rb', line 90 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
64 65 66 |
# File 'lib/elastic_record/relation/search_methods.rb', line 64 def limit(value) clone.limit!(value) end |
#limit!(value) ⇒ Object
59 60 61 62 |
# File 'lib/elastic_record/relation/search_methods.rb', line 59 def limit!(value) self.limit_value = value self end |
#none ⇒ Object
138 139 140 |
# File 'lib/elastic_record/relation/search_methods.rb', line 138 def none extending(None) end |
#offset(value) ⇒ Object
73 74 75 |
# File 'lib/elastic_record/relation/search_methods.rb', line 73 def offset(value) clone.offset! value end |
#offset!(value) ⇒ Object
68 69 70 71 |
# File 'lib/elastic_record/relation/search_methods.rb', line 68 def offset!(value) self.offset_value = value self end |
#order(*args) ⇒ Object
109 110 111 |
# File 'lib/elastic_record/relation/search_methods.rb', line 109 def order(*args) clone.order! *args end |
#order!(*args) ⇒ Object
:nodoc:
104 105 106 107 |
# File 'lib/elastic_record/relation/search_methods.rb', line 104 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}
116 117 118 |
# File 'lib/elastic_record/relation/search_methods.rb', line 116 def reverse_order clone.reverse_order! end |
#reverse_order! ⇒ Object
:nodoc:
120 121 122 123 |
# File 'lib/elastic_record/relation/search_methods.rb', line 120 def reverse_order! # :nodoc: self.reverse_order_value = !reverse_order_value self end |
#select(*args, &block) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/elastic_record/relation/search_methods.rb', line 82 def select(*args, &block) if block_given? to_a.select(&block) else clone.select! *args end end |
#select!(*args) ⇒ Object
77 78 79 80 |
# File 'lib/elastic_record/relation/search_methods.rb', line 77 def select!(*args) self.select_values += args.flatten self end |