Sha256: fe6f351b915cda86e057c9f9bdc2930192dcb37e81ebce8c38301a6c3350a9da
Contents?: true
Size: 830 Bytes
Versions: 2
Compression:
Stored size: 830 Bytes
Contents
# Indexes the ActiveModel instance for search, based on # the mapping outlined using ElasticMapper::Mapping. module ElasticMapper::Index # Index the ActiveModel in ElasticSearch. def index mapping_name = self.class.instance_variable_get(:@_mapping_name) ElasticMapper.index.type(mapping_name).put(self.id, index_hash) end # Remove the document from the ElasticSearch index. def delete_from_index mapping_name = self.class.instance_variable_get(:@_mapping_name) ElasticMapper.index.type(mapping_name).delete(self.id) end # Generate a hash representation of the model. # # @return [Hash] hash representation of model. def index_hash mapping = self.class.instance_variable_get(:@_mapping) mapping.inject({}) do |h, (k, v)| h[k] = self.send(v[:field]) h end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
elastic_mapper-0.3.0 | lib/elastic_mapper/index.rb |
elastic_mapper-0.2.1 | lib/elastic_mapper/index.rb |