2020-10-29 11:49:09 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Reports::TrendingSearch
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def report_trending_search(report)
|
|
|
|
report.labels = [
|
2023-01-09 12:20:10 +00:00
|
|
|
{ property: :term, type: :text, title: I18n.t("reports.trending_search.labels.term") },
|
2020-10-29 11:49:09 -05:00
|
|
|
{
|
|
|
|
property: :searches,
|
|
|
|
type: :number,
|
2023-01-09 12:20:10 +00:00
|
|
|
title: I18n.t("reports.trending_search.labels.searches"),
|
2020-10-29 11:49:09 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: :percent,
|
|
|
|
property: :ctr,
|
2023-01-09 12:20:10 +00:00
|
|
|
title: I18n.t("reports.trending_search.labels.click_through"),
|
|
|
|
},
|
2020-10-29 11:49:09 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
report.data = []
|
|
|
|
|
|
|
|
report.modes = [:table]
|
|
|
|
|
2023-01-09 12:20:10 +00:00
|
|
|
trends =
|
|
|
|
SearchLog.trending_from(report.start_date, end_date: report.end_date, limit: report.limit)
|
2020-10-29 11:49:09 -05:00
|
|
|
|
|
|
|
trends.each do |trend|
|
2023-01-09 12:20:10 +00:00
|
|
|
report.data << { term: trend.term, searches: trend.searches, ctr: trend.ctr }
|
2020-10-29 11:49:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|