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

Instance Method Details

#aggregate(aggregation) ⇒ Object

[View source]

135
136
137
# File 'lib/elastic_record/relation/search_methods.rb', line 135

def aggregate(aggregation)
  clone.aggregate! aggregation
end

#aggregate!(aggregation) ⇒ Object

[View source]

130
131
132
133
# File 'lib/elastic_record/relation/search_methods.rb', line 130

def aggregate!(aggregation)
  self.aggregation_values += [aggregation]
  self
end

#as_elasticObject

[View source]

177
178
179
# File 'lib/elastic_record/relation/search_methods.rb', line 177

def as_elastic
  build_search.as_elastic
end

#extending(*modules, &block) ⇒ Object

[View source]

169
170
171
# File 'lib/elastic_record/relation/search_methods.rb', line 169

def extending(*modules, &block)
  clone.extending!(*modules, &block)
end

#extending!(*modules, &block) ⇒ Object

[View source]

160
161
162
163
164
165
166
167
# File 'lib/elastic_record/relation/search_methods.rb', line 160

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

[View source]

81
82
83
84
85
86
87
# File 'lib/elastic_record/relation/search_methods.rb', line 81

def filter(opts = :chain, *rest)
  if opts == :chain
    FilterChain.new(clone)
  else
    clone.filter!(opts, *rest)
  end
end

#filter!(*args) ⇒ Object

[View source]

76
77
78
79
# File 'lib/elastic_record/relation/search_methods.rb', line 76

def filter!(*args)
  self.filter_values += args
  self
end

#limit(value) ⇒ Object

[View source]

94
95
96
# File 'lib/elastic_record/relation/search_methods.rb', line 94

def limit(value)
  clone.limit!(value)
end

#limit!(value) ⇒ Object

[View source]

89
90
91
92
# File 'lib/elastic_record/relation/search_methods.rb', line 89

def limit!(value)
  self.limit_value = value
  self
end

#noneObject

[View source]

173
174
175
# File 'lib/elastic_record/relation/search_methods.rb', line 173

def none
  extending(None)
end

#offset(value) ⇒ Object

[View source]

103
104
105
# File 'lib/elastic_record/relation/search_methods.rb', line 103

def offset(value)
  clone.offset! value
end

#offset!(value) ⇒ Object

[View source]

98
99
100
101
# File 'lib/elastic_record/relation/search_methods.rb', line 98

def offset!(value)
  self.offset_value = value
  self
end

#order(*args) ⇒ Object

[View source]

144
145
146
# File 'lib/elastic_record/relation/search_methods.rb', line 144

def order(*args)
  clone.order! *args
end

#order!(*args) ⇒ Object

:nodoc:

[View source]

139
140
141
142
# File 'lib/elastic_record/relation/search_methods.rb', line 139

def order!(*args) # :nodoc:
  self.order_values += args.flatten
  self
end

#query(value) ⇒ Object

[View source]

72
73
74
# File 'lib/elastic_record/relation/search_methods.rb', line 72

def query(value)
  clone.query! value
end

#query!(value) ⇒ Object

[View source]

67
68
69
70
# File 'lib/elastic_record/relation/search_methods.rb', line 67

def query!(value)
  self.query_value = value
  self
end

#reverse_orderObject

Reverse the existing order clause on the relation.

User.order('name').reverse_order # generated search has 'sort: {'name' => :desc}
[View source]

151
152
153
# File 'lib/elastic_record/relation/search_methods.rb', line 151

def reverse_order
  clone.reverse_order!
end

#reverse_order!Object

:nodoc:

[View source]

155
156
157
158
# File 'lib/elastic_record/relation/search_methods.rb', line 155

def reverse_order! # :nodoc:
  self.reverse_order_value = !reverse_order_value
  self
end

#search_options(options) ⇒ Object

[View source]

113
114
115
# File 'lib/elastic_record/relation/search_methods.rb', line 113

def search_options(options)
  clone.search_options!(options)
end

#search_options!(options) ⇒ Object

[View source]

107
108
109
110
111
# File 'lib/elastic_record/relation/search_methods.rb', line 107

def search_options!(options)
  self.search_options_value ||= {}
  self.search_options_value.merge! options
  self
end

#search_type(type) ⇒ Object

[View source]

126
127
128
# File 'lib/elastic_record/relation/search_methods.rb', line 126

def search_type(type)
  clone.search_type! type
end

#search_type!(type) ⇒ Object

[View source]

117
118
119
120
121
122
123
124
# File 'lib/elastic_record/relation/search_methods.rb', line 117

def search_type!(type)
  if type == :count # TODO: Deprecate support
    limit! 0
  else
    self.search_type_value = type
    self
  end
end