Class: Tire::Search::Facet
- Inherits:
-
Object
- Object
- Tire::Search::Facet
- Defined in:
- lib/tire/search/facet.rb
Instance Method Summary collapse
- #date(field, options = {}) ⇒ Object
- #facet_filter(type, *options) ⇒ Object
- #filter(type, options = {}) ⇒ Object
- #geo_distance(field, point, ranges = [], options = {}) ⇒ Object
- #histogram(field, options = {}) ⇒ Object
-
#initialize(name, options = {}, &block) ⇒ Facet
constructor
A new instance of Facet.
- #query(&block) ⇒ Object
- #range(field, ranges = [], options = {}) ⇒ Object
- #statistical(field, options = {}) ⇒ Object
- #terms(field, options = {}) ⇒ Object
- #terms_stats(key_field, value_field, options = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Facet
Returns a new instance of Facet.
6 7 8 9 10 11 |
# File 'lib/tire/search/facet.rb', line 6 def initialize(name, ={}, &block) @name = name @options = @value = {} block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given? end |
Instance Method Details
#date(field, options = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/tire/search/facet.rb', line 24 def date(field, ={}) interval = { :interval => .delete(:interval) || 'day' } fields = [:value_field] || [:value_script] ? { :key_field => field } : { :field => field } @value[:date_histogram] = {}.update(fields).update(interval).update() self end |
#facet_filter(type, *options) ⇒ Object
65 66 67 68 |
# File 'lib/tire/search/facet.rb', line 65 def facet_filter(type, *) @value[:facet_filter] = Filter.new(type, *).to_hash self end |
#filter(type, options = {}) ⇒ Object
60 61 62 63 |
# File 'lib/tire/search/facet.rb', line 60 def filter(type, ={}) @value[:filter] = Filter.new(type, ) self end |
#geo_distance(field, point, ranges = [], options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/tire/search/facet.rb', line 46 def geo_distance(field, point, ranges=[], ={}) @value[:geo_distance] = { field => point, :ranges => ranges }.update() self end |
#histogram(field, options = {}) ⇒ Object
36 37 38 39 |
# File 'lib/tire/search/facet.rb', line 36 def histogram(field, ={}) @value[:histogram] = (.delete(:histogram) || {:field => field}.update()) self end |
#query(&block) ⇒ Object
56 57 58 |
# File 'lib/tire/search/facet.rb', line 56 def query(&block) @value[:query] = Query.new(&block).to_hash end |
#range(field, ranges = [], options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/tire/search/facet.rb', line 31 def range(field, ranges=[], ={}) @value[:range] = { :field => field, :ranges => ranges }.update() self end |
#statistical(field, options = {}) ⇒ Object
41 42 43 44 |
# File 'lib/tire/search/facet.rb', line 41 def statistical(field, ={}) @value[:statistical] = (.delete(:statistical) || {:field => field}.update()) self end |
#terms(field, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tire/search/facet.rb', line 13 def terms(field, ={}) size = .delete(:size) || 10 all_terms = .delete(:all_terms) || false @value[:terms] = if field.is_a?(Enumerable) and not field.is_a?(String) { :fields => field }.update({ :size => size, :all_terms => all_terms }).update() else { :field => field }.update({ :size => size, :all_terms => all_terms }).update() end self end |
#terms_stats(key_field, value_field, options = {}) ⇒ Object
51 52 53 54 |
# File 'lib/tire/search/facet.rb', line 51 def terms_stats(key_field, value_field, ={}) @value[:terms_stats] = {:key_field => key_field, :value_field => value_field}.update() self end |
#to_hash ⇒ Object
74 75 76 77 |
# File 'lib/tire/search/facet.rb', line 74 def to_hash @value.update @options { @name => @value } end |
#to_json(options = {}) ⇒ Object
70 71 72 |
# File 'lib/tire/search/facet.rb', line 70 def to_json(={}) to_hash.to_json end |