diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index 15c6c01..db3f145 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -13,10 +13,14 @@ 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 @@ -27,28 +31,29 @@ class ElasticsearchPluginController < ApplicationController def get_query text, klass query = {} unless text.blank? + puts "="*80 - fields = klass.indexable_fields.map do |key, value| + fields = klass::SEARCHABLE_FIELDS.map do |key, value| if value[:weight] - "#{k}^#{v[:weight]}" + "#{key}^#{value[:weight]}" else - "#{k}" + "#{key}" end end query = { query: { - multi_match: { - query: text, - fields: fields, - operator: "and" + regexp: { + name: { + value: "*" + text + "*" + + } + } } - }, - filter: { - term: {visible: "true"} - } } end + puts "="*80 + puts query.inspect query end diff --git a/plugins/elasticsearch/lib/ext/community.rb b/plugins/elasticsearch/lib/ext/community.rb new file mode 100644 index 0000000..3eaebc4 --- /dev/null +++ b/plugins/elasticsearch/lib/ext/community.rb @@ -0,0 +1,10 @@ +require_dependency 'community' +require_relative '../elasticsearch_indexed_model' + +class Community + include ElasticsearchIndexedModel + + def self.control_fields + [] + end +end -- libgit2 0.21.2