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 13  
14 14 if params[:model].present?
15 15 params[:model].keys.each do |model|
  16 + model = model.singularize
16 17 @checkbox[model.to_sym] = true
17 18 klass = model.classify.constantize
18 19 query = get_query params[:q], klass
  20 +
19 21 @results |= klass.__elasticsearch__.search(query).records.to_a
  22 + puts "="*80
  23 + puts @results.inspect
20 24 end
21 25 end
22 26  
... ... @@ -27,28 +31,29 @@ class ElasticsearchPluginController &lt; ApplicationController
27 31 def get_query text, klass
28 32 query = {}
29 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 37 if value[:weight]
33   - "#{k}^#{v[:weight]}"
  38 + "#{key}^#{value[:weight]}"
34 39 else
35   - "#{k}"
  40 + "#{key}"
36 41 end
37 42 end
38 43  
39 44 query = {
40 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 54 end
  55 + puts "="*80
  56 + puts query.inspect
52 57 query
53 58 end
54 59  
... ...
plugins/elasticsearch/lib/ext/community.rb 0 → 100644
... ... @@ -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
... ...