Class: Slingshot::Search::Facet
- Inherits:
-
Object
- Object
- Slingshot::Search::Facet
- Defined in:
- lib/slingshot/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
-
#initialize(name, options = {}, &block) ⇒ Facet
constructor
A new instance of Facet.
- #terms(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/slingshot/search/facet.rb', line 11 def initialize(name, ={}, &block) @name = name @options = self.instance_eval(&block) if block_given? end |
Instance Method Details
#date(field, options = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/slingshot/search/facet.rb', line 24 def date(field, ={}) interval = .delete(:interval) || 'day' @value = { :date_histogram => { :field => field, :interval => interval } }.update() self end |
#terms(field, options = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/slingshot/search/facet.rb', line 17 def terms(field, ={}) size = .delete(:size) || 10 all_terms = .delete(:all_terms) || false @value = { :terms => { :field => field, :size => size, :all_terms => all_terms } }.update() self end |
#to_hash ⇒ Object
34 35 36 37 |
# File 'lib/slingshot/search/facet.rb', line 34 def to_hash @value.update @options { @name => @value } end |
#to_json ⇒ Object
30 31 32 |
# File 'lib/slingshot/search/facet.rb', line 30 def to_json to_hash.to_json end |