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(activity) ⇒ Object



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

def add(activity)
  searches = activity
              .searches
              .map { |s| QueryString.new(s).id }
              .reject(&:blank?)

  predictor.sessions.add_set(activity.id.to_s, searches) if searches.many?
end

#page_sizeObject



31
32
33
# File 'app/workers/workarea/process_search_recommendations.rb', line 31

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

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

  predictor.process!
end

#predictorObject



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

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