Class: Dilute::Query
Instance Attribute Summary collapse
-
#chained ⇒ Object
readonly
Returns the value of attribute chained.
-
#for_class ⇒ Object
readonly
Returns the value of attribute for_class.
-
#from_elastic_search ⇒ Object
readonly
Returns the value of attribute from_elastic_search.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #each(*args, &block) ⇒ Object
- #execute! ⇒ Object
-
#initialize(for_class, options = {}, chained = true) ⇒ Query
constructor
A new instance of Query.
- #match(q) ⇒ Object
- #to_a ⇒ Object
- #to_query ⇒ Object
Constructor Details
#initialize(for_class, options = {}, chained = true) ⇒ Query
Returns a new instance of Query.
5 6 7 |
# File 'lib/dilute/query.rb', line 5 def initialize(for_class, = {}, chained = true) @for_class, @options, @chained = for_class, , chained end |
Instance Attribute Details
#chained ⇒ Object (readonly)
Returns the value of attribute chained.
2 3 4 |
# File 'lib/dilute/query.rb', line 2 def chained @chained end |
#for_class ⇒ Object (readonly)
Returns the value of attribute for_class.
2 3 4 |
# File 'lib/dilute/query.rb', line 2 def for_class @for_class end |
#from_elastic_search ⇒ Object (readonly)
Returns the value of attribute from_elastic_search.
2 3 4 |
# File 'lib/dilute/query.rb', line 2 def from_elastic_search @from_elastic_search end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/dilute/query.rb', line 2 def @options end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
2 3 4 |
# File 'lib/dilute/query.rb', line 2 def results @results end |
Instance Method Details
#each(*args, &block) ⇒ Object
32 33 34 35 |
# File 'lib/dilute/query.rb', line 32 def each(*args, &block) return enum_for(__callee__) unless block_given? to_a.each(*args, &block) end |
#execute! ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dilute/query.rb', line 19 def execute! @results ||= begin search_results = for_class.type.search(size: 25, query: to_query) @from_elastic_search = search_results search_results.raw["hits"]["hits"].collect {|r| for_class.new(r) } end end |
#match(q) ⇒ Object
9 10 11 |
# File 'lib/dilute/query.rb', line 9 def match(q) merge_or_chain(:match, q) end |
#to_a ⇒ Object
27 28 29 30 |
# File 'lib/dilute/query.rb', line 27 def to_a execute! results end |
#to_query ⇒ Object
13 14 15 16 17 |
# File 'lib/dilute/query.rb', line 13 def to_query query = .reject {|k,v| v.nil? || v.empty? } query[:match_all] ||= {} unless query[:match] query end |