Class: Thredded::TopicsSearch

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/thredded/topics_search.rb

Instance Method Summary collapse

Constructor Details

#initialize(query, scope) ⇒ TopicsSearch

Returns a new instance of TopicsSearch.



5
6
7
8
9
10
# File 'app/models/concerns/thredded/topics_search.rb', line 5

def initialize(query, scope)
  @terms = Thredded::SearchParser.new(query).parse
  @scope = scope

  @search_categories = @search_users = @search_text = nil
end

Instance Method Details

#searchActiveRecord::Relation<Thredded::Topic>

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'app/models/concerns/thredded/topics_search.rb', line 13

def search
  if categories.present?
    @scope = @scope.joins(:topic_categories).merge(Thredded::TopicCategory.where(category_id: categories))
  end
  if text.present? || users.present?
    [search_topics, search_posts].compact.reduce(:union)
  else
    @scope
  end
end