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