Class: Stretchy::Builders::ShellBuilder
- Inherits:
-
Object
- Object
- Stretchy::Builders::ShellBuilder
- Defined in:
- lib/stretchy/builders/shell_builder.rb
Constant Summary collapse
- DEFAULT_LIMIT =
30
- DEFAULT_OFFSET =
0
Instance Attribute Summary collapse
-
#aggregate_builder ⇒ Object
Returns the value of attribute aggregate_builder.
-
#boost_builder ⇒ Object
Returns the value of attribute boost_builder.
-
#explain ⇒ Object
Returns the value of attribute explain.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#index ⇒ Object
Returns the value of attribute index.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#match_builder ⇒ Object
Returns the value of attribute match_builder.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#type ⇒ Object
Returns the value of attribute type.
-
#where_builder ⇒ Object
Returns the value of attribute where_builder.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ShellBuilder
constructor
A new instance of ShellBuilder.
- #page ⇒ Object (also: #current_page)
-
#to_search ⇒ Hash
Compiles the internal representation of your filters, full-text queries, and boosts into the JSON to be passed to Elastic.
Constructor Details
#initialize(options = {}) ⇒ ShellBuilder
Returns a new instance of ShellBuilder.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/stretchy/builders/shell_builder.rb', line 12 def initialize( = {}) @index = [:index] || Stretchy.index_name @match_builder = Stretchy::Builders::MatchBuilder.new @where_builder = Stretchy::Builders::WhereBuilder.new @boost_builder = Stretchy::Builders::BoostBuilder.new @aggregate_builder = {} @limit = [:limit] || DEFAULT_LIMIT @offset = [:offset] || DEFAULT_OFFSET @fields = [:fields] @type = [:type] end |
Instance Attribute Details
#aggregate_builder ⇒ Object
Returns the value of attribute aggregate_builder.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def aggregate_builder @aggregate_builder end |
#boost_builder ⇒ Object
Returns the value of attribute boost_builder.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def boost_builder @boost_builder end |
#explain ⇒ Object
Returns the value of attribute explain.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def explain @explain end |
#fields ⇒ Object
Returns the value of attribute fields.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def fields @fields end |
#index ⇒ Object
Returns the value of attribute index.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def index @index end |
#limit ⇒ Object
Returns the value of attribute limit.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def limit @limit end |
#match_builder ⇒ Object
Returns the value of attribute match_builder.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def match_builder @match_builder end |
#offset ⇒ Object
Returns the value of attribute offset.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def offset @offset end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def type @type end |
#where_builder ⇒ Object
Returns the value of attribute where_builder.
8 9 10 |
# File 'lib/stretchy/builders/shell_builder.rb', line 8 def where_builder @where_builder end |
Instance Method Details
#page ⇒ Object Also known as: current_page
24 25 26 |
# File 'lib/stretchy/builders/shell_builder.rb', line 24 def page (offset.to_f / limit).ceil + 1 end |
#to_search ⇒ Hash
Compiles the internal representation of your filters, full-text queries, and boosts into the JSON to be passed to Elastic. If you want to know exactly what your query generated, you can call this method.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stretchy/builders/shell_builder.rb', line 37 def to_search _to_search = if where_builder.any? Stretchy::Queries::FilteredQuery.new( query: match_builder.to_query, filter: where_builder.to_filter ) else match_builder.to_query end _to_search = boost_builder.to_search(_to_search) if boost_builder.any? _to_search.to_search end |