Class: Searcher

Inherits:
Object
  • Object
show all
Defined in:
app/models/searcher.rb

Defined Under Namespace

Classes: Boostificator, Configuration, Model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Searcher

Returns a new instance of Searcher.



11
12
13
14
15
# File 'app/models/searcher.rb', line 11

def initialize(&block)
  self.scope_chain = [:default, :runtime]
  self.search_object = Searcher::Model.new(self)
  self.configuration = Configuration.new(self, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



115
116
117
118
119
120
121
122
# File 'app/models/searcher.rb', line 115

def method_missing(name, *args, &block)
  if configuration.scopes.include?(name)
    scope_chain << name
    return self
  end
  return results.send(name, *args, &block) if results.respond_to?(name)
  super
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



3
4
5
# File 'app/models/searcher.rb', line 3

def configuration
  @configuration
end

#scope_chainObject

Returns the value of attribute scope_chain.



4
5
6
# File 'app/models/searcher.rb', line 4

def scope_chain
  @scope_chain
end

#search_objectObject

Returns the value of attribute search_object.



3
4
5
# File 'app/models/searcher.rb', line 3

def search_object
  @search_object
end

#sunspotObject

Returns the value of attribute sunspot.



3
4
5
# File 'app/models/searcher.rb', line 3

def sunspot
  @sunspot
end

Instance Method Details

#boost_by(field, options = {}) ⇒ Object



60
61
62
63
64
65
# File 'app/models/searcher.rb', line 60

def boost_by(field, options={})
  boostificator = Boostificator.new(field, options)
  configuration.scope :runtime do |sunspot|
    boostificator.adjust_solr_params(sunspot)
  end
end

#each(&block) ⇒ Object



25
26
27
# File 'app/models/searcher.rb', line 25

def each(&block)
  results.each(&block)
end

#executeObject



72
73
74
75
76
77
78
79
# File 'app/models/searcher.rb', line 72

def execute
  unless @executed
    build_query
    set_facets
    sunspot.execute
    @executed = true
  end
end

#executed_sunspotObject



81
82
83
84
# File 'app/models/searcher.rb', line 81

def executed_sunspot
  execute
  sunspot
end

#limit(number) ⇒ Object Also known as: per_page, per



40
41
42
# File 'app/models/searcher.rb', line 40

def limit(number)
  paginate(:per_page => number)
end

#more_like_this(object, *types, &block) ⇒ Object



67
68
69
70
# File 'app/models/searcher.rb', line 67

def more_like_this(object, *types, &block)
  configuration.more_like_this(object, *types, &block)
  self
end

#order_by(name, type = :asc) ⇒ Object Also known as: order



33
34
35
36
37
# File 'app/models/searcher.rb', line 33

def order_by(name, type=:asc)
  configuration.scope :runtime do |sunspot|
    sunspot.order_by(name, type)
  end
end

#page(number) ⇒ Object



46
47
48
# File 'app/models/searcher.rb', line 46

def page(number)
  paginate(:page => number)
end

#paginate(params) ⇒ Object



50
51
52
53
54
# File 'app/models/searcher.rb', line 50

def paginate(params)
  configuration.scope :runtime do |sunspot|
    sunspot.paginate(params)
  end
end

#result_idsObject



29
30
31
# File 'app/models/searcher.rb', line 29

def result_ids
  executed_sunspot.hits.map(&:primary_key)
end

#scopedObject



56
57
58
# File 'app/models/searcher.rb', line 56

def scoped
  default.runtime
end