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,6 +7,7 @@ module ElasticsearchIndexedModel | ||
| 7 | mappings dynamic: 'false' do | 7 | mappings dynamic: 'false' do |
| 8 | base::SEARCHABLE_FIELDS.each do |field, value| | 8 | base::SEARCHABLE_FIELDS.each do |field, value| |
| 9 | indexes field | 9 | indexes field |
| 10 | + print '.' | ||
| 10 | end | 11 | end |
| 11 | end | 12 | end |
| 12 | base.__elasticsearch__.client.indices.delete \ | 13 | base.__elasticsearch__.client.indices.delete \ |
| @@ -19,7 +20,14 @@ module ElasticsearchIndexedModel | @@ -19,7 +20,14 @@ module ElasticsearchIndexedModel | ||
| 19 | } | 20 | } |
| 20 | end | 21 | end |
| 21 | end | 22 | end |
| 23 | + base.extend ClassMethods | ||
| 22 | base.send :import | 24 | base.send :import |
| 23 | end | 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 | end | 33 | end |
plugins/elasticsearch/lib/ext/article.rb
plugins/elasticsearch/lib/ext/category.rb
| @@ -2,7 +2,10 @@ require_dependency 'category' | @@ -2,7 +2,10 @@ require_dependency 'category' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class Category | 4 | class Category |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w() | 8 | + [] |
| 7 | end | 9 | end |
| 10 | + | ||
| 8 | end | 11 | end |
plugins/elasticsearch/lib/ext/comment.rb
| @@ -2,7 +2,9 @@ require_dependency 'comment' | @@ -2,7 +2,9 @@ require_dependency 'comment' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class Comment | 4 | class Comment |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w() | 8 | + [] |
| 7 | end | 9 | end |
| 8 | end | 10 | end |
plugins/elasticsearch/lib/ext/license.rb
| @@ -2,7 +2,9 @@ require_dependency 'license.rb' | @@ -2,7 +2,9 @@ require_dependency 'license.rb' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class License | 4 | class License |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w() | 8 | + [] |
| 7 | end | 9 | end |
| 8 | end | 10 | end |
plugins/elasticsearch/lib/ext/national_region.rb
| @@ -2,7 +2,9 @@ require_dependency 'national_region' | @@ -2,7 +2,9 @@ require_dependency 'national_region' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class NationalRegion | 4 | class NationalRegion |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w() | 8 | + [] |
| 7 | end | 9 | end |
| 8 | end | 10 | end |
plugins/elasticsearch/lib/ext/profile.rb
| @@ -2,7 +2,12 @@ require_dependency 'profile' | @@ -2,7 +2,12 @@ require_dependency 'profile' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class Profile | 4 | class Profile |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w( visible public_profile ) | 8 | + [ |
| 9 | + :visible, | ||
| 10 | + :public_profile, | ||
| 11 | + ] | ||
| 7 | end | 12 | end |
| 8 | end | 13 | end |
plugins/elasticsearch/lib/ext/scrap.rb
| @@ -2,7 +2,12 @@ require_dependency 'scrap' | @@ -2,7 +2,12 @@ require_dependency 'scrap' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class Scrap | 4 | class Scrap |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w(advertise published) | 8 | + [ |
| 9 | + :advertise, | ||
| 10 | + :published, | ||
| 11 | + ] | ||
| 7 | end | 12 | end |
| 8 | end | 13 | end |
plugins/elasticsearch/lib/ext/user.rb
| @@ -2,7 +2,9 @@ require_dependency 'user' | @@ -2,7 +2,9 @@ require_dependency 'user' | ||
| 2 | require_relative '../elasticsearch_indexed_model' | 2 | require_relative '../elasticsearch_indexed_model' |
| 3 | 3 | ||
| 4 | class User | 4 | class User |
| 5 | + include ElasticsearchIndexedModel | ||
| 6 | + | ||
| 5 | def self.control_fields | 7 | def self.control_fields |
| 6 | - %w() | 8 | + [] |
| 7 | end | 9 | end |
| 8 | end | 10 | end |