Commit eeba2dd69355abe666edd8973335f3fbdec5a086
1 parent
70d116cf
Exists in
elasticsearch_api
refactoring models extensions
Showing
9 changed files
with
36 additions
and
12 deletions
Show diff stats
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
| ... | ... | @@ -7,6 +7,7 @@ module ElasticsearchIndexedModel |
| 7 | 7 | mappings dynamic: 'false' do |
| 8 | 8 | base::SEARCHABLE_FIELDS.each do |field, value| |
| 9 | 9 | indexes field |
| 10 | + print '.' | |
| 10 | 11 | end |
| 11 | 12 | end |
| 12 | 13 | base.__elasticsearch__.client.indices.delete \ |
| ... | ... | @@ -19,7 +20,14 @@ module ElasticsearchIndexedModel |
| 19 | 20 | } |
| 20 | 21 | end |
| 21 | 22 | end |
| 23 | + base.extend ClassMethods | |
| 22 | 24 | base.send :import |
| 23 | 25 | end |
| 24 | 26 | |
| 27 | + module ClassMethods | |
| 28 | + def indexable_fields | |
| 29 | + self::SEARCHABLE_FIELDS.keys + self.control_fields | |
| 30 | + end | |
| 31 | + end | |
| 32 | + | |
| 25 | 33 | end | ... | ... |
plugins/elasticsearch/lib/ext/article.rb
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
| ... | ... | @@ -2,7 +2,12 @@ require_dependency 'profile' |
| 2 | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | |
| 4 | 4 | class Profile |
| 5 | + include ElasticsearchIndexedModel | |
| 6 | + | |
| 5 | 7 | def self.control_fields |
| 6 | - %w( visible public_profile ) | |
| 8 | + [ | |
| 9 | + :visible, | |
| 10 | + :public_profile, | |
| 11 | + ] | |
| 7 | 12 | end |
| 8 | 13 | end | ... | ... |
plugins/elasticsearch/lib/ext/scrap.rb
| ... | ... | @@ -2,7 +2,12 @@ require_dependency 'scrap' |
| 2 | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | |
| 4 | 4 | class Scrap |
| 5 | + include ElasticsearchIndexedModel | |
| 6 | + | |
| 5 | 7 | def self.control_fields |
| 6 | - %w(advertise published) | |
| 8 | + [ | |
| 9 | + :advertise, | |
| 10 | + :published, | |
| 11 | + ] | |
| 7 | 12 | end |
| 8 | 13 | end | ... | ... |
plugins/elasticsearch/lib/ext/user.rb