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.



9
10
11
12
13
# File 'lib/pg_search/scope_options.rb', line 9

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.



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

def config
  @config
end

#feature_optionsObject (readonly)

Returns the value of attribute feature_options.



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

def feature_options
  @feature_options
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#apply(scope) ⇒ Object



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

def apply(scope)
  scope = include_table_aliasing_for_rank(scope)
  rank_table_alias = scope.pg_search_rank_table_alias(include_counter: true)

  scope
    .joins(rank_join(rank_table_alias))
    .order(Arel.sql("#{rank_table_alias}.rank DESC, #{order_within_rank}"))
    .extend(WithPgSearchRank)
    .extend(WithPgSearchHighlight[feature_for(:tsearch)])
end