class ElasticQueue::QueryOptions
Attributes
filters[R]
page[R]
per_page[RW]
search[R]
sorts[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/elastic_queue/query_options.rb, line 12 def initialize(options = {}) @options = { per_page: 30, page: 1 }.merge(options) @filters = { and: [] }.with_indifferent_access @sorts = [] self.per_page = @options[:per_page] self.page = @options[:page] end
Public Instance Methods
add_filter(options)
click to toggle source
# File lib/elastic_queue/query_options.rb, line 20 def add_filter(options) @filters[:and] += options_to_filters(options) end
add_search(string)
click to toggle source
# File lib/elastic_queue/query_options.rb, line 28 def add_search(string) @search = string end
add_sort(options)
click to toggle source
# File lib/elastic_queue/query_options.rb, line 24 def add_sort(options) @sorts += options_to_sorts(options) end
body()
click to toggle source
# 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()
click to toggle source
# File lib/elastic_queue/query_options.rb, line 32 def from (page - 1) * per_page end
page=(num)
click to toggle source
# File lib/elastic_queue/query_options.rb, line 36 def page=(num) @page = num.to_i unless num.blank? end
percolator_body()
click to toggle source
# 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