Module: Tire::Model::Suggest::ClassMethods

Included in:
Tire::Model::Search::ClassMethodsProxy
Defined in:
lib/tire/model/suggest.rb

Instance Method Summary collapse

Instance Method Details

#suggest(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tire/model/suggest.rb', line 5

def suggest(*args, &block)
  default_options = {:type => document_type, :index => index.name}

  if block_given?
    options = args.shift || {}
  else
    query, options = args
    options ||= {}
  end

  options = default_options.update(options)

  s = Tire::Suggest::Suggest.new(options.delete(:index), options)

  if block_given?
    block.arity < 1 ? s.instance_eval(&block) : block.call(s)
  else
    s.suggestion 'default_suggestion' do
      text query
      completion 'suggest'
    end
  end

  s.results

end