Class: DaedalSL::Builder

Inherits:
Object
  • Object
show all
Includes:
QueryHelpers
Defined in:
lib/daedal-sl/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from QueryHelpers

#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

#dataObject (readonly)

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

#filterObject



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

#queryObject



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_hashObject



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