asari 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,10 +50,21 @@ class Asari
50
50
  #
51
51
  # Raises: SearchException if there's an issue communicating the request to
52
52
  # the server.
53
- def search(term)
53
+ def search(term, options = {})
54
54
  return [] if self.class.mode == :sandbox
55
55
 
56
56
  url = "http://search-#{search_domain}.us-east-1.cloudsearch.amazonaws.com/#{api_version}/search?q=#{CGI.escape(term)}"
57
+
58
+ if options[:page_size]
59
+ url << "&size=#{options[:page_size]}"
60
+ end
61
+
62
+ if options[:page]
63
+ size = options[:page_size] || 10
64
+ start = (options[:page] - 1) * size + 1
65
+ url << "&start=#{start}"
66
+ end
67
+
57
68
  begin
58
69
  response = HTTParty.get(url)
59
70
  rescue Exception => e
@@ -100,8 +100,8 @@ class Asari
100
100
  #
101
101
  # Raises: an Asari::SearchException error if there are issues
102
102
  # communicating with the CloudSearch server.
103
- def asari_find(term)
104
- ids = self.asari_instance.search(term).map { |id| id.to_i }
103
+ def asari_find(term, options = {})
104
+ ids = self.asari_instance.search(term, options).map { |id| id.to_i }
105
105
  begin
106
106
  self.find(*ids)
107
107
  rescue ::ActiveRecord::RecordNotFound
@@ -1,3 +1,3 @@
1
1
  class Asari
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -18,6 +18,16 @@ describe Asari do
18
18
  @asari.search("testsearch!")
19
19
  end
20
20
 
21
+ it "honors the page_size option" do
22
+ HTTParty.should_receive(:get).with("http://search-testdomain.us-east-1.cloudsearch.amazonaws.com/2011-02-01/search?q=testsearch&size=20")
23
+ @asari.search("testsearch", :page_size => 20)
24
+ end
25
+
26
+ it "honors the page option" do
27
+ HTTParty.should_receive(:get).with("http://search-testdomain.us-east-1.cloudsearch.amazonaws.com/2011-02-01/search?q=testsearch&size=20&start=41")
28
+ @asari.search("testsearch", :page_size => 20, :page => 3)
29
+ end
30
+
21
31
  it "returns a list of document IDs for search results." do
22
32
  expect(@asari.search("testsearch")).to eq(["123","456"])
23
33
  end
@@ -36,5 +46,6 @@ describe Asari do
36
46
  HTTParty.stub(:get).and_raise(SocketError.new)
37
47
  expect { @asari.search("testsearch)") }.to raise_error Asari::SearchException
38
48
  end
49
+
39
50
  end
40
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70351657843560 !ruby/object:Gem::Requirement
16
+ requirement: &70161865408960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70351657843560
24
+ version_requirements: *70161865408960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70351657841900 !ruby/object:Gem::Requirement
27
+ requirement: &70161865407860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70351657841900
35
+ version_requirements: *70161865407860
36
36
  description: Asari s a Ruby interface for AWS CloudSearch
37
37
  email:
38
38
  - tommy@wellbredgrapefruit.com