Class: Workarea::Reports::SearchesWithoutResultsOverTime

Inherits:
Object
  • Object
show all
Includes:
GroupByTime, Report
Defined in:
app/queries/workarea/reports/searches_without_results_over_time.rb

Instance Method Summary collapse

Methods included from GroupByTime

#group_by, #time_group_id

Methods included from Report

#cache_key, #count, #ends_at, #initialize, #limit, #more_results?, #results, #slug, #sort, #sort_by, #sort_direction, #sort_value, #starts_at

Instance Method Details

#aggregationObject



10
11
12
# File 'app/queries/workarea/reports/searches_without_results_over_time.rb', line 10

def aggregation
  [filter, project_used_fields, group_by_time]
end

#filterObject



14
15
16
17
18
19
20
21
# File 'app/queries/workarea/reports/searches_without_results_over_time.rb', line 14

def filter
  {
    '$match' => {
      'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
      'total_results' => 0
    }
  }
end

#group_by_timeObject



27
28
29
30
31
32
33
34
35
# File 'app/queries/workarea/reports/searches_without_results_over_time.rb', line 27

def group_by_time
  {
    '$group' => {
      '_id' => time_group_id,
      'starts_at' => { '$min' => '$reporting_on' },
      'searches' => { '$sum' => '$searches' }
    }
  }
end

#project_used_fieldsObject



23
24
25
# File 'app/queries/workarea/reports/searches_without_results_over_time.rb', line 23

def project_used_fields
  { '$project' => { 'reporting_on' => 1, 'searches' => 1 } }
end