Class: Elasticity::BaseDocument
- Inherits:
-
Object
- Object
- Elasticity::BaseDocument
- Includes:
- ActiveModel::Model
- Defined in:
- lib/elasticity/base_document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_explanation ⇒ Object
Define common attributes for all documents.
-
#_id ⇒ Object
Define common attributes for all documents.
-
#_score ⇒ Object
Define common attributes for all documents.
-
#highlighted ⇒ Object
Define common attributes for all documents.
-
#highlighted_attrs ⇒ Object
Define common attributes for all documents.
-
#matched_queries ⇒ Object
Define common attributes for all documents.
-
#sort ⇒ Object
Define common attributes for all documents.
Class Method Summary collapse
-
.configure(&block) ⇒ Object
Configure the given klass, changing default parameters and resetting some of the internal state.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Defines equality by comparing the ID and values of each instance variable.
- #attributes=(attributes) ⇒ Object
- #created? ⇒ Boolean
- #delete ⇒ Object
-
#to_document ⇒ Object
IMPLEMENT Returns a hash with the attributes as they should be stored in the index.
-
#update ⇒ Object
Update this object on the index, creating or updating the document.
Instance Attribute Details
#_explanation ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def _explanation @_explanation end |
#_id ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def _id @_id end |
#_score ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def _score @_score end |
#highlighted ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def highlighted @highlighted end |
#highlighted_attrs ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def highlighted_attrs @highlighted_attrs end |
#matched_queries ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def matched_queries @matched_queries end |
#sort ⇒ Object
Define common attributes for all documents
15 16 17 |
# File 'lib/elasticity/base_document.rb', line 15 def sort @sort end |
Class Method Details
.configure(&block) ⇒ Object
Configure the given klass, changing default parameters and resetting some of the internal state.
10 11 12 |
# File 'lib/elasticity/base_document.rb', line 10 def self.configure(&block) self.config = IndexConfig.new(Elasticity.config, self.index_config_defaults, &block) end |
Instance Method Details
#==(other) ⇒ Object
Defines equality by comparing the ID and values of each instance variable.
24 25 26 27 28 29 30 31 |
# File 'lib/elasticity/base_document.rb', line 24 def ==(other) return false if other.nil? return false if _id != other._id instance_variables.all? do |ivar| instance_variable_get(ivar) == other.instance_variable_get(ivar) end end |
#attributes=(attributes) ⇒ Object
17 18 19 20 21 |
# File 'lib/elasticity/base_document.rb', line 17 def attributes=(attributes) attributes.each do |attr, value| self.public_send("#{attr}=", value) end end |
#created? ⇒ Boolean
49 50 51 |
# File 'lib/elasticity/base_document.rb', line 49 def created? @created || false end |
#delete ⇒ Object
45 46 47 |
# File 'lib/elasticity/base_document.rb', line 45 def delete self.class.delete(self._id) end |
#to_document ⇒ Object
IMPLEMENT Returns a hash with the attributes as they should be stored in the index. This will be stored as _source attributes on Elasticsearch.
36 37 38 |
# File 'lib/elasticity/base_document.rb', line 36 def to_document raise NotImplementedError, "to_document needs to be implemented for #{self.class}" end |
#update ⇒ Object
Update this object on the index, creating or updating the document.
41 42 43 |
# File 'lib/elasticity/base_document.rb', line 41 def update self._id, @created = self.class.index_document(_id, to_document) end |