Class: Stretchy::Builders::ShellBuilder
- Inherits:
-
Object
- Object
- Stretchy::Builders::ShellBuilder
- Extended by:
- Forwardable
- 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.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stretchy/builders/shell_builder.rb', line 17 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.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def aggregate_builder @aggregate_builder end |
#boost_builder ⇒ Object
Returns the value of attribute boost_builder.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def boost_builder @boost_builder end |
#explain ⇒ Object
Returns the value of attribute explain.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def explain @explain end |
#fields ⇒ Object
Returns the value of attribute fields.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def fields @fields end |
#index ⇒ Object
Returns the value of attribute index.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def index @index end |
#limit ⇒ Object
Returns the value of attribute limit.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def limit @limit end |
#match_builder ⇒ Object
Returns the value of attribute match_builder.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def match_builder @match_builder end |
#offset ⇒ Object
Returns the value of attribute offset.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def offset @offset end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def type @type end |
#where_builder ⇒ Object
Returns the value of attribute where_builder.
10 11 12 |
# File 'lib/stretchy/builders/shell_builder.rb', line 10 def where_builder @where_builder end |
Instance Method Details
#page ⇒ Object Also known as: current_page
29 30 31 |
# File 'lib/stretchy/builders/shell_builder.rb', line 29 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.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/stretchy/builders/shell_builder.rb', line 42 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 |