Class: JobSearch

Inherits:
Object
  • Object
show all
Defined in:
app/models/job_search.rb

Class Method Summary collapse

Class Method Details

.search(jobs, query) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/job_search.rb', line 3

def search(jobs, query)
  query.split(' ').each do |part|
    field, value = part.split(':')
    value = value.to_s

    case field
    when /^id|^job/
      jobs = jobs.where('jobs.id = ?', value)
    when /^state/
      jobs = jobs.where('state = ?', value)
    when /^source|^input/
      jobs = jobs.where('source_file LIKE ?', '%' + value + '%')
    when /^dest|^output/
      jobs = jobs.where('destination_file LIKE ?', '%' + value + '%')
    when /^file/
      value = '%' + value + '%'
      jobs = jobs.where('source_file LIKE ? OR destination_file LIKE ?', value, value)
    when /^preset/
      value = '%' + value + '%'
      jobs = jobs.joins(:preset).where('presets.name LIKE ?', value)
    when /^host/
      value = '%' + value + '%'
      jobs = jobs.joins(:host).where('hosts.name LIKE ?', value)
    when /^submitted|^created/
      dates = val_to_date(value)
      if dates
        jobs = jobs.where('jobs.created_at BETWEEN ? AND ?', dates[0], dates[1])
      end
    when /^completed/
      dates = val_to_date(value)
      if dates
        jobs = jobs.where('jobs.completed_at BETWEEN ? AND ?', dates[0], dates[1])
      end
    when /^started/
      dates = val_to_date(value)
      if dates
        jobs = jobs.where('jobs.transcoding_started_at BETWEEN ? AND ?', dates[0], dates[1])
      end
    end
  end

  jobs
end