Class: ElasticRecord::Relation
- Inherits:
-
Object
- Object
- ElasticRecord::Relation
- 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]
- SINGLE_VALUE_METHODS =
[:query, :limit, :offset, :reverse_order]
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #count ⇒ Object
- #explain(id) ⇒ Object
- #facets ⇒ Object
-
#initialize(klass) ⇒ Relation
constructor
A new instance of Relation.
- #initialize_copy(other) ⇒ Object
- #inspect ⇒ Object
- #scoping ⇒ Object
- #to_a ⇒ Object
- #to_ids ⇒ Object
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
Methods included from FinderMethods
#all, #find, #first, #first!, #last
Methods included from Merging
Methods included from SearchMethods
#as_elastic, #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 (readonly)
Returns the value of attribute klass.
14 15 16 |
# File 'lib/elastic_record/relation.rb', line 14 def klass @klass end |
#values ⇒ Object (readonly)
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
46 47 48 |
# File 'lib/elastic_record/relation.rb', line 46 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 |
#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
50 51 52 |
# File 'lib/elastic_record/relation.rb', line 50 def inspect to_a.inspect end |
#scoping ⇒ Object
54 55 56 57 58 59 |
# File 'lib/elastic_record/relation.rb', line 54 def scoping previous, klass.current_elastic_search = klass.current_elastic_search, self yield ensure klass.current_elastic_search = previous 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 |