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


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

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


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

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


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

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


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

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

#relationObject


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

def relation
  Hyrax::WorkRelation.new
end

#where_publicObject


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

def where_public
  where_access_is 'public'
end

#where_registeredObject


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

def where_registered
  where_access_is 'registered'
end