Class: ElasticRecord::Relation
- Inherits:
-
Object
- Object
- ElasticRecord::Relation
show all
- Includes:
- Admin, Batches, Delegation, FinderMethods, Merging, SearchMethods
- Defined in:
- lib/elastic_record/relation.rb,
lib/elastic_record/relation/none.rb,
lib/elastic_record/relation/admin.rb,
lib/elastic_record/relation/batches.rb,
lib/elastic_record/relation/merging.rb,
lib/elastic_record/relation/delegation.rb,
lib/elastic_record/relation/value_methods.rb,
lib/elastic_record/relation/finder_methods.rb,
lib/elastic_record/relation/search_methods.rb
Defined Under Namespace
Modules: Admin, Batches, Delegation, FinderMethods, Merging, None, SearchMethods
Constant Summary
collapse
- MULTI_VALUE_METHODS =
[:extending, :filter, :order, :select, :aggregation]
- SINGLE_VALUE_METHODS =
[:query, :limit, :offset, :search_options, :search_type, :reverse_order]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Admin
#create_percolator, #create_warmer
Methods included from Batches
#create_scan_search, #find_each, #find_ids_in_batches, #find_in_batches, #reindex
Methods included from Delegation
#include?, #to_ary
#all, #find, #first, #first!, #last
Methods included from Merging
#merge, #merge!
#aggregate, #aggregate!, #as_elastic, #extending, #extending!, #filter, #filter!, #find_by, #find_by!, #limit, #limit!, #none, #offset, #offset!, #order, #order!, #query, #query!, #reverse_order, #reverse_order!, #search_options, #search_options!, #search_type, #search_type!, #select, #select!
Constructor Details
#initialize(klass) ⇒ Relation
Returns a new instance of Relation.
16
17
18
19
|
# File 'lib/elastic_record/relation.rb', line 16
def initialize(klass)
@klass = klass
@values = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ElasticRecord::Relation::Delegation
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
14
15
16
|
# File 'lib/elastic_record/relation.rb', line 14
def klass
@klass
end
|
#values ⇒ Object
Returns the value of attribute values.
14
15
16
|
# File 'lib/elastic_record/relation.rb', line 14
def values
@values
end
|
Instance Method Details
#==(other) ⇒ Object
51
52
53
|
# File 'lib/elastic_record/relation.rb', line 51
def ==(other)
to_a == other
end
|
#aggregations ⇒ Object
25
26
27
|
# File 'lib/elastic_record/relation.rb', line 25
def aggregations
search_results['aggregations']
end
|
#count ⇒ Object
21
22
23
|
# File 'lib/elastic_record/relation.rb', line 21
def count
search_results['hits']['total']
end
|
#delete_all ⇒ Object
46
47
48
49
|
# File 'lib/elastic_record/relation.rb', line 46
def delete_all
find_ids_in_batches { |ids| klass.delete(ids) }
klass.elastic_index.delete_by_query(as_elastic)
end
|
#explain(id) ⇒ Object
29
30
31
|
# File 'lib/elastic_record/relation.rb', line 29
def explain(id)
klass.elastic_index.explain(id, as_elastic)
end
|
#initialize_copy(other) ⇒ Object
33
34
35
36
|
# File 'lib/elastic_record/relation.rb', line 33
def initialize_copy(other)
@values = @values.dup
reset
end
|
#inspect ⇒ Object
55
56
57
|
# File 'lib/elastic_record/relation.rb', line 55
def inspect
to_a.inspect
end
|
#scoping ⇒ Object
59
60
61
62
63
64
|
# File 'lib/elastic_record/relation.rb', line 59
def scoping
previous, klass.current_elastic_search = klass.current_elastic_search, self
yield
ensure
klass.current_elastic_search = previous
end
|
#search_hits ⇒ Object
66
67
68
|
# File 'lib/elastic_record/relation.rb', line 66
def search_hits
search_results['hits']['hits']
end
|
#to_a ⇒ Object
38
39
40
|
# File 'lib/elastic_record/relation.rb', line 38
def to_a
@records ||= load_hits(to_ids)
end
|
#to_ids ⇒ Object
42
43
44
|
# File 'lib/elastic_record/relation.rb', line 42
def to_ids
search_hits.map { |hit| hit['_id'] }
end
|