Commit f2d95acd685aba6b910494183879f7843f9d8bc3

Authored by Daniel Damasceno
1 parent 7f0f08d6
Exists in elasticsearch_api

Adding regex filter

Signed-off-by: Daniel Henrique <danielhmarinho@gmail.com>
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
@@ -13,14 +13,10 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -13,14 +13,10 @@ 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  
17 @checkbox[model.to_sym] = true 16 @checkbox[model.to_sym] = true
18 klass = model.classify.constantize 17 klass = model.classify.constantize
19 query = get_query params[:q], klass 18 query = get_query params[:q], klass
20 -  
21 @results |= klass.__elasticsearch__.search(query).records.to_a 19 @results |= klass.__elasticsearch__.search(query).records.to_a
22 - puts "="*80  
23 - puts @results.inspect  
24 end 20 end
25 end 21 end
26 22
@@ -31,7 +27,6 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -31,7 +27,6 @@ class ElasticsearchPluginController &lt; ApplicationController
31 def get_query text, klass 27 def get_query text, klass
32 query = {} 28 query = {}
33 unless text.blank? 29 unless text.blank?
34 - puts "="*80  
35 30
36 fields = klass::SEARCHABLE_FIELDS.map do |key, value| 31 fields = klass::SEARCHABLE_FIELDS.map do |key, value|
37 if value[:weight] 32 if value[:weight]
@@ -43,17 +38,17 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -43,17 +38,17 @@ class ElasticsearchPluginController &lt; ApplicationController
43 38
44 query = { 39 query = {
45 query: { 40 query: {
46 - regexp: {  
47 - name: {  
48 - value: "*" + text + "*"  
49 -  
50 - }  
51 - } 41 + match_all: {
52 } 42 }
  43 + },
  44 + filter: {
  45 + regexp: {
  46 + name: {
  47 + value: ".*" + text + ".*" }
  48 + }
  49 + }
53 } 50 }
54 end 51 end
55 - puts "="*80  
56 - puts query.inspect  
57 query 52 query
58 end 53 end
59 54