Class: DaedalSL::Builder
Instance Attribute Summary collapse
Instance Method Summary
collapse
#and_filter, #bool_filter, #bool_query, #constant_score, #dis_max, #exists_filter, #filtered_query, #fuzzy, #geo_distance_filter, #match, #match_all, #multi_match, #nested_bool_filter, #nested_bool_query, #nested_dis_max_query, #or_filter, #prefix, #query_string, #range_filter, #term_filter, #terms_filter
Constructor Details
#initialize(data = nil) ⇒ Builder
Returns a new instance of Builder.
7
8
9
10
11
12
|
# File 'lib/daedal-sl/builder.rb', line 7
def initialize(data=nil)
@data = data
@query = match_all
@filter = nil
@options = {}
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/daedal-sl/builder.rb', line 5
def data
@data
end
|
Instance Method Details
#fields(*f) ⇒ Object
34
35
36
|
# File 'lib/daedal-sl/builder.rb', line 34
def fields(*f)
@options[:fields] = f
end
|
#filter ⇒ Object
20
21
22
23
24
|
# File 'lib/daedal-sl/builder.rb', line 20
def filter
if block_given?
@filter = yield
end
end
|
#from(num) ⇒ Object
26
27
28
|
# File 'lib/daedal-sl/builder.rb', line 26
def from(num)
@options[:from] = num
end
|
#paginate(options = {}) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/daedal-sl/builder.rb', line 38
def paginate(options={})
page = options[:page] || 1
per_page = options[:per_page] || 10
from ((page - 1) * per_page)
size per_page
end
|
#query ⇒ Object
14
15
16
17
18
|
# File 'lib/daedal-sl/builder.rb', line 14
def query
if block_given?
@query = yield
end
end
|
#size(num) ⇒ Object
30
31
32
|
# File 'lib/daedal-sl/builder.rb', line 30
def size(num)
@options[:size] = num
end
|
#to_hash ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/daedal-sl/builder.rb', line 46
def to_hash
result = {}
unless @query.nil?
result[:query] = @query.to_hash
end
unless @filter.nil?
result[:filter] = @filter.to_hash
end
result.merge(@options)
end
|