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


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

def initialize
  @facet_constraints, @facet_sort, @facet_top_n, @t, @rank_expressions = {}, {}, {}, {}, {}
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


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.


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.

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_rank_expression(expression_name, value) ⇒ Object

Adds a query time rank expression to the query. In order to use this rank expression, you are still required to include it in the rank value.

All expression names passed to this method are prefixed by 'rank-' For instance passing in 'expression1' will use 'rank-expression1' in the query to AWS CloudSearch.

For more information please see: docs.aws.amazon.com/cloudsearch/latest/developerguide/rankexpressionquery.html


54
55
56
# File 'lib/aws_cloud_search/search_request.rb', line 54

def add_rank_expression(expression_name, value)
  @rank_expressions['rank-'+expression_name] = value
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.

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.


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/aws_cloud_search/search_request.rb', line 60

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).merge(@rank_expressions)
end