From 221861950066abe8915fd55617797c6df7fc0ce3 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Date: Mon, 30 May 2016 17:40:00 -0300 Subject: [PATCH] Adding regex filter --- plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index db3f145..f696d0f 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -13,14 +13,10 @@ class ElasticsearchPluginController < ApplicationController if params[:model].present? params[:model].keys.each do |model| - model = model.singularize @checkbox[model.to_sym] = true klass = model.classify.constantize query = get_query params[:q], klass - @results |= klass.__elasticsearch__.search(query).records.to_a - puts "="*80 - puts @results.inspect end end @@ -31,7 +27,6 @@ class ElasticsearchPluginController < ApplicationController def get_query text, klass query = {} unless text.blank? - puts "="*80 fields = klass::SEARCHABLE_FIELDS.map do |key, value| if value[:weight] @@ -43,17 +38,17 @@ class ElasticsearchPluginController < ApplicationController query = { query: { - regexp: { - name: { - value: "*" + text + "*" - - } - } + match_all: { } + }, + filter: { + regexp: { + name: { + value: ".*" + text + ".*" } + } + } } end - puts "="*80 - puts query.inspect query end -- libgit2 0.21.2