class Searcher
Attributes
results[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/searcher.rb, line 4 def initialize options = {} @options = options @query = options[:query] @q = options[:q] @search_group = options[:search_group] || "pages,attachments" @type = options[:type] @comparator = options[:comparator] || "AND" end
search(options = {})
click to toggle source
# File lib/searcher.rb, line 15 def self.search options = {} searcher = Searcher.new options searcher.search searcher end
Public Instance Methods
results_with_hits() { |grouped_results[_source.id].first, hit| ... }
click to toggle source
# File lib/searcher.rb, line 43 def results_with_hits grouped_results = {} hits = @results.hits hits.group_by(&:_type).each do |type, values| klass = type.classify.constantize ids = values.collect{|value| value._source.id } grouped_results[type] = klass.find(ids).group_by(&:id) end hits.each do |hit| yield grouped_results[hit._type][hit._source.id].first, hit end end
search()
click to toggle source
# File lib/searcher.rb, line 22 def search q = @query if @q q = @q else q = q.split(" ").join(" #{@comparator} ") end if @type q = "(#{q}) AND type:#{@type}" end client = Page.__elasticsearch__.client query = client.search index: search_group, size: 30, q: q @results = Hashie::Mash.new query['hits'] end
search_group()
click to toggle source
# File lib/searcher.rb, line 58 def search_group @search_group end