class Elasticity::BaseDocument
Attributes
_explanation[RW]
Define common attributes for all documents
_id[RW]
Define common attributes for all documents
_score[RW]
Define common attributes for all documents
highlighted[RW]
Define common attributes for all documents
highlighted_attrs[RW]
Define common attributes for all documents
matched_queries[RW]
Define common attributes for all documents
sort[RW]
Define common attributes for all documents
Public Class Methods
configure(&block)
click to toggle source
Configure the given klass, changing default parameters and resetting some of the internal state.
# File lib/elasticity/base_document.rb, line 10 def self.configure(&block) self.config = IndexConfig.new(Elasticity.config, self.index_config_defaults, &block) end
Private Class Methods
default_document_type()
click to toggle source
# File lib/elasticity/base_document.rb, line 62 def self.default_document_type self.name.gsub('::', '_').underscore end
default_index_base_name()
click to toggle source
# File lib/elasticity/base_document.rb, line 66 def self.default_index_base_name ActiveSupport::Inflector.pluralize(default_document_type) end
index_config_defaults()
click to toggle source
# File lib/elasticity/base_document.rb, line 55 def self.index_config_defaults { document_type: default_document_type, index_base_name: default_index_base_name } end
Public Instance Methods
==(other)
click to toggle source
Defines equality by comparing the ID and values of each instance variable.
# 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)
click to toggle source
# File lib/elasticity/base_document.rb, line 17 def attributes=(attributes) attributes.each do |attr, value| self.public_send("#{attr}=", value) end end
created?()
click to toggle source
# File lib/elasticity/base_document.rb, line 49 def created? @created || false end
delete()
click to toggle source
# File lib/elasticity/base_document.rb, line 45 def delete self.class.delete(self._id) end
to_document()
click to toggle source
IMPLEMENT Returns a hash with the attributes as they should be stored in the index. This will be stored as _source attributes on Elasticsearch.
# File lib/elasticity/base_document.rb, line 36 def to_document raise NotImplementedError, "to_document needs to be implemented for #{self.class}" end
update()
click to toggle source
Update this object on the index, creating or updating the document.
# File lib/elasticity/base_document.rb, line 41 def update self._id, @created = self.class.index_document(_id, to_document) end