aws_cloud_search 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Rakefile +2 -0
- data/lib/aws_cloud_search/search_request.rb +42 -2
- data/lib/aws_cloud_search/search_response.rb +1 -1
- data/lib/aws_cloud_search/version.rb +1 -1
- data/spec/aws_cloud_search/search_request_spec.rb +30 -0
- metadata +20 -7
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@aws_cloud_search --create
|
data/Rakefile
CHANGED
@@ -1,8 +1,47 @@
|
|
1
1
|
module AWSCloudSearch
|
2
2
|
class SearchRequest
|
3
3
|
|
4
|
-
attr_accessor :q, :bq, :rank, :results_type, :return_fields, :size, :start
|
4
|
+
attr_accessor :q, :bq, :rank, :results_type, :return_fields, :size, :start, :facet
|
5
|
+
attr_accessor :facet_constraints, :facet_sort, :facet_top_n, :t
|
5
6
|
|
7
|
+
def initialize
|
8
|
+
@facet_constraints, @facet_sort, @facet_top_n, @t = {}, {}, {}, {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Specifies the facet constraints for a field
|
12
|
+
# @param [String] field The field for which to add the facet constraints
|
13
|
+
# @param [String] constraints The facet contraints
|
14
|
+
def add_facet_constraints(field, constraints)
|
15
|
+
@facet_constraints["facet-#{field}-constraints"] = constraints
|
16
|
+
end
|
17
|
+
|
18
|
+
# Specifies how to sort a facet field.
|
19
|
+
# @param [String] field The field for which to add the facet sort
|
20
|
+
# @param [String] sort The facet sort method: alpha, count, max, sum
|
21
|
+
def add_facet_sort(field, sort)
|
22
|
+
@facet_sort["facet-#{field}-sort"] = sort
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specifies how many facet constraints to return.
|
26
|
+
# @param [String] field The field for which to add the facet top n constraints.
|
27
|
+
# @param [Integer] top_n The maximum number of facet constraints to add for a field.
|
28
|
+
def add_facet_top_n(field, top_n)
|
29
|
+
raise ArgumentError.new("top_n must be of type Integer") unless top_n.kind_of? Integer
|
30
|
+
@facet_top_n["facet-#{field}-top-n"] = top_n
|
31
|
+
end
|
32
|
+
|
33
|
+
# Restricts the records returned based on the values from the rank expression. The t-field value is a range.
|
34
|
+
# @param [String] field The field for which to add.
|
35
|
+
# @param [Integer] t_from Beginning of the range, may be nil or blank string.
|
36
|
+
# @param [Integer] t_to End of the range, may be nil or blank string.
|
37
|
+
def add_t(field, t_from, t_to)
|
38
|
+
raise ArgumentError.new("Range must have a beginning or ending value or both.") if t_from.nil? and t_to.nil?
|
39
|
+
raise ArgumentError.new("Range values must be of type Integer") unless t_from.kind_of? Integer and t_to.kind_of? Integer
|
40
|
+
@t["t-#{field}"] = "#{t_from}..#{t_to}"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the hash of all the values for this SearchRequest. Useful for creating URL params.
|
44
|
+
# @return [Hash] The object converted to a Hash
|
6
45
|
def to_hash
|
7
46
|
hash = {}
|
8
47
|
hash['q'] = @q unless @q.nil?
|
@@ -12,7 +51,8 @@ module AWSCloudSearch
|
|
12
51
|
hash['start'] = @start unless @start.nil?
|
13
52
|
hash['results-type'] = @results_type unless @results_type.nil?
|
14
53
|
hash['return-fields'] = @return_fields.join(',') unless @return_fields.nil?
|
15
|
-
hash
|
54
|
+
hash['facet'] = @facet unless @facet.nil?
|
55
|
+
hash.merge(@facet_constraints).merge(@facet_sort).merge(@facet_top_n).merge(@t)
|
16
56
|
end
|
17
57
|
|
18
58
|
end
|
@@ -6,7 +6,7 @@ module AWSCloudSearch
|
|
6
6
|
alias :results :hits
|
7
7
|
|
8
8
|
# error is an undocumented field that occurs when an error is returned
|
9
|
-
FIELDS = [ :match_expr, :rank, :cpu_time_ms, :time_ms, :rid, :found, :start, :error, :messages ].freeze
|
9
|
+
FIELDS = [ :match_expr, :rank, :cpu_time_ms, :time_ms, :rid, :found, :start, :error, :messages, :facets ].freeze
|
10
10
|
FIELDS.each { |f| attr_accessor f }
|
11
11
|
|
12
12
|
# Takes in the hash, representing the json object returned from a search request
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AWSCloudSearch::SearchResponse do
|
4
|
+
let(:search_req) { AWSCloudSearch::SearchRequest.new }
|
5
|
+
|
6
|
+
context "#add_facet_top_n" do
|
7
|
+
it "should raise ArgumentError when param is not an Integer" do
|
8
|
+
expect { search_req.add_facet_top_n("fieldname", "string") }.to raise_error(ArgumentError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#ad_t" do
|
13
|
+
it "should raise ArgumentError when range beginning and end are nil" do
|
14
|
+
expect {search_req.add_t("fieldname", nil, nil)}.to raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise ArgumentError when t_from or t_to are not an Integers" do
|
18
|
+
expect {search_req.add_t("fieldname", "string", 10)}.to raise_error(ArgumentError)
|
19
|
+
expect {search_req.add_t("fieldname", 10, "string")}.to raise_error(ArgumentError)
|
20
|
+
expect {search_req.add_t("fieldname", "string", "string")}.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "#to_hash" do
|
25
|
+
it "should return an empty hash" do
|
26
|
+
search_req.to_hash.should eq({})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_cloud_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday_middleware
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: 0.8.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.8.0
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: rspec
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
@@ -33,7 +38,12 @@ dependencies:
|
|
33
38
|
version: 2.6.0
|
34
39
|
type: :development
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.6.0
|
37
47
|
description: AWSCloudSearch Search gem
|
38
48
|
email:
|
39
49
|
- david.jensen@spoke.com
|
@@ -44,6 +54,7 @@ extra_rdoc_files: []
|
|
44
54
|
files:
|
45
55
|
- .gitignore
|
46
56
|
- .rspec
|
57
|
+
- .rvmrc
|
47
58
|
- Gemfile
|
48
59
|
- LICENSE
|
49
60
|
- README.md
|
@@ -62,6 +73,7 @@ files:
|
|
62
73
|
- spec/aws_cloud_search/cloud_search_spec.rb
|
63
74
|
- spec/aws_cloud_search/document_batch_spec.rb
|
64
75
|
- spec/aws_cloud_search/document_spec.rb
|
76
|
+
- spec/aws_cloud_search/search_request_spec.rb
|
65
77
|
- spec/aws_cloud_search/search_response_spec.rb
|
66
78
|
- spec/spec_helper.rb
|
67
79
|
homepage: ''
|
@@ -84,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
96
|
version: '0'
|
85
97
|
requirements: []
|
86
98
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.8.
|
99
|
+
rubygems_version: 1.8.24
|
88
100
|
signing_key:
|
89
101
|
specification_version: 3
|
90
102
|
summary: Implementation of the AWS CloudSearch API
|
@@ -92,5 +104,6 @@ test_files:
|
|
92
104
|
- spec/aws_cloud_search/cloud_search_spec.rb
|
93
105
|
- spec/aws_cloud_search/document_batch_spec.rb
|
94
106
|
- spec/aws_cloud_search/document_spec.rb
|
107
|
+
- spec/aws_cloud_search/search_request_spec.rb
|
95
108
|
- spec/aws_cloud_search/search_response_spec.rb
|
96
109
|
- spec/spec_helper.rb
|