Commit d6d7dcadc3bb4a30daedbd5ed454fed9a264cb11
Committed by
Macartur Sousa
1 parent
a5efa70d
Exists in
elasticsearch_view
Adding regex filter
Signed-off-by: Daniel Henrique <danielhmarinho@gmail.com> Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Showing
1 changed file
with
8 additions
and
13 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
| ... | ... | @@ -13,14 +13,10 @@ class ElasticsearchPluginController < ApplicationController |
| 13 | 13 | |
| 14 | 14 | if params[:model].present? |
| 15 | 15 | params[:model].keys.each do |model| |
| 16 | - model = model.singularize | |
| 17 | 16 | @checkbox[model.to_sym] = true |
| 18 | 17 | klass = model.classify.constantize |
| 19 | 18 | query = get_query params[:q], klass |
| 20 | - | |
| 21 | 19 | @results |= klass.__elasticsearch__.search(query).records.to_a |
| 22 | - puts "="*80 | |
| 23 | - puts @results.inspect | |
| 24 | 20 | end |
| 25 | 21 | end |
| 26 | 22 | |
| ... | ... | @@ -31,7 +27,6 @@ class ElasticsearchPluginController < ApplicationController |
| 31 | 27 | def get_query text, klass |
| 32 | 28 | query = {} |
| 33 | 29 | unless text.blank? |
| 34 | - puts "="*80 | |
| 35 | 30 | |
| 36 | 31 | fields = klass::SEARCHABLE_FIELDS.map do |key, value| |
| 37 | 32 | if value[:weight] |
| ... | ... | @@ -43,17 +38,17 @@ class ElasticsearchPluginController < ApplicationController |
| 43 | 38 | |
| 44 | 39 | query = { |
| 45 | 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 | 51 | end |
| 55 | - puts "="*80 | |
| 56 | - puts query.inspect | |
| 57 | 52 | query |
| 58 | 53 | end |
| 59 | 54 | ... | ... |