Compare View
Commits (3)
Showing
13 changed files
Show diff stats
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
0 → 100644
| ... | ... | @@ -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 | ... | ... |
plugins/elasticsearch/lib/ext/article.rb
| 1 | 1 | require_dependency 'article' |
| 2 | -require_relative '../elasticsearch_helper' | |
| 2 | +require_relative '../elasticsearch_indexed_model' | |
| 3 | 3 | |
| 4 | 4 | class Article |
| 5 | - include INDEXED_MODEL | |
| 5 | + include ElasticsearchIndexedModel | |
| 6 | 6 | |
| 7 | 7 | def self.control_fields |
| 8 | - %w(advertise published).map{ |e| e.to_sym } | |
| 8 | + [ | |
| 9 | + :advertise, | |
| 10 | + :published, | |
| 11 | + ] | |
| 9 | 12 | end |
| 10 | 13 | |
| 11 | 14 | def self.indexable_fields | ... | ... |
plugins/elasticsearch/lib/ext/category.rb
plugins/elasticsearch/lib/ext/comment.rb
plugins/elasticsearch/lib/ext/license.rb
plugins/elasticsearch/lib/ext/national_region.rb
plugins/elasticsearch/lib/ext/profile.rb
plugins/elasticsearch/lib/ext/scrap.rb