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, :facet, :filter, :order, :select, :eager_load]
- SINGLE_VALUE_METHODS =
[:query, :limit, :offset, :reverse_order]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Admin
#create_percolator, #create_warmer
Methods included from Batches
#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!
#as_elastic, #eager_load, #eager_load!, #extending, #extending!, #facet, #facet!, #filter, #filter!, #find_by, #find_by!, #limit, #limit!, #none, #offset, #offset!, #order, #order!, #query, #query!, #reverse_order, #reverse_order!, #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
54
55
56
|
# File 'lib/elastic_record/relation.rb', line 54
def ==(other)
to_a == other
end
|
#count ⇒ Object
21
22
23
|
# File 'lib/elastic_record/relation.rb', line 21
def count
search_results['hits']['total']
end
|
#eager_loading? ⇒ Boolean
38
39
40
|
# File 'lib/elastic_record/relation.rb', line 38
def eager_loading?
@should_eager_load ||= eager_load_values.any?
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
|
#facets ⇒ Object
25
26
27
|
# File 'lib/elastic_record/relation.rb', line 25
def facets
search_results['facets']
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
58
59
60
|
# File 'lib/elastic_record/relation.rb', line 58
def inspect
to_a.inspect
end
|
#scoping ⇒ Object
62
63
64
65
66
67
|
# File 'lib/elastic_record/relation.rb', line 62
def scoping
previous, klass.current_elastic_search = klass.current_elastic_search, self
yield
ensure
klass.current_elastic_search = previous
end
|
#to_a ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/elastic_record/relation.rb', line 42
def to_a
@records ||= begin
records = load_hits(to_ids)
eager_load_associations(records) if eager_loading?
records
end
end
|
#to_ids ⇒ Object
50
51
52
|
# File 'lib/elastic_record/relation.rb', line 50
def to_ids
search_hits.map { |hit| hit['_id'] }
end
|