Class: Workarea::ProcessSearchRecommendations

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/process_search_recommendations.rb

Instance Method Summary collapse

Instance Method Details

#add(metrics) ⇒ Object



22
23
24
25
# File 'app/workers/workarea/process_search_recommendations.rb', line 22

def add(metrics)
  return unless metrics.viewed.search_ids.many?
  predictor.sessions.add_set(metrics.id, metrics.viewed.search_ids)
end

#page_sizeObject



27
28
29
# File 'app/workers/workarea/process_search_recommendations.rb', line 27

def page_size
  Workarea.config.search_recommendation_index_page_size
end

#performObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/workers/workarea/process_search_recommendations.rb', line 5

def perform(*)
  predictor.clean!

  start = Workarea.config.recommendation_expiration.ago

  Metrics::User
    .where(:updated_at.gte => start)
    .desc(:updated_at) # sort by updated_at to ensure use of that index
    .each_by(page_size) { |metrics| add(metrics) }

  predictor.process!
end

#predictorObject



18
19
20
# File 'app/workers/workarea/process_search_recommendations.rb', line 18

def predictor
  @predictor ||= Recommendation::SearchPredictor.new
end