sunspot 1.3.3 → 2.0.0.pre.111215
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -10
- data/lib/sunspot/configuration.rb +5 -0
- data/lib/sunspot/dsl/field_group.rb +37 -0
- data/lib/sunspot/dsl/field_query.rb +48 -0
- data/lib/sunspot/dsl/restriction_with_near.rb +17 -0
- data/lib/sunspot/dsl.rb +1 -1
- data/lib/sunspot/query/common_query.rb +10 -0
- data/lib/sunspot/query/dismax.rb +5 -1
- data/lib/sunspot/query/field_group.rb +35 -0
- data/lib/sunspot/query/geofilt.rb +15 -0
- data/lib/sunspot/query/sort.rb +14 -0
- data/lib/sunspot/query/sort_composite.rb +3 -2
- data/lib/sunspot/query.rb +2 -2
- data/lib/sunspot/search/abstract_search.rb +52 -64
- data/lib/sunspot/search/field_group.rb +32 -0
- data/lib/sunspot/search/group.rb +35 -0
- data/lib/sunspot/search/hit_enumerable.rb +72 -0
- data/lib/sunspot/search/paginated_collection.rb +5 -3
- data/lib/sunspot/search.rb +1 -1
- data/lib/sunspot/session_proxy.rb +0 -8
- data/lib/sunspot/type.rb +21 -0
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/class_set_spec.rb +1 -1
- data/spec/api/hit_enumerable_spec.rb +47 -0
- data/spec/api/query/group_spec.rb +32 -0
- data/spec/api/query/ordering_pagination_examples.rb +7 -0
- data/spec/api/query/spatial_examples.rb +11 -0
- data/spec/api/query/standard_spec.rb +1 -0
- data/spec/api/search/paginated_collection_spec.rb +10 -0
- data/spec/api/search/results_spec.rb +6 -0
- data/spec/integration/field_grouping_spec.rb +65 -0
- data/spec/integration/geospatial_spec.rb +59 -0
- data/spec/integration/highlighting_spec.rb +20 -0
- data/spec/mocks/post.rb +1 -0
- data/sunspot.gemspec +2 -1
- metadata +54 -34
- data/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +0 -67
- data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +0 -73
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'abstract_session_proxy')
|
2
|
-
|
3
|
-
module Sunspot
|
4
|
-
module SessionProxy
|
5
|
-
class Retry5xxSessionProxy < AbstractSessionProxy
|
6
|
-
|
7
|
-
class RetryHandler
|
8
|
-
attr_reader :search_session
|
9
|
-
|
10
|
-
def initialize(search_session)
|
11
|
-
@search_session = search_session
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(m, *args, &block)
|
15
|
-
retry_count = 1
|
16
|
-
begin
|
17
|
-
search_session.send(m, *args, &block)
|
18
|
-
rescue Errno::ECONNRESET => e
|
19
|
-
if retry_count > 0
|
20
|
-
$stderr.puts "Error - #{e.message[/^.*$/]} - retrying..."
|
21
|
-
retry_count -= 1
|
22
|
-
retry
|
23
|
-
else
|
24
|
-
$stderr.puts "Error - #{e.message[/^.*$/]} - ignoring..."
|
25
|
-
end
|
26
|
-
rescue RSolr::Error::Http => e
|
27
|
-
if (500..599).include?(e.response[:status].to_i)
|
28
|
-
if retry_count > 0
|
29
|
-
$stderr.puts "Error - #{e.message[/^.*$/]} - retrying..."
|
30
|
-
retry_count -= 1
|
31
|
-
retry
|
32
|
-
else
|
33
|
-
$stderr.puts "Error - #{e.message[/^.*$/]} - ignoring..."
|
34
|
-
e.response
|
35
|
-
end
|
36
|
-
else
|
37
|
-
raise e
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
attr_reader :search_session
|
44
|
-
attr_reader :retry_handler
|
45
|
-
|
46
|
-
delegate :new_search, :search, :config,
|
47
|
-
:new_more_like_this, :more_like_this,
|
48
|
-
:delete_dirty, :delete_dirty?,
|
49
|
-
:to => :search_session
|
50
|
-
|
51
|
-
def initialize(search_session = Sunspot.session)
|
52
|
-
@search_session = search_session
|
53
|
-
@retry_handler = RetryHandler.new(search_session)
|
54
|
-
end
|
55
|
-
|
56
|
-
def rescued_exception(method, e)
|
57
|
-
$stderr.puts("Exception in #{method}: #{e.message}")
|
58
|
-
end
|
59
|
-
|
60
|
-
delegate :batch, :commit, :commit_if_dirty, :commit_if_delete_dirty,
|
61
|
-
:dirty?, :index!, :index, :optimize, :remove!, :remove, :remove_all!,
|
62
|
-
:remove_all, :remove_by_id!, :remove_by_id,
|
63
|
-
:to => :retry_handler
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
describe Sunspot::SessionProxy::Retry5xxSessionProxy do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
Sunspot::Session.connection_class = Mock::ConnectionFactory.new
|
7
|
-
@sunspot_session = Sunspot.session
|
8
|
-
@proxy = Sunspot::SessionProxy::Retry5xxSessionProxy.new(@sunspot_session)
|
9
|
-
Sunspot.session = @proxy
|
10
|
-
end
|
11
|
-
|
12
|
-
class FakeRSolrErrorHttp < RSolr::Error::Http
|
13
|
-
def backtrace
|
14
|
-
[]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let :fake_rsolr_request do
|
19
|
-
{:uri => 'http://solr.test/uri'}
|
20
|
-
end
|
21
|
-
|
22
|
-
def fake_rsolr_response(status)
|
23
|
-
{:status => status.to_s}
|
24
|
-
end
|
25
|
-
|
26
|
-
let :post do
|
27
|
-
Post.new(:title => 'test')
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should behave normally without a stubbed exception" do
|
31
|
-
@sunspot_session.should_receive(:index).and_return(mock)
|
32
|
-
Sunspot.index(post)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should be successful with a single exception followed by a sucess" do
|
36
|
-
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(503))
|
37
|
-
@sunspot_session.should_receive(:index).and_return do
|
38
|
-
@sunspot_session.should_receive(:index).and_return(mock)
|
39
|
-
raise e
|
40
|
-
end
|
41
|
-
Sunspot.index(post)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return the error response after two exceptions" do
|
45
|
-
fake_response = fake_rsolr_response(503)
|
46
|
-
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_response)
|
47
|
-
fake_success = mock('success')
|
48
|
-
|
49
|
-
@sunspot_session.should_receive(:index).and_return do
|
50
|
-
@sunspot_session.should_receive(:index).and_return do
|
51
|
-
@sunspot_session.stub!(:index).and_return(fake_success)
|
52
|
-
raise e
|
53
|
-
end
|
54
|
-
raise e
|
55
|
-
end
|
56
|
-
|
57
|
-
response = Sunspot.index(post)
|
58
|
-
response.should_not == fake_success
|
59
|
-
response.should == fake_response
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not retry a 4xx" do
|
63
|
-
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(400))
|
64
|
-
@sunspot_session.should_receive(:index).and_raise(e)
|
65
|
-
lambda { Sunspot.index(post) }.should raise_error
|
66
|
-
end
|
67
|
-
|
68
|
-
# TODO: try against more than just Sunspot.index? but that's just testing the
|
69
|
-
# invocation of delegate, so probably not important. -nz 11Apr12
|
70
|
-
|
71
|
-
it_should_behave_like 'session proxy'
|
72
|
-
|
73
|
-
end
|