Class: Search::ModelSearchService

Inherits:
Object
  • Object
show all
Defined in:
app/services/search/model_search_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ ModelSearchService

Returns a new instance of ModelSearchService.



2
3
4
5
6
7
# File 'app/services/search/model_search_service.rb', line 2

def initialize(scope)
  base = scope.includes("federails_actor")
  @scope = base.where("federails_actor.local": true).or(
    base.where("federails_actor.local": false, indexable: "yes")
  )
end

Instance Method Details

#search(query) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/search/model_search_service.rb', line 9

def search(query)
  if DatabaseDetector.is_postgres?
    @scope.where(
      id: Model.select("DISTINCT ON (models.id) models.*") # rubocop:disable Pundit/UsePolicyScope
        .search_for(query)
        .pluck(:id) # rubocop:todo Rails/PluckInWhere
    )
  else
    @scope.search_for(query).distinct
  end
end