Class: SearchIndexer

Inherits:
ApplicationJob show all
Defined in:
app/jobs/search_indexer.rb

Instance Method Summary collapse

Instance Method Details

#perform(operation, type, id) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/search_indexer.rb', line 4

def perform(operation, type, id)
  obj = nil
  type.downcase!

  case type
  when 'topic'
    obj = Topic.find_by_id(id)
  when 'page'
    obj = Page.find_by_id(id)
  when 'user'
    obj = User.find_by_id(id)
  end

  return false if !obj

  if operation == 'update'
    obj.__elasticsearch__.update_document
  elsif operation == 'delete'
    obj.__elasticsearch__.delete_document
  elsif operation == 'index'
    obj.__elasticsearch__.index_document
  end
end