Class: Hyrax::Statistics::QueryService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/statistics/query_service.rb

Instance Method Summary collapse

Instance Method Details

#build_date_query(start_datetime, end_datetime) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/services/hyrax/statistics/query_service.rb', line 28

def build_date_query(start_datetime, end_datetime)
  start_date_str =  start_datetime.utc.strftime(date_format)
  end_date_str = if end_datetime.blank?
                   "*"
                 else
                   end_datetime.utc.strftime(date_format)
                 end
  "system_create_dtsi:[#{start_date_str} TO #{end_date_str}]"
end

#find_by_date_created(start_datetime, end_datetime = nil) ⇒ Object

query to find works created during the time range

Parameters:

  • start_datetime (DateTime)

    starting date time for range query

  • end_datetime (DateTime) (defaults to: nil)

    ending date time for range query



7
8
9
10
# File 'app/services/hyrax/statistics/query_service.rb', line 7

def find_by_date_created(start_datetime, end_datetime = nil)
  return [] if start_datetime.blank? # no date just return nothing
  relation.where(build_date_query(start_datetime, end_datetime))
end

#find_public_in_date_range(start_datetime, end_datetime = nil) ⇒ Object



16
17
18
# File 'app/services/hyrax/statistics/query_service.rb', line 16

def find_public_in_date_range(start_datetime, end_datetime = nil)
  find_by_date_created(start_datetime, end_datetime).merge(where_public)
end

#find_registered_in_date_range(start_datetime, end_datetime = nil) ⇒ Object



12
13
14
# File 'app/services/hyrax/statistics/query_service.rb', line 12

def find_registered_in_date_range(start_datetime, end_datetime = nil)
  find_by_date_created(start_datetime, end_datetime).merge(where_registered)
end

#relationObject



40
41
42
# File 'app/services/hyrax/statistics/query_service.rb', line 40

def relation
  Hyrax::WorkRelation.new
end

#where_publicObject



20
21
22
# File 'app/services/hyrax/statistics/query_service.rb', line 20

def where_public
  where_access_is 'public'
end

#where_registeredObject



24
25
26
# File 'app/services/hyrax/statistics/query_service.rb', line 24

def where_registered
  where_access_is 'registered'
end