class Tire::Search::Facet

Public Class Methods

new(name, options={}, &block) click to toggle source
# File lib/tire/search/facet.rb, line 11
def initialize(name, options={}, &block)
  @name    = name
  @options = options
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

Public Instance Methods

date(field, options={}) click to toggle source
# File lib/tire/search/facet.rb, line 24
def date(field, options={})
  interval = options.delete(:interval) || 'day'
  @value = { :date_histogram => { :field => field, :interval => interval }.update(options) }
  self
end
histogram(field, options={}) click to toggle source
# File lib/tire/search/facet.rb, line 35
def histogram(field, options={})
  @value = { :histogram => (options.delete(:histogram) || {:field => field}.update(options)) }
  self
end
query(&block) click to toggle source
# File lib/tire/search/facet.rb, line 40
def query(&block)
  @value = { :query => Query.new(&block).to_hash }
end
range(field, ranges=[], options={}) click to toggle source
# File lib/tire/search/facet.rb, line 30
def range(field, ranges=[], options={})
  @value = { :range => { :field => field, :ranges => ranges }.update(options) }
  self
end
terms(field, options={}) click to toggle source
# File lib/tire/search/facet.rb, line 17
def terms(field, options={})
  size      = options.delete(:size) || 10
  all_terms = options.delete(:all_terms) || false
  @value = { :terms => { :field => field, :size => size, :all_terms => all_terms }.update(options) }
  self
end
to_hash() click to toggle source
# File lib/tire/search/facet.rb, line 48
def to_hash
  @value.update @options
  { @name => @value }
end
to_json() click to toggle source
# File lib/tire/search/facet.rb, line 44
def to_json
  to_hash.to_json
end