Commit 4322afa2852e887f328e7f71f7b3acacfa27d3ad
Committed by
Macartur Sousa
1 parent
786f15a8
Exists in
elasticsearch_view
renaming elasticsearch helper to a better name (now, working as well)
Showing
2 changed files
with
25 additions
and
31 deletions
Show diff stats
plugins/elasticsearch/lib/elasticsearch_helper.rb
| @@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
| 1 | -module INDEXED_MODEL | ||
| 2 | - include Elasticsearch::Model | ||
| 3 | - include Elasticsearch::Model::Callbacks | ||
| 4 | - | ||
| 5 | - def self.included base | ||
| 6 | - base.extend ClassMethods | ||
| 7 | - end | ||
| 8 | - | ||
| 9 | - module ClassMethods | ||
| 10 | -# settings index: { number_of_shards: 1 } do | ||
| 11 | -# mappings dynamic: 'false' do | ||
| 12 | -# self::SEARCHABLE_FIELDS.each do |field, value| | ||
| 13 | -# indexes field | ||
| 14 | -# end | ||
| 15 | -# end | ||
| 16 | -# | ||
| 17 | -# self.__elasticsearch__.client.indices.delete \ | ||
| 18 | -# index: self.index_name rescue nil | ||
| 19 | -# | ||
| 20 | -# self.__elasticsearch__.client.indices.create \ | ||
| 21 | -# index: self.index_name, | ||
| 22 | -# body: { | ||
| 23 | -# settings: self.settings.to_hash, | ||
| 24 | -# mappings: self.mappings.to_hash | ||
| 25 | -# } | ||
| 26 | -# | ||
| 27 | -# self.import | ||
| 28 | -# end | ||
| 29 | - end | ||
| 30 | -end | ||
| 31 | - |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
0 → 100644
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +module ElasticsearchIndexedModel | ||
| 2 | + | ||
| 3 | + def self.included base | ||
| 4 | + base.send :include, Elasticsearch::Model | ||
| 5 | + base.class_eval do | ||
| 6 | + settings index: { number_of_shards: 1 } do | ||
| 7 | + mappings dynamic: 'false' do | ||
| 8 | + base::SEARCHABLE_FIELDS.each do |field, value| | ||
| 9 | + indexes field | ||
| 10 | + end | ||
| 11 | + end | ||
| 12 | + base.__elasticsearch__.client.indices.delete \ | ||
| 13 | + index: base.index_name rescue nil | ||
| 14 | + base.__elasticsearch__.client.indices.create \ | ||
| 15 | + index: base.index_name, | ||
| 16 | + body: { | ||
| 17 | + settings: base.settings.to_hash, | ||
| 18 | + mappings: base.mappings.to_hash | ||
| 19 | + } | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | + base.send :import | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | +end |