lib/searchjoy/track.rb in searchjoy-0.0.10 vs lib/searchjoy/track.rb in searchjoy-0.1.0
- old
+ new
@@ -1,15 +1,24 @@
module Searchjoy
module Track
- def search_with_track(term, options = {}, &block)
- results = search_without_track(term, options) do |body|
- block.call(body) if block
- end
+ def execute_with_track
+ results = execute_without_track
if options[:track]
attributes = options[:track] == true ? {} : options[:track]
- results.search = Searchjoy::Search.create({search_type: name, query: term, results_count: results.total_count}.merge(attributes))
+
+ 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
+
+ results.search = Searchjoy::Search.create({search_type: search_type, query: term, results_count: results.total_count}.merge(attributes))
end
+
results
end
end
end