Class: PgSearch::ScopeOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_search/scope_options.rb

Defined Under Namespace

Modules: PgSearchRankTableAliasing, WithPgSearchHighlight, WithPgSearchRank

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ScopeOptions

Returns a new instance of ScopeOptions.



7
8
9
10
11
# File 'lib/pg_search/scope_options.rb', line 7

def initialize(config)
  @config = config
  @model = config.model
  @feature_options = config.feature_options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/pg_search/scope_options.rb', line 5

def config
  @config
end

#feature_optionsObject (readonly)

Returns the value of attribute feature_options.



5
6
7
# File 'lib/pg_search/scope_options.rb', line 5

def feature_options
  @feature_options
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/pg_search/scope_options.rb', line 5

def model
  @model
end

Instance Method Details

#apply(scope) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pg_search/scope_options.rb', line 13

def apply(scope)
  scope = include_table_aliasing_for_rank(scope)
  rank_table_alias = scope.pg_search_rank_table_alias(include_counter: true)
  rank_subquery = subquery.arel.as(rank_table_alias)

  scope
    .joins(rank_join(rank_subquery))
    .order(rank_subquery[:rank].desc)
    .order(order_within_rank)
    .extend(WithPgSearchRank)
    .extend(WithPgSearchHighlight[feature_for(:tsearch)])
end