Commit 7f0f08d618dc636be2ad02d8104b41d3132ab703

Authored by Daniel Damasceno
1 parent eeba2dd6
Exists in elasticsearch_api

Adding community.rb and fixing searchable_fields

Signed-off-by: Daniel Henrique <danielhmarinho@gmail.com>
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
@@ -13,10 +13,14 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -13,10 +13,14 @@ class ElasticsearchPluginController &lt; ApplicationController
13 13
14 if params[:model].present? 14 if params[:model].present?
15 params[:model].keys.each do |model| 15 params[:model].keys.each do |model|
  16 + model = model.singularize
16 @checkbox[model.to_sym] = true 17 @checkbox[model.to_sym] = true
17 klass = model.classify.constantize 18 klass = model.classify.constantize
18 query = get_query params[:q], klass 19 query = get_query params[:q], klass
  20 +
19 @results |= klass.__elasticsearch__.search(query).records.to_a 21 @results |= klass.__elasticsearch__.search(query).records.to_a
  22 + puts "="*80
  23 + puts @results.inspect
20 end 24 end
21 end 25 end
22 26
@@ -27,28 +31,29 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -27,28 +31,29 @@ class ElasticsearchPluginController &lt; ApplicationController
27 def get_query text, klass 31 def get_query text, klass
28 query = {} 32 query = {}
29 unless text.blank? 33 unless text.blank?
  34 + puts "="*80
30 35
31 - fields = klass.indexable_fields.map do |key, value| 36 + fields = klass::SEARCHABLE_FIELDS.map do |key, value|
32 if value[:weight] 37 if value[:weight]
33 - "#{k}^#{v[:weight]}" 38 + "#{key}^#{value[:weight]}"
34 else 39 else
35 - "#{k}" 40 + "#{key}"
36 end 41 end
37 end 42 end
38 43
39 query = { 44 query = {
40 query: { 45 query: {
41 - multi_match: {  
42 - query: text,  
43 - fields: fields,  
44 - operator: "and" 46 + regexp: {
  47 + name: {
  48 + value: "*" + text + "*"
  49 +
  50 + }
  51 + }
45 } 52 }
46 - },  
47 - filter: {  
48 - term: {visible: "true"}  
49 - }  
50 } 53 }
51 end 54 end
  55 + puts "="*80
  56 + puts query.inspect
52 query 57 query
53 end 58 end
54 59
plugins/elasticsearch/lib/ext/community.rb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +require_dependency 'community'
  2 +require_relative '../elasticsearch_indexed_model'
  3 +
  4 +class Community
  5 + include ElasticsearchIndexedModel
  6 +
  7 + def self.control_fields
  8 + []
  9 + end
  10 +end