Class: Intel::SearchesController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/intel/searches_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



13
14
15
16
17
# File 'app/controllers/intel/searches_controller.rb', line 13

def index
  if params[:sort] == "conversion_rate"
    @searches.sort_by!{|s| [s["conversion_rate"].to_f, s["query"]] }
  end
end

#overviewObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/intel/searches_controller.rb', line 19

def overview
  relation = Intel::Search.where(search_type: params[:search_type])
  @searches_by_week = relation.group_by_week(:created_at, Time.zone, @time_range).count
  @conversions_by_week = relation.where("converted_at is not null").group_by_week(:created_at, Time.zone, @time_range).count
  @top_searches = @searches.first(5)
  @bad_conversion_rate = @searches.sort_by{|s| [s["conversion_rate"].to_f, s["query"]] }.first(5).select{|s| s["conversion_rate"] < 50 }
  @conversion_rate_by_week = {}
  @searches_by_week.each do |week, searches_count|
    @conversion_rate_by_week[week] = searches_count > 0 ? (100.0 * @conversions_by_week[week] / searches_count).round : 0
  end
end

#recentObject



34
35
36
37
# File 'app/controllers/intel/searches_controller.rb', line 34

def recent
  @searches = Intel::Search.order("created_at desc").limit(10)
  render layout: false
end

#streamObject



31
32
# File 'app/controllers/intel/searches_controller.rb', line 31

def stream
end