Class: Workarea::Recommendation::Searches

Inherits:
Object
  • Object
show all
Defined in:
app/queries/workarea/recommendation/searches.rb

Class Method Summary collapse

Class Method Details

.find(query) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/queries/workarea/recommendation/searches.rb', line 4

def self.find(query)
  id = QueryString.new(query).id
  return [] if id.blank?

  result_ids = SearchPredictor.new.similarities_for(
    id,
    limit: Workarea.config.per_page
  )

  Metrics::SearchByWeek
    .any_in(query_id: result_ids)
    .sort { |a, b| result_ids.index(a.id) <=> result_ids.index(b.id) }
    .map(&:query_string)
    .reject(&:blank?)
end