Class: Tire::Search::Facet
- Inherits:
-
Object
- Object
- Tire::Search::Facet
- Defined in:
- lib/tire/search/facet.rb
Overview
– TODO: Implement all elastic search facets (geo, histogram, range, etc) elasticsearch.org/guide/reference/api/search/facets/ ++
Instance Method Summary collapse
- #date(field, options = {}) ⇒ Object
- #filter(field, value, 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 ⇒ Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Facet
Returns a new instance of Facet.
11 12 13 14 15 |
# File 'lib/tire/search/facet.rb', line 11 def initialize(name, ={}, &block) @name = name @options = block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given? end |
Instance Method Details
#date(field, options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/tire/search/facet.rb', line 28 def date(field, ={}) interval = .delete(:interval) || 'day' @value = { :date_histogram => { :field => field, :interval => interval }.update() } self end |
#filter(field, value, options = {}) ⇒ Object
58 59 60 61 |
# File 'lib/tire/search/facet.rb', line 58 def filter(field, value, ={}) @value = { :filter => { :term => { field => value }}.update() } self end |
#histogram(field, options = {}) ⇒ Object
39 40 41 42 |
# File 'lib/tire/search/facet.rb', line 39 def histogram(field, ={}) @value = { :histogram => (.delete(:histogram) || {:field => field}.update()) } self end |
#query(&block) ⇒ Object
54 55 56 |
# File 'lib/tire/search/facet.rb', line 54 def query(&block) @value = { :query => Query.new(&block).to_hash } end |
#range(field, ranges = [], options = {}) ⇒ Object
34 35 36 37 |
# File 'lib/tire/search/facet.rb', line 34 def range(field, ranges=[], ={}) @value = { :range => { :field => field, :ranges => ranges }.update() } self end |
#statistical(field, options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/tire/search/facet.rb', line 44 def statistical(field, ={}) @value = { :statistical => (.delete(:statistical) || {:field => field}.update()) } self end |
#terms(field, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tire/search/facet.rb', line 17 def terms(field, ={}) size = .delete(:size) || 10 all_terms = .delete(:all_terms) || false @value = if field.is_a?(Enumerable) and not field.is_a?(String) { :terms => { :fields => field }.update({ :size => size, :all_terms => all_terms }).update() } else { :terms => { :field => field }.update({ :size => size, :all_terms => all_terms }).update() } end self end |
#terms_stats(key_field, value_field, options = {}) ⇒ Object
49 50 51 52 |
# File 'lib/tire/search/facet.rb', line 49 def terms_stats(key_field, value_field, ={}) @value = { :terms_stats => {:key_field => key_field, :value_field => value_field}.update() } self end |
#to_hash ⇒ Object
67 68 69 70 |
# File 'lib/tire/search/facet.rb', line 67 def to_hash @value.update @options { @name => @value } end |
#to_json ⇒ Object
63 64 65 |
# File 'lib/tire/search/facet.rb', line 63 def to_json to_hash.to_json end |