Class: Searchlight::Search

Inherits:
Object
  • Object
show all
Extended by:
Adapters::ActionView::ClassMethods, Adapters::ActiveRecord, Adapters::Mongoid, DSL
Defined in:
lib/searchlight/search.rb

Defined Under Namespace

Classes: UndefinedOption

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

search_on, searches

Methods included from Adapters::Mongoid

search_on

Methods included from Adapters::ActionView::ClassMethods

model_name

Methods included from Adapters::ActiveRecord

search_on

Constructor Details

#initialize(options = {}) ⇒ Search

Returns a new instance of Search.



11
12
13
# File 'lib/searchlight/search.rb', line 11

def initialize(options = {})
  filter_and_mass_assign(options)
end

Instance Attribute Details

#searchObject



15
16
17
# File 'lib/searchlight/search.rb', line 15

def search
  @search ||= self.class.search_target
end

Class Method Details

.search_targetObject



5
6
7
8
9
# File 'lib/searchlight/search.rb', line 5

def self.search_target
  return @search_target           if defined?(@search_target)
  return superclass.search_target if superclass.respond_to?(:search_target) && superclass != Searchlight::Search
  guess_search_class!
end

Instance Method Details

#optionsObject



23
24
25
26
27
28
# File 'lib/searchlight/search.rb', line 23

def options
  search_attributes.reduce({}) { |hash, option_name|
    option_val = send(option_name)
    hash.tap { |hash| hash[option_name.to_sym] = option_val unless is_blank?(option_val) }
  }
end

#resultsObject



19
20
21
# File 'lib/searchlight/search.rb', line 19

def results
  @results ||= run
end