diff --git a/plugins/elasticsearch/Rakefile b/plugins/elasticsearch/Rakefile index 71c57e1..2c6eedd 100644 --- a/plugins/elasticsearch/Rakefile +++ b/plugins/elasticsearch/Rakefile @@ -24,6 +24,7 @@ task :start do end sh 'sudo systemctl start elasticsearch' sh 'sudo systemctl enable elasticsearch' + sleep 100 # this sleep gives time to the service to be ready. end desc "stop elasticsearch" diff --git a/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb b/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb index 06c412e..e2f4151 100644 --- a/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb +++ b/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb @@ -7,7 +7,8 @@ module ElasticsearchIndexedModel settings index: { number_of_shards: 1 } do mappings dynamic: 'false' do base.indexable_fields.each do |field, value| - indexes field + value = {} if value.nil? + indexes field, type: value[:type].presence print '.' end end @@ -26,7 +27,7 @@ module ElasticsearchIndexedModel module ClassMethods def indexable_fields - self::SEARCHABLE_FIELDS.keys + self.control_fields + self::SEARCHABLE_FIELDS.update self.control_fields end end diff --git a/plugins/elasticsearch/lib/ext/community.rb b/plugins/elasticsearch/lib/ext/community.rb index 6dd34b6..8dd9d86 100644 --- a/plugins/elasticsearch/lib/ext/community.rb +++ b/plugins/elasticsearch/lib/ext/community.rb @@ -3,7 +3,7 @@ require_relative '../elasticsearch_indexed_model' class Community def self.control_fields - [] + {} end include ElasticsearchIndexedModel end diff --git a/plugins/elasticsearch/lib/ext/event.rb b/plugins/elasticsearch/lib/ext/event.rb index 6866649..d0a4b15 100644 --- a/plugins/elasticsearch/lib/ext/event.rb +++ b/plugins/elasticsearch/lib/ext/event.rb @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' class Event def self.control_fields - [ - :advertise, - :published, - ] + { + :advertise => {}, + :published => {}, + } end include ElasticsearchIndexedModel end diff --git a/plugins/elasticsearch/lib/ext/person.rb b/plugins/elasticsearch/lib/ext/person.rb index 46cefef..c99e97e 100644 --- a/plugins/elasticsearch/lib/ext/person.rb +++ b/plugins/elasticsearch/lib/ext/person.rb @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' class Person def self.control_fields - [ - :visible, - :public_profile, - ] + { + :visible => {type: 'boolean'}, + :public_profile => {type: 'boolean'}, + } end include ElasticsearchIndexedModel end diff --git a/plugins/elasticsearch/lib/ext/text_article.rb b/plugins/elasticsearch/lib/ext/text_article.rb index 7f81991..8cc4f3a 100644 --- a/plugins/elasticsearch/lib/ext/text_article.rb +++ b/plugins/elasticsearch/lib/ext/text_article.rb @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' class TextArticle def self.control_fields - [ - :advertise, - :published, - ] + { + :advertise => nil, + :published => nil, + } end include ElasticsearchIndexedModel end diff --git a/plugins/elasticsearch/lib/ext/uploaded_file.rb b/plugins/elasticsearch/lib/ext/uploaded_file.rb index aa7f4b5..b8425ba 100644 --- a/plugins/elasticsearch/lib/ext/uploaded_file.rb +++ b/plugins/elasticsearch/lib/ext/uploaded_file.rb @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' class UploadedFile def self.control_fields - [ - :advertise, - :published, - ] + { + :advertise => nil, + :published => nil, + } end include ElasticsearchIndexedModel end diff --git a/plugins/elasticsearch/test/test_helper.rb b/plugins/elasticsearch/test/test_helper.rb index bdb3012..c4d2c7e 100644 --- a/plugins/elasticsearch/test/test_helper.rb +++ b/plugins/elasticsearch/test/test_helper.rb @@ -30,4 +30,8 @@ class ElasticsearchTestHelper < ActionController::TestCase [] end + def indexed_fields model + model.mappings.to_hash[model.name.downcase.to_sym][:properties] + end + end diff --git a/plugins/elasticsearch/test/unit/models/community_test.rb b/plugins/elasticsearch/test/unit/models/community_test.rb index f73bc54..4ee9208 100644 --- a/plugins/elasticsearch/test/unit/models/community_test.rb +++ b/plugins/elasticsearch/test/unit/models/community_test.rb @@ -3,19 +3,24 @@ require "#{File.dirname(__FILE__)}/../../test_helper" class CommunityTest < ElasticsearchTestHelper def indexed_models - [Community, Person] + [Community] end def setup - @profile = create_user('testing').person super end - should 'index custom fields for Event model' do - community_cluster = Community.__elasticsearch__.client.cluster + should 'index searchable fields for Community model' do + Community::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(Community), key + end + end - assert_not_nil Community.mappings.to_hash[:community][:properties][:name] - assert_not_nil Community.mappings.to_hash[:community][:properties][:identifier] - assert_not_nil Community.mappings.to_hash[:community][:properties][:nickname] + should 'index control fields for Community model' do + Community::control_fields.each do |key, value| + assert_includes indexed_fields(Community), key + assert_includes indexed_fields(Community)[key][:type], value[:type] || 'string' + end end + end diff --git a/plugins/elasticsearch/test/unit/models/event_test.rb b/plugins/elasticsearch/test/unit/models/event_test.rb index f17b1d6..4b0da33 100644 --- a/plugins/elasticsearch/test/unit/models/event_test.rb +++ b/plugins/elasticsearch/test/unit/models/event_test.rb @@ -7,14 +7,20 @@ class EventTest < ElasticsearchTestHelper end def setup - @profile = create_user('testing').person super end - should 'index custom fields for Event model' do - event_cluster = Event.__elasticsearch__.client.cluster + should 'index searchable fields for Event model' do + Event::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(Event), key + end + end - assert_not_nil Event.mappings.to_hash[:event][:properties][:advertise] - assert_not_nil Event.mappings.to_hash[:event][:properties][:published] + should 'index control fields for Event model' do + Event::control_fields.each do |key, value| + assert_includes indexed_fields(Event), key + assert_includes indexed_fields(Event)[key][:type], value[:type] || 'string' + end end + end diff --git a/plugins/elasticsearch/test/unit/models/person_test.rb b/plugins/elasticsearch/test/unit/models/person_test.rb index 3c24f87..0be2861 100644 --- a/plugins/elasticsearch/test/unit/models/person_test.rb +++ b/plugins/elasticsearch/test/unit/models/person_test.rb @@ -3,21 +3,24 @@ require "#{File.dirname(__FILE__)}/../../test_helper" class PersonTest < ElasticsearchTestHelper def indexed_models - [Event] + [Person] end def setup - @profile = create_user('testing').person super end - should 'index custom fields for Event model' do - person_cluster = Person.__elasticsearch__.client.cluster + should 'index searchable fields for Person model' do + Person::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(Person), key + end + end - assert_not_nil Person.mappings.to_hash[:person][:properties][:name] - assert_not_nil Person.mappings.to_hash[:person][:properties][:identifier] - assert_not_nil Person.mappings.to_hash[:person][:properties][:nickname] - assert_not_nil Person.mappings.to_hash[:person][:properties][:visible] + should 'index control fields for Person model' do + Person::control_fields.each do |key, value| + assert_includes indexed_fields(Person), key + assert_includes indexed_fields(Person)[key][:type], value[:type] || 'string' + end end end -- libgit2 0.21.2