Commit 52d6389722943919ef81ea1b7c2f74ab8c843184

Authored by Luciano Prestes
1 parent 7a6f1212
Exists in elasticsearch_api

Create elasticsearch structure

Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class ElasticsearchPluginController < ApplicationController
  2 +
  3 + def communities
  4 + @communities = environment.communities
  5 + end
  6 +end
... ...
plugins/elasticsearch/lib/ext/community.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +require_dependency 'community'
  2 +
  3 +require 'elasticsearch/model'
  4 +
  5 +Community.class_eval do
  6 + include Elasticsearch::Model
  7 + include Elasticsearch::Model::Callbacks
  8 +
  9 + def self.search(query)
  10 + __elasticsearch__.search(
  11 + {
  12 + query: {
  13 + multi_match: {
  14 + query: query,
  15 + fields: ['name', 'identifier']
  16 + }
  17 + },
  18 + highlight: {
  19 + pre_tags: ['<em>'],
  20 + post_tags: ['</em>'],
  21 + fields: {
  22 + name: {},
  23 + identifier: {}
  24 + }
  25 + }
  26 + }
  27 + )
  28 + end
  29 +
  30 + settings index: { number_of_shards: 1 } do
  31 + mappings dynamic: 'false' do
  32 + indexes :name, analyzer: 'english', index_options: 'offsets'
  33 + indexes :identifier, analyzer: 'english'
  34 + end
  35 + end
  36 +end
  37 +
  38 +Community.__elasticsearch__.client.indices.delete index: Community.index_name rescue nil
  39 +
  40 +# Create the new index with the new mapping
  41 +Community.__elasticsearch__.client.indices.create \
  42 + index: Community.index_name,
  43 + body: { settings: Community.settings.to_hash, mappings: Community.mappings.to_hash }
  44 +
  45 +# Index all Community records from the DB to Elasticsearch
  46 +Community.import
... ...
plugins/elasticsearch/views/elasticsearch_plugin/communities.html.erb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<h1> Communities </h1>
  2 +
  3 +<% @communities.each do |community| %>
  4 +
  5 + <%= community.name %>
  6 + <br>
  7 +
  8 +<% end %>
... ...