Class: ElasticQueue::QueryOptions
- Inherits:
-
Object
- Object
- ElasticQueue::QueryOptions
- Defined in:
- lib/elastic_queue/query_options.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
-
#sorts ⇒ Object
readonly
Returns the value of attribute sorts.
Instance Method Summary collapse
- #add_filter(options) ⇒ Object
- #add_search(string) ⇒ Object
- #add_sort(options) ⇒ Object
- #body ⇒ Object
- #from ⇒ Object
-
#initialize(options = {}) ⇒ QueryOptions
constructor
A new instance of QueryOptions.
- #percolator_body ⇒ Object
Methods included from Sorts
Methods included from Filters
Constructor Details
#initialize(options = {}) ⇒ QueryOptions
Returns a new instance of QueryOptions.
12 13 14 15 16 17 18 |
# File 'lib/elastic_queue/query_options.rb', line 12 def initialize( = {}) @options = { per_page: 30, page: 1 }.merge() @filters = { and: [] }.with_indifferent_access @sorts = [] self.per_page = @options[:per_page] self.page = @options[:page] end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
9 10 11 |
# File 'lib/elastic_queue/query_options.rb', line 9 def filters @filters end |
#page ⇒ Object
Returns the value of attribute page.
9 10 11 |
# File 'lib/elastic_queue/query_options.rb', line 9 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
10 11 12 |
# File 'lib/elastic_queue/query_options.rb', line 10 def per_page @per_page end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
9 10 11 |
# File 'lib/elastic_queue/query_options.rb', line 9 def search @search end |
#sorts ⇒ Object (readonly)
Returns the value of attribute sorts.
9 10 11 |
# File 'lib/elastic_queue/query_options.rb', line 9 def sorts @sorts end |
Instance Method Details
#add_filter(options) ⇒ Object
20 21 22 |
# File 'lib/elastic_queue/query_options.rb', line 20 def add_filter() @filters[:and] += () end |
#add_search(string) ⇒ Object
28 29 30 |
# File 'lib/elastic_queue/query_options.rb', line 28 def add_search(string) @search = string end |
#add_sort(options) ⇒ Object
24 25 26 |
# File 'lib/elastic_queue/query_options.rb', line 24 def add_sort() @sorts += () end |
#body ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/elastic_queue/query_options.rb', line 40 def body b = {} b[:filter] = @filters unless @filters[:and].blank? b[:sort] = @sorts unless @sorts.blank? b[:query] = { query_string: { query: @search } } unless @search.blank? b end |
#from ⇒ Object
32 33 34 |
# File 'lib/elastic_queue/query_options.rb', line 32 def from (page - 1) * per_page end |
#percolator_body ⇒ Object
48 49 50 51 52 |
# File 'lib/elastic_queue/query_options.rb', line 48 def percolator_body b = {} b[:filter] = @filters unless @filters[:and].blank? { query: { constant_score: b } } end |