Class: SearchRedux::Searchable

Inherits:
Object
  • Object
show all
Defined in:
lib/search_redux/searchable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Searchable

Returns a new instance of Searchable.



16
17
18
19
20
# File 'lib/search_redux/searchable.rb', line 16

def initialize(options = {})
  options = self.class.default_options.merge(options)

  @options = options
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/search_redux/searchable.rb', line 5

def columns
  @columns
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/search_redux/searchable.rb', line 7

def options
  @options
end

#rankObject

Returns the value of attribute rank.



6
7
8
# File 'lib/search_redux/searchable.rb', line 6

def rank
  @rank
end

Class Method Details

.default_optionsObject



9
10
11
12
13
14
# File 'lib/search_redux/searchable.rb', line 9

def self.default_options
  @default_options ||= {
    :columns => %w(title content),
    :rank    => 'title'
  }
end

Instance Method Details

#full_text_search(query, active_record_instance) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/search_redux/searchable.rb', line 22

def full_text_search(query, active_record_instance)
  if query.present?
    @options.merge! :query => query

    adapter  = SearchRedux.db_adapter
    strategy = SearchRedux.select_best_query_strategy(adapter, @options)

    strategy.call(active_record_instance)
  else
    active_record_instance.scoped
  end
end