Commit e9727422ba264349cdc136b14477e29fb0f27466
Committed by
Macartur Sousa
1 parent
2cdc4592
Exists in
elasticsearch_sort
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>
Showing
3 changed files
with
60 additions
and
0 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
0 → 100644
@@ -0,0 +1,46 @@ | @@ -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