Class: Tire::Suggest::PhraseSuggester

Inherits:
Object
  • Object
show all
Defined in:
lib/tire/suggest/suggestion.rb

Overview

Used to generate phrase suggestions

Instance Method Summary collapse

Constructor Details

#initialize(field, options = {}, &block) ⇒ PhraseSuggester

Returns a new instance of PhraseSuggester.



46
47
48
49
50
# File 'lib/tire/suggest/suggestion.rb', line 46

def initialize(field, options={}, &block)
  @options = options
  @value   = { :field => field }
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

Instance Method Details

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



52
53
54
55
56
# File 'lib/tire/suggest/suggestion.rb', line 52

def generator(field, options={})
  @generators ||= []
  @generators << { :field => field }.update(options).to_hash
  self
end

#smoothing(type, options = {}) ⇒ Object



58
59
60
# File 'lib/tire/suggest/suggestion.rb', line 58

def smoothing(type, options={})
  @value[:smoothing] = { type => options }
end

#to_hashObject



66
67
68
69
70
71
# File 'lib/tire/suggest/suggestion.rb', line 66

def to_hash
  @value.update(@options)
  @value.update( { :direct_generator => @generators } ) if @generators && @generators.size > 0

  @value
end

#to_json(options = {}) ⇒ Object



62
63
64
# File 'lib/tire/suggest/suggestion.rb', line 62

def to_json(options={})
  to_hash.to_json
end