diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb new file mode 100644 index 0000000..92cbf8b --- /dev/null +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -0,0 +1,6 @@ +class ElasticsearchPluginController < ApplicationController + + def communities + @communities = environment.communities + end +end diff --git a/plugins/elasticsearch/lib/ext/community.rb b/plugins/elasticsearch/lib/ext/community.rb new file mode 100644 index 0000000..f921f0b --- /dev/null +++ b/plugins/elasticsearch/lib/ext/community.rb @@ -0,0 +1,46 @@ +require_dependency 'community' + +require 'elasticsearch/model' + +Community.class_eval do + include Elasticsearch::Model + include Elasticsearch::Model::Callbacks + + def self.search(query) + __elasticsearch__.search( + { + query: { + multi_match: { + query: query, + fields: ['name', 'identifier'] + } + }, + highlight: { + pre_tags: [''], + post_tags: [''], + fields: { + name: {}, + identifier: {} + } + } + } + ) + end + + settings index: { number_of_shards: 1 } do + mappings dynamic: 'false' do + indexes :name, analyzer: 'english', index_options: 'offsets' + indexes :identifier, analyzer: 'english' + end + end +end + +Community.__elasticsearch__.client.indices.delete index: Community.index_name rescue nil + +# Create the new index with the new mapping +Community.__elasticsearch__.client.indices.create \ + index: Community.index_name, + body: { settings: Community.settings.to_hash, mappings: Community.mappings.to_hash } + +# Index all Community records from the DB to Elasticsearch +Community.import diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/communities.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/communities.html.erb new file mode 100644 index 0000000..4fb51b0 --- /dev/null +++ b/plugins/elasticsearch/views/elasticsearch_plugin/communities.html.erb @@ -0,0 +1,8 @@ +