Class: AWSCloudSearch::SearchRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_cloud_search/search_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSearchRequest

Returns a new instance of SearchRequest.



7
8
9
# File 'lib/aws_cloud_search/search_request.rb', line 7

def initialize
  @facet_constraints, @facet_sort, @facet_top_n, @t = {}, {}, {}, {}
end

Instance Attribute Details

#bqObject

Returns the value of attribute bq.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def bq
  @bq
end

#facetObject

Returns the value of attribute facet.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def facet
  @facet
end

#facet_constraintsObject

Returns the value of attribute facet_constraints.



5
6
7
# File 'lib/aws_cloud_search/search_request.rb', line 5

def facet_constraints
  @facet_constraints
end

#facet_sortObject

Returns the value of attribute facet_sort.



5
6
7
# File 'lib/aws_cloud_search/search_request.rb', line 5

def facet_sort
  @facet_sort
end

#facet_top_nObject

Returns the value of attribute facet_top_n.



5
6
7
# File 'lib/aws_cloud_search/search_request.rb', line 5

def facet_top_n
  @facet_top_n
end

#qObject

Returns the value of attribute q.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def q
  @q
end

#rankObject

Returns the value of attribute rank.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def rank
  @rank
end

#results_typeObject

Returns the value of attribute results_type.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def results_type
  @results_type
end

#return_fieldsObject

Returns the value of attribute return_fields.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def return_fields
  @return_fields
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def size
  @size
end

#startObject

Returns the value of attribute start.



4
5
6
# File 'lib/aws_cloud_search/search_request.rb', line 4

def start
  @start
end

#tObject

Returns the value of attribute t.



5
6
7
# File 'lib/aws_cloud_search/search_request.rb', line 5

def t
  @t
end

Instance Method Details

#add_facet_constraints(field, constraints) ⇒ Object

Specifies the facet constraints for a field

Parameters:

  • field (String)

    The field for which to add the facet constraints

  • constraints (String)

    The facet contraints



14
15
16
# File 'lib/aws_cloud_search/search_request.rb', line 14

def add_facet_constraints(field, constraints)
  @facet_constraints["facet-#{field}-constraints"] = constraints
end

#add_facet_sort(field, sort) ⇒ Object

Specifies how to sort a facet field.

Parameters:

  • field (String)

    The field for which to add the facet sort

  • sort (String)

    The facet sort method: alpha, count, max, sum



21
22
23
# File 'lib/aws_cloud_search/search_request.rb', line 21

def add_facet_sort(field, sort)
  @facet_sort["facet-#{field}-sort"] = sort
end

#add_facet_top_n(field, top_n) ⇒ Object

Specifies how many facet constraints to return.

Parameters:

  • field (String)

    The field for which to add the facet top n constraints.

  • top_n (Integer)

    The maximum number of facet constraints to add for a field.

Raises:

  • (ArgumentError)


28
29
30
31
# File 'lib/aws_cloud_search/search_request.rb', line 28

def add_facet_top_n(field, top_n)
  raise ArgumentError.new("top_n must be of type Integer") unless top_n.kind_of? Integer
  @facet_top_n["facet-#{field}-top-n"] = top_n
end

#add_t(field, t_from, t_to) ⇒ Object

Restricts the records returned based on the values from the rank expression. The t-field value is a range.

Parameters:

  • field (String)

    The field for which to add.

  • t_from (Integer)

    Beginning of the range, may be nil or blank string.

  • t_to (Integer)

    End of the range, may be nil or blank string.

Raises:

  • (ArgumentError)


37
38
39
40
41
# File 'lib/aws_cloud_search/search_request.rb', line 37

def add_t(field, t_from, t_to)
  raise ArgumentError.new("Range must have a beginning or ending value or both.") if t_from.nil? and t_to.nil?
  raise ArgumentError.new("Range values must be of type Integer") unless t_from.kind_of? Integer and t_to.kind_of? Integer
  @t["t-#{field}"] = "#{t_from}..#{t_to}"
end

#to_hashHash

Returns the hash of all the values for this SearchRequest. Useful for creating URL params.

Returns:

  • (Hash)

    The object converted to a Hash



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/aws_cloud_search/search_request.rb', line 45

def to_hash
  hash = {}
  hash['q']     = @q unless @q.nil?
  hash['bq']    = @bq unless @bq.nil?
  hash['rank']  = @rank unless @rank.nil?
  hash['size']  = @size unless @size.nil?
  hash['start'] = @start unless @start.nil?
  hash['results-type']  = @results_type unless @results_type.nil?
  hash['return-fields'] = @return_fields.join(',') unless @return_fields.nil?
  hash['facet'] = @facet unless @facet.nil?
  hash.merge(@facet_constraints).merge(@facet_sort).merge(@facet_top_n).merge(@t)
end