Class: Thredded::TopicsSearch
- Inherits:
-
Object
- Object
- Thredded::TopicsSearch
- Defined in:
- app/models/concerns/thredded/topics_search.rb
Instance Method Summary collapse
-
#initialize(query, scope) ⇒ TopicsSearch
constructor
A new instance of TopicsSearch.
- #search ⇒ ActiveRecord::Relation<Thredded::Topic>
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
#search ⇒ ActiveRecord::Relation<Thredded::Topic>
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 |