lib/searchjoy/track.rb in searchjoy-0.3.2 vs lib/searchjoy/track.rb in searchjoy-0.4.0

- old
+ new

@@ -1,24 +1,48 @@ module Searchjoy module Track - def execute - results = super + module Query + def track + results = @execute - if options[:track] - attributes = options[:track] == true ? {} : options[:track] + if options[:track] && !results.search + attributes = options[:track] == true ? {} : options[:track] - search_type = - if klass.respond_to?(:name) && klass.name.present? - klass.name - elsif options[:index_name] - Array(options[:index_name]).map(&:to_s).sort.join(" ") - else - "All Indices" - end + search_type = + if klass.respond_to?(:name) && klass.name.present? + klass.name + elsif options[:models] + Array(options[:models]).map(&:to_s).sort.join(" ") + elsif options[:index_name] + Array(options[:index_name]).map(&:to_s).sort.join(" ") + else + "All Indices" + end - results.search = Searchjoy::Search.create({search_type: search_type, query: term, results_count: results.total_count}.merge(attributes)) + results.search = Searchjoy::Search.create({search_type: search_type, query: term, results_count: results.total_count}.merge(attributes)) + end end - results + def execute + results = super + track + results + end + + def search + @execute.search if @execute + end + end + + module MultiSearch + def perform + result = super + + @queries.each do |query| + query.track + end + + result + end end end end