sunspot 2.0.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -2
- data/History.txt +10 -0
- data/lib/sunspot.rb +55 -17
- data/lib/sunspot/adapters.rb +68 -18
- data/lib/sunspot/batcher.rb +1 -1
- data/lib/sunspot/configuration.rb +4 -2
- data/lib/sunspot/data_extractor.rb +36 -6
- data/lib/sunspot/dsl.rb +4 -3
- data/lib/sunspot/dsl/adjustable.rb +2 -2
- data/lib/sunspot/dsl/field_query.rb +69 -16
- data/lib/sunspot/dsl/field_stats.rb +25 -0
- data/lib/sunspot/dsl/fields.rb +28 -8
- data/lib/sunspot/dsl/fulltext.rb +9 -1
- data/lib/sunspot/dsl/group.rb +118 -0
- data/lib/sunspot/dsl/paginatable.rb +4 -1
- data/lib/sunspot/dsl/scope.rb +19 -10
- data/lib/sunspot/dsl/search.rb +1 -1
- data/lib/sunspot/dsl/spellcheckable.rb +14 -0
- data/lib/sunspot/dsl/standard_query.rb +63 -35
- data/lib/sunspot/field.rb +76 -4
- data/lib/sunspot/field_factory.rb +60 -11
- data/lib/sunspot/indexer.rb +70 -18
- data/lib/sunspot/query.rb +5 -4
- data/lib/sunspot/query/abstract_field_facet.rb +0 -2
- data/lib/sunspot/query/abstract_fulltext.rb +76 -0
- data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
- data/lib/sunspot/query/bbox.rb +5 -1
- data/lib/sunspot/query/common_query.rb +31 -6
- data/lib/sunspot/query/composite_fulltext.rb +58 -8
- data/lib/sunspot/query/date_field_json_facet.rb +25 -0
- data/lib/sunspot/query/dismax.rb +25 -71
- data/lib/sunspot/query/field_json_facet.rb +19 -0
- data/lib/sunspot/query/field_list.rb +15 -0
- data/lib/sunspot/query/field_stats.rb +61 -0
- data/lib/sunspot/query/function_query.rb +1 -2
- data/lib/sunspot/query/geo.rb +1 -1
- data/lib/sunspot/query/geofilt.rb +8 -3
- data/lib/sunspot/query/group.rb +46 -0
- data/lib/sunspot/query/group_query.rb +17 -0
- data/lib/sunspot/query/join.rb +88 -0
- data/lib/sunspot/query/more_like_this.rb +1 -1
- data/lib/sunspot/query/pagination.rb +12 -4
- data/lib/sunspot/query/range_json_facet.rb +28 -0
- data/lib/sunspot/query/restriction.rb +99 -13
- data/lib/sunspot/query/sort.rb +41 -0
- data/lib/sunspot/query/sort_composite.rb +7 -0
- data/lib/sunspot/query/spellcheck.rb +19 -0
- data/lib/sunspot/query/standard_query.rb +24 -2
- data/lib/sunspot/query/text_field_boost.rb +1 -3
- data/lib/sunspot/schema.rb +12 -3
- data/lib/sunspot/search.rb +4 -2
- data/lib/sunspot/search/abstract_search.rb +93 -43
- data/lib/sunspot/search/cursor_paginated_collection.rb +32 -0
- data/lib/sunspot/search/field_facet.rb +4 -4
- data/lib/sunspot/search/field_json_facet.rb +33 -0
- data/lib/sunspot/search/field_stats.rb +21 -0
- data/lib/sunspot/search/hit.rb +6 -1
- data/lib/sunspot/search/hit_enumerable.rb +4 -1
- data/lib/sunspot/search/json_facet_row.rb +40 -0
- data/lib/sunspot/search/json_facet_stats.rb +23 -0
- data/lib/sunspot/search/paginated_collection.rb +1 -0
- data/lib/sunspot/search/query_group.rb +74 -0
- data/lib/sunspot/search/standard_search.rb +70 -3
- data/lib/sunspot/search/stats_facet.rb +25 -0
- data/lib/sunspot/search/stats_json_row.rb +82 -0
- data/lib/sunspot/search/stats_row.rb +68 -0
- data/lib/sunspot/session.rb +62 -37
- data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +6 -4
- data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +16 -8
- data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +2 -2
- data/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/sharding_session_proxy.rb +4 -2
- data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +6 -4
- data/lib/sunspot/setup.rb +42 -0
- data/lib/sunspot/type.rb +20 -0
- data/lib/sunspot/util.rb +78 -14
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/adapters_spec.rb +40 -15
- data/spec/api/batcher_spec.rb +15 -15
- data/spec/api/binding_spec.rb +3 -3
- data/spec/api/class_set_spec.rb +6 -6
- data/spec/api/data_extractor_spec.rb +39 -0
- data/spec/api/hit_enumerable_spec.rb +32 -9
- data/spec/api/indexer/attributes_spec.rb +35 -30
- data/spec/api/indexer/batch_spec.rb +8 -7
- data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
- data/spec/api/indexer/fixed_fields_spec.rb +16 -11
- data/spec/api/indexer/fulltext_spec.rb +8 -8
- data/spec/api/indexer/removal_spec.rb +24 -14
- data/spec/api/indexer_spec.rb +2 -2
- data/spec/api/query/advanced_manipulation_examples.rb +3 -3
- data/spec/api/query/connectives_examples.rb +26 -14
- data/spec/api/query/dsl_spec.rb +24 -6
- data/spec/api/query/dynamic_fields_examples.rb +18 -18
- data/spec/api/query/faceting_examples.rb +80 -61
- data/spec/api/query/fulltext_examples.rb +194 -40
- data/spec/api/query/function_spec.rb +116 -13
- data/spec/api/query/geo_examples.rb +8 -12
- data/spec/api/query/group_spec.rb +27 -5
- data/spec/api/query/highlighting_examples.rb +26 -26
- data/spec/api/query/join_spec.rb +19 -0
- data/spec/api/query/more_like_this_spec.rb +40 -27
- data/spec/api/query/ordering_pagination_examples.rb +37 -23
- data/spec/api/query/scope_examples.rb +39 -39
- data/spec/api/query/spatial_examples.rb +3 -3
- data/spec/api/query/spellcheck_examples.rb +20 -0
- data/spec/api/query/standard_spec.rb +3 -1
- data/spec/api/query/stats_examples.rb +66 -0
- data/spec/api/query/text_field_scoping_examples.rb +5 -5
- data/spec/api/query/types_spec.rb +4 -4
- data/spec/api/search/cursor_paginated_collection_spec.rb +35 -0
- data/spec/api/search/dynamic_fields_spec.rb +4 -4
- data/spec/api/search/faceting_spec.rb +55 -52
- data/spec/api/search/highlighting_spec.rb +7 -7
- data/spec/api/search/hits_spec.rb +43 -29
- data/spec/api/search/paginated_collection_spec.rb +19 -18
- data/spec/api/search/results_spec.rb +13 -13
- data/spec/api/search/search_spec.rb +3 -3
- data/spec/api/search/stats_spec.rb +94 -0
- data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +23 -16
- data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +16 -4
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
- data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +11 -11
- data/spec/api/session_proxy/sharding_session_proxy_spec.rb +15 -14
- data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +3 -3
- data/spec/api/session_proxy/spec_helper.rb +1 -1
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +40 -26
- data/spec/api/session_spec.rb +78 -38
- data/spec/api/sunspot_spec.rb +7 -4
- data/spec/helpers/integration_helper.rb +11 -1
- data/spec/helpers/query_helper.rb +1 -1
- data/spec/helpers/search_helper.rb +30 -0
- data/spec/integration/atomic_updates_spec.rb +58 -0
- data/spec/integration/dynamic_fields_spec.rb +31 -20
- data/spec/integration/faceting_spec.rb +252 -39
- data/spec/integration/field_grouping_spec.rb +47 -15
- data/spec/integration/field_lists_spec.rb +57 -0
- data/spec/integration/geospatial_spec.rb +34 -8
- data/spec/integration/highlighting_spec.rb +8 -8
- data/spec/integration/indexing_spec.rb +7 -6
- data/spec/integration/join_spec.rb +45 -0
- data/spec/integration/keyword_search_spec.rb +68 -38
- data/spec/integration/local_search_spec.rb +4 -4
- data/spec/integration/more_like_this_spec.rb +7 -7
- data/spec/integration/scoped_search_spec.rb +193 -74
- data/spec/integration/spellcheck_spec.rb +119 -0
- data/spec/integration/stats_spec.rb +88 -0
- data/spec/integration/stored_fields_spec.rb +1 -1
- data/spec/integration/test_pagination.rb +4 -4
- data/spec/integration/unicode_spec.rb +1 -1
- data/spec/mocks/adapters.rb +36 -0
- data/spec/mocks/connection.rb +5 -3
- data/spec/mocks/photo.rb +32 -1
- data/spec/mocks/post.rb +18 -3
- data/spec/spec_helper.rb +13 -8
- data/sunspot.gemspec +6 -4
- data/tasks/rdoc.rake +22 -14
- metadata +101 -44
- data/lib/sunspot/dsl/field_group.rb +0 -57
- data/lib/sunspot/query/field_group.rb +0 -37
@@ -9,8 +9,8 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
|
|
9
9
|
it "should delegate #{method} to appropriate shard" do
|
10
10
|
post = Post.new
|
11
11
|
photo = Photo.new
|
12
|
-
@proxy.post_session.
|
13
|
-
@proxy.photo_session.
|
12
|
+
expect(@proxy.post_session).to receive(method).with([post])
|
13
|
+
expect(@proxy.photo_session).to receive(method).with([photo])
|
14
14
|
@proxy.send(method, post)
|
15
15
|
@proxy.send(method, photo)
|
16
16
|
end
|
@@ -18,24 +18,30 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
|
|
18
18
|
|
19
19
|
[:remove_by_id, :remove_by_id!].each do |method|
|
20
20
|
it "should delegate #{method} to appropriate shard" do
|
21
|
-
@proxy.post_session.
|
22
|
-
@proxy.photo_session.
|
21
|
+
expect(@proxy.post_session).to receive(method).with(Post, [1])
|
22
|
+
expect(@proxy.photo_session).to receive(method).with(Photo, [1])
|
23
23
|
@proxy.send(method, Post, 1)
|
24
24
|
@proxy.send(method, Photo, 1)
|
25
25
|
end
|
26
|
+
it "should delegate #{method} to appropriate shard given ids" do
|
27
|
+
expect(@proxy.post_session).to receive(method).with(Post, [1, 2])
|
28
|
+
expect(@proxy.photo_session).to receive(method).with(Photo, [1, 2])
|
29
|
+
@proxy.send(method, Post, 1, 2)
|
30
|
+
@proxy.send(method, Photo, [1, 2])
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
[:remove_all, :remove_all!].each do |method|
|
29
35
|
it "should delegate #{method} with argument to appropriate shard" do
|
30
|
-
@proxy.post_session.
|
31
|
-
@proxy.photo_session.
|
36
|
+
expect(@proxy.post_session).to receive(method).with(Post)
|
37
|
+
expect(@proxy.photo_session).to receive(method).with(Photo)
|
32
38
|
@proxy.send(method, Post)
|
33
39
|
@proxy.send(method, Photo)
|
34
40
|
end
|
35
41
|
|
36
42
|
it "should delegate #{method} without argument to all shards" do
|
37
|
-
@proxy.post_session.
|
38
|
-
@proxy.photo_session.
|
43
|
+
expect(@proxy.post_session).to receive(method)
|
44
|
+
expect(@proxy.photo_session).to receive(method)
|
39
45
|
@proxy.send(method)
|
40
46
|
end
|
41
47
|
end
|
@@ -43,42 +49,43 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
|
|
43
49
|
[:commit, :commit_if_dirty, :commit_if_delete_dirty, :optimize].each do |method|
|
44
50
|
it "should delegate #{method} to all sessions" do
|
45
51
|
[@proxy.post_session, @proxy.photo_session].each do |session|
|
46
|
-
session.
|
52
|
+
expect(session).to receive(method)
|
47
53
|
end
|
48
54
|
@proxy.send(method)
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
52
58
|
it "should not support the :batch method" do
|
53
|
-
|
59
|
+
expect { @proxy.batch }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
|
54
60
|
end
|
55
61
|
|
56
62
|
it "should delegate new_search to search session, adding in shards parameter" do
|
57
63
|
search = @proxy.new_search(Post)
|
58
|
-
search.query[:shards].
|
64
|
+
expect(search.query[:shards]).to eq(
|
59
65
|
'http://photos.solr.local/solr,http://posts.solr.local/solr'
|
66
|
+
)
|
60
67
|
end
|
61
68
|
|
62
69
|
it "should delegate search to search session, adding in shards parameter" do
|
63
70
|
@proxy.search(Post)
|
64
|
-
connection.
|
71
|
+
expect(connection).to have_last_search_with(
|
65
72
|
:shards => 'http://photos.solr.local/solr,http://posts.solr.local/solr'
|
66
73
|
)
|
67
74
|
end
|
68
75
|
|
69
76
|
[:dirty, :delete_dirty].each do |method|
|
70
77
|
it "should be dirty if any of the sessions are dirty" do
|
71
|
-
@proxy.post_session.
|
72
|
-
@proxy.
|
78
|
+
allow(@proxy.post_session).to receive(:"#{method}?").and_return(true)
|
79
|
+
expect(@proxy).to send("be_#{method}")
|
73
80
|
end
|
74
81
|
|
75
82
|
it "should not be dirty if none of the sessions are dirty" do
|
76
|
-
@proxy.
|
83
|
+
expect(@proxy).not_to send("be_#{method}")
|
77
84
|
end
|
78
85
|
end
|
79
86
|
|
80
87
|
it "should raise a NotSupportedError when :config is called" do
|
81
|
-
|
88
|
+
expect { @proxy.config }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
|
82
89
|
end
|
83
90
|
|
84
91
|
it_should_behave_like 'session proxy'
|
@@ -10,8 +10,8 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
|
|
10
10
|
[:index, :index!, :remove, :remove!].each do |method|
|
11
11
|
it "should delegate #{method} to appropriate shard" do
|
12
12
|
posts = [Post.new(:id => 2), Post.new(:id => 1)]
|
13
|
-
@proxy.sessions[0].
|
14
|
-
@proxy.sessions[1].
|
13
|
+
expect(@proxy.sessions[0]).to receive(method).with([posts[0]])
|
14
|
+
expect(@proxy.sessions[1]).to receive(method).with([posts[1]])
|
15
15
|
@proxy.send(method, posts[0])
|
16
16
|
@proxy.send(method, posts[1])
|
17
17
|
end
|
@@ -19,10 +19,22 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
|
|
19
19
|
|
20
20
|
[:remove_by_id, :remove_by_id!].each do |method|
|
21
21
|
it "should delegate #{method} to appropriate session" do
|
22
|
-
@proxy.sessions[
|
23
|
-
@proxy.sessions[
|
22
|
+
expect(@proxy.sessions[1]).to receive(method).with(Post, [3])
|
23
|
+
expect(@proxy.sessions[0]).to receive(method).with(Post, [2])
|
24
|
+
expect(@proxy.sessions[1]).to receive(method).with(Post, [1])
|
24
25
|
@proxy.send(method, Post, 1)
|
25
26
|
@proxy.send(method, Post, 2)
|
27
|
+
@proxy.send(method, Post, 3)
|
28
|
+
end
|
29
|
+
it "should delegate #{method} to appropriate session given splatted index ids" do
|
30
|
+
expect(@proxy.sessions[0]).to receive(method).with(Post, [2])
|
31
|
+
expect(@proxy.sessions[1]).to receive(method).with(Post, [1, 3])
|
32
|
+
@proxy.send(method, Post, 1, 2, 3)
|
33
|
+
end
|
34
|
+
it "should delegate #{method} to appropriate session given array of index ids" do
|
35
|
+
expect(@proxy.sessions[0]).to receive(method).with(Post, [2])
|
36
|
+
expect(@proxy.sessions[1]).to receive(method).with(Post, [1, 3])
|
37
|
+
@proxy.send(method, Post, [1, 2, 3])
|
26
38
|
end
|
27
39
|
end
|
28
40
|
|
@@ -13,28 +13,32 @@ describe Sunspot::SessionProxy::MasterSlaveSessionProxy do
|
|
13
13
|
methods.each do |method|
|
14
14
|
it "should delegate #{method} to #{delegate}" do
|
15
15
|
args = Array.new(Sunspot::Session.instance_method(method).arity.abs) do
|
16
|
-
|
16
|
+
double('arg')
|
17
|
+
end
|
18
|
+
if args.empty?
|
19
|
+
expect(instance_variable_get(:"@#{delegate}")).to receive(method).with(no_args)
|
20
|
+
else
|
21
|
+
expect(instance_variable_get(:"@#{delegate}")).to receive(method).with(*args)
|
17
22
|
end
|
18
|
-
instance_variable_get(:"@#{delegate}").should_receive(method).with(*args)
|
19
23
|
@proxy.send(method, *args)
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
it 'should return master session config by default' do
|
25
|
-
@proxy.config.
|
29
|
+
expect(@proxy.config).to eql(@master_session.config)
|
26
30
|
end
|
27
31
|
|
28
32
|
it 'should return master session config when specified' do
|
29
|
-
@proxy.config(:master).
|
33
|
+
expect(@proxy.config(:master)).to eql(@master_session.config)
|
30
34
|
end
|
31
35
|
|
32
36
|
it 'should return slave session config when specified' do
|
33
|
-
@proxy.config(:slave).
|
37
|
+
expect(@proxy.config(:slave)).to eql(@slave_session.config)
|
34
38
|
end
|
35
39
|
|
36
40
|
it 'should raise ArgumentError when bogus config specified' do
|
37
|
-
|
41
|
+
expect { @proxy.config(:bogus) }.to raise_error
|
38
42
|
end
|
39
43
|
|
40
44
|
it_should_behave_like 'session proxy'
|
@@ -33,14 +33,14 @@ describe Sunspot::SessionProxy::Retry5xxSessionProxy do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should behave normally without a stubbed exception" do
|
36
|
-
@sunspot_session.
|
36
|
+
expect(@sunspot_session).to receive(:index).and_return(double)
|
37
37
|
Sunspot.index(post)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should be successful with a single exception followed by a sucess" do
|
41
41
|
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(503))
|
42
|
-
@sunspot_session.
|
43
|
-
@sunspot_session.
|
42
|
+
expect(@sunspot_session).to receive(:index) do
|
43
|
+
expect(@sunspot_session).to receive(:index).and_return(double)
|
44
44
|
raise e
|
45
45
|
end
|
46
46
|
Sunspot.index(post)
|
@@ -49,25 +49,25 @@ describe Sunspot::SessionProxy::Retry5xxSessionProxy do
|
|
49
49
|
it "should return the error response after two exceptions" do
|
50
50
|
fake_response = fake_rsolr_response(503)
|
51
51
|
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_response)
|
52
|
-
fake_success =
|
52
|
+
fake_success = double('success')
|
53
53
|
|
54
|
-
@sunspot_session.
|
55
|
-
@sunspot_session.
|
56
|
-
@sunspot_session.
|
54
|
+
expect(@sunspot_session).to receive(:index) do
|
55
|
+
expect(@sunspot_session).to receive(:index) do
|
56
|
+
allow(@sunspot_session).to receive(:index).and_return(fake_success)
|
57
57
|
raise e
|
58
58
|
end
|
59
59
|
raise e
|
60
60
|
end
|
61
61
|
|
62
62
|
response = Sunspot.index(post)
|
63
|
-
response.
|
64
|
-
response.
|
63
|
+
expect(response).not_to eq(fake_success)
|
64
|
+
expect(response).to eq(fake_response)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should not retry a 4xx" do
|
68
68
|
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(400))
|
69
|
-
@sunspot_session.
|
70
|
-
|
69
|
+
expect(@sunspot_session).to receive(:index).and_raise(e)
|
70
|
+
expect { Sunspot.index(post) }.to raise_error
|
71
71
|
end
|
72
72
|
|
73
73
|
# TODO: try against more than just Sunspot.index? but that's just testing the
|
@@ -8,26 +8,26 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
|
|
8
8
|
[:index, :index!, :remove, :remove!].each do |method|
|
9
9
|
it "should delegate #{method} to appropriate shard" do
|
10
10
|
posts = [Post.new(:blog_id => 2), Post.new(:blog_id => 3)]
|
11
|
-
@proxy.sessions[0].
|
12
|
-
@proxy.sessions[1].
|
11
|
+
expect(@proxy.sessions[0]).to receive(method).with([posts[0]])
|
12
|
+
expect(@proxy.sessions[1]).to receive(method).with([posts[1]])
|
13
13
|
@proxy.send(method, posts[0])
|
14
14
|
@proxy.send(method, posts[1])
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
[:remove_by_id, :remove_by_id!].each do |method|
|
18
|
+
[:remove_by_id, :remove_by_id!, :atomic_update, :atomic_update!].each do |method|
|
19
19
|
it "should raise NotSupportedError when #{method} called" do
|
20
|
-
|
20
|
+
expect { @proxy.send(method, Post, 1) }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
[:remove_all, :remove_all!].each do |method|
|
25
25
|
it "should raise NotSupportedError when #{method} called with argument" do
|
26
|
-
|
26
|
+
expect { @proxy.send(method, Post) }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should delegate #{method} without argument to all shards" do
|
30
|
-
@proxy.sessions.each { |session| session.
|
30
|
+
@proxy.sessions.each { |session| expect(session).to receive(method) }
|
31
31
|
@proxy.send(method)
|
32
32
|
end
|
33
33
|
end
|
@@ -35,42 +35,43 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
|
|
35
35
|
[:commit, :commit_if_dirty, :commit_if_delete_dirty, :optimize].each do |method|
|
36
36
|
it "should delegate #{method} to all sessions" do
|
37
37
|
@proxy.sessions.each do |session|
|
38
|
-
session.
|
38
|
+
expect(session).to receive(method)
|
39
39
|
end
|
40
40
|
@proxy.send(method)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not support the :batch method" do
|
45
|
-
|
45
|
+
expect { @proxy.batch }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should delegate new_search to search session, adding in shards parameter" do
|
49
49
|
search = @proxy.new_search(Post)
|
50
|
-
search.query[:shards].
|
50
|
+
expect(search.query[:shards]).to eq(
|
51
51
|
'http://localhost:8980/solr,http://localhost:8981/solr'
|
52
|
+
)
|
52
53
|
end
|
53
54
|
|
54
55
|
it "should delegate search to search session, adding in shards parameter" do
|
55
56
|
@proxy.search(Post)
|
56
|
-
connection.
|
57
|
+
expect(connection).to have_last_search_with(
|
57
58
|
:shards => 'http://localhost:8980/solr,http://localhost:8981/solr'
|
58
59
|
)
|
59
60
|
end
|
60
61
|
|
61
62
|
[:dirty, :delete_dirty].each do |method|
|
62
63
|
it "should be dirty if any of the sessions are dirty" do
|
63
|
-
@proxy.sessions[0].
|
64
|
-
@proxy.
|
64
|
+
allow(@proxy.sessions[0]).to receive(:"#{method}?").and_return(true)
|
65
|
+
expect(@proxy).to send("be_#{method}")
|
65
66
|
end
|
66
67
|
|
67
68
|
it "should not be dirty if none of the sessions are dirty" do
|
68
|
-
@proxy.
|
69
|
+
expect(@proxy).not_to send("be_#{method}")
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
73
|
it "should raise a NotSupportedError when :config is called" do
|
73
|
-
|
74
|
+
expect { @proxy.config }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
|
74
75
|
end
|
75
76
|
|
76
77
|
it_should_behave_like 'session proxy'
|
@@ -6,15 +6,15 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
|
|
6
6
|
SUPPORTED_METHODS = Sunspot::SessionProxy::SilentFailSessionProxy::SUPPORTED_METHODS
|
7
7
|
|
8
8
|
before do
|
9
|
-
@search_session =
|
9
|
+
@search_session = double(Sunspot::Session.new)
|
10
10
|
@proxy = Sunspot::SessionProxy::SilentFailSessionProxy.new(@search_session)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should call rescued_exception when an exception is caught" do
|
14
14
|
SUPPORTED_METHODS.each do |method|
|
15
15
|
e = FakeException.new(method)
|
16
|
-
@search_session.
|
17
|
-
@proxy.
|
16
|
+
allow(@search_session).to receive(method).and_raise(e)
|
17
|
+
expect(@proxy).to receive(:rescued_exception).with(method, e)
|
18
18
|
@proxy.send(method)
|
19
19
|
end
|
20
20
|
end
|
@@ -3,7 +3,7 @@ require File.expand_path('spec_helper', File.join(File.dirname(__FILE__), '..'))
|
|
3
3
|
shared_examples_for 'session proxy' do
|
4
4
|
Sunspot::Session.public_instance_methods(false).each do |method|
|
5
5
|
it "should respond to #{method.inspect}" do
|
6
|
-
@proxy.
|
6
|
+
expect(@proxy).to respond_to(method)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,38 +2,52 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
2
2
|
require 'weakref'
|
3
3
|
|
4
4
|
describe Sunspot::SessionProxy::ThreadLocalSessionProxy do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
context 'when not passing a config' do
|
6
|
+
before :each do
|
7
|
+
@proxy = Sunspot::SessionProxy::ThreadLocalSessionProxy.new
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
@proxy.session.should eql(@proxy.session)
|
10
|
+
it_should_behave_like 'session proxy'
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end.join
|
20
|
-
session1.should_not eql(session2)
|
21
|
-
end
|
13
|
+
context 'when passing a config' do
|
14
|
+
before :each do
|
15
|
+
@config = Sunspot::Configuration.build
|
16
|
+
@proxy = Sunspot::SessionProxy::ThreadLocalSessionProxy.new(@config)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
19
|
+
it 'should have the same session for the same thread' do
|
20
|
+
expect(@proxy.session).to eql(@proxy.session)
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
it 'should not have the same session for different threads' do
|
24
|
+
session1 = @proxy.session
|
25
|
+
session2 = nil
|
26
|
+
Thread.new do
|
27
|
+
session2 = @proxy.session
|
28
|
+
end.join
|
29
|
+
expect(session1).not_to eql(session2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not have the same session for the same thread in different proxy instances' do
|
33
|
+
proxy2 = Sunspot::SessionProxy::ThreadLocalSessionProxy.new(@config)
|
34
|
+
expect(@proxy.session).not_to eql(proxy2.session)
|
35
|
+
end
|
36
|
+
|
37
|
+
(Sunspot::Session.public_instance_methods(false) - ['config', :config]).each do |method|
|
38
|
+
it "should delegate #{method.inspect} to its session" do
|
39
|
+
args = Array.new(Sunspot::Session.instance_method(method).arity.abs) do
|
40
|
+
double('arg')
|
41
|
+
end
|
42
|
+
if args.empty?
|
43
|
+
expect(@proxy.session).to receive(method).with(no_args)
|
44
|
+
else
|
45
|
+
expect(@proxy.session).to receive(method).with(*args)
|
46
|
+
end
|
47
|
+
@proxy.send(method, *args)
|
32
48
|
end
|
33
|
-
@proxy.session.should_receive(method).with(*args)
|
34
|
-
@proxy.send(method, *args)
|
35
49
|
end
|
36
|
-
end
|
37
50
|
|
38
|
-
|
51
|
+
it_should_behave_like 'session proxy'
|
52
|
+
end
|
39
53
|
end
|
data/spec/api/session_spec.rb
CHANGED
@@ -7,7 +7,7 @@ shared_examples_for 'all sessions' do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should add document to connection' do
|
10
|
-
connection.
|
10
|
+
expect(connection.adds.size).to eq(1)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,11 +17,11 @@ shared_examples_for 'all sessions' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should add document to connection' do
|
20
|
-
connection.
|
20
|
+
expect(connection.adds.size).to eq(1)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should commit' do
|
24
|
-
connection.
|
24
|
+
expect(connection.commits.size).to eq(1)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,27 @@ shared_examples_for 'all sessions' do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should commit' do
|
34
|
-
connection.
|
34
|
+
expect(connection.commits.size).to eq(1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context '#commit(bool)' do
|
39
|
+
it 'should soft-commit if bool=true' do
|
40
|
+
@session.commit(true)
|
41
|
+
expect(connection.commits.size).to eq(1)
|
42
|
+
expect(connection.soft_commits.size).to eq(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should hard-commit if bool=false' do
|
46
|
+
@session.commit(false)
|
47
|
+
expect(connection.commits.size).to eq(1)
|
48
|
+
expect(connection.soft_commits.size).to eq(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should hard-commit if bool is not specified' do
|
52
|
+
@session.commit
|
53
|
+
expect(connection.commits.size).to eq(1)
|
54
|
+
expect(connection.soft_commits.size).to eq(0)
|
35
55
|
end
|
36
56
|
end
|
37
57
|
|
@@ -41,7 +61,7 @@ shared_examples_for 'all sessions' do
|
|
41
61
|
end
|
42
62
|
|
43
63
|
it 'should optimize' do
|
44
|
-
connection.
|
64
|
+
expect(connection.optims.size).to eq(1)
|
45
65
|
end
|
46
66
|
end
|
47
67
|
|
@@ -51,7 +71,7 @@ shared_examples_for 'all sessions' do
|
|
51
71
|
end
|
52
72
|
|
53
73
|
it 'should search' do
|
54
|
-
connection.
|
74
|
+
expect(connection.searches.size).to eq(1)
|
55
75
|
end
|
56
76
|
end
|
57
77
|
end
|
@@ -77,25 +97,31 @@ describe 'Session' do
|
|
77
97
|
|
78
98
|
it 'should open connection with defaults if nothing specified' do
|
79
99
|
Sunspot.commit
|
80
|
-
connection.opts[:url].
|
100
|
+
expect(connection.opts[:url]).to eq('http://127.0.0.1:8983/solr/default')
|
81
101
|
end
|
82
102
|
|
83
103
|
it 'should open a connection with custom host' do
|
84
104
|
Sunspot.config.solr.url = 'http://127.0.0.1:8981/solr'
|
85
105
|
Sunspot.commit
|
86
|
-
connection.opts[:url].
|
106
|
+
expect(connection.opts[:url]).to eq('http://127.0.0.1:8981/solr')
|
87
107
|
end
|
88
108
|
|
89
109
|
it 'should open a connection with custom read timeout' do
|
90
110
|
Sunspot.config.solr.read_timeout = 0.5
|
91
111
|
Sunspot.commit
|
92
|
-
connection.opts[:read_timeout].
|
112
|
+
expect(connection.opts[:read_timeout]).to eq(0.5)
|
93
113
|
end
|
94
114
|
|
95
115
|
it 'should open a connection with custom open timeout' do
|
96
116
|
Sunspot.config.solr.open_timeout = 0.5
|
97
117
|
Sunspot.commit
|
98
|
-
connection.opts[:open_timeout].
|
118
|
+
expect(connection.opts[:open_timeout]).to eq(0.5)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should open a connection through a provided proxy' do
|
122
|
+
Sunspot.config.solr.proxy = 'http://proxy.com:1234'
|
123
|
+
Sunspot.commit
|
124
|
+
expect(connection.opts[:proxy]).to eq('http://proxy.com:1234')
|
99
125
|
end
|
100
126
|
end
|
101
127
|
|
@@ -111,7 +137,7 @@ describe 'Session' do
|
|
111
137
|
config.solr.url = 'http://127.0.0.1:8982/solr'
|
112
138
|
end
|
113
139
|
session.commit
|
114
|
-
connection.opts[:url].
|
140
|
+
expect(connection.opts[:url]).to eq('http://127.0.0.1:8982/solr')
|
115
141
|
end
|
116
142
|
end
|
117
143
|
|
@@ -121,106 +147,120 @@ describe 'Session' do
|
|
121
147
|
end
|
122
148
|
|
123
149
|
it 'should start out not dirty' do
|
124
|
-
@session.dirty
|
150
|
+
expect(@session.dirty?).to be(false)
|
125
151
|
end
|
126
|
-
|
152
|
+
|
127
153
|
it 'should start out not delete_dirty' do
|
128
|
-
@session.delete_dirty
|
154
|
+
expect(@session.delete_dirty?).to be(false)
|
129
155
|
end
|
130
156
|
|
131
157
|
it 'should be dirty after adding an item' do
|
132
158
|
@session.index(Post.new)
|
133
|
-
@session.dirty
|
159
|
+
expect(@session.dirty?).to be(true)
|
134
160
|
end
|
135
|
-
|
161
|
+
|
136
162
|
it 'should be not be delete_dirty after adding an item' do
|
137
163
|
@session.index(Post.new)
|
138
|
-
@session.delete_dirty
|
164
|
+
expect(@session.delete_dirty?).to be(false)
|
139
165
|
end
|
140
166
|
|
141
167
|
it 'should be dirty after deleting an item' do
|
142
168
|
@session.remove(Post.new)
|
143
|
-
@session.dirty
|
169
|
+
expect(@session.dirty?).to be(true)
|
144
170
|
end
|
145
171
|
|
146
172
|
it 'should be delete_dirty after deleting an item' do
|
147
173
|
@session.remove(Post.new)
|
148
|
-
@session.delete_dirty
|
174
|
+
expect(@session.delete_dirty?).to be(true)
|
149
175
|
end
|
150
176
|
|
151
177
|
it 'should be dirty after a remove_all for a class' do
|
152
178
|
@session.remove_all(Post)
|
153
|
-
@session.dirty
|
179
|
+
expect(@session.dirty?).to be(true)
|
154
180
|
end
|
155
181
|
|
156
182
|
it 'should be delete_dirty after a remove_all for a class' do
|
157
183
|
@session.remove_all(Post)
|
158
|
-
@session.delete_dirty
|
184
|
+
expect(@session.delete_dirty?).to be(true)
|
159
185
|
end
|
160
186
|
|
161
187
|
it 'should be dirty after a global remove_all' do
|
162
188
|
@session.remove_all
|
163
|
-
@session.dirty
|
189
|
+
expect(@session.dirty?).to be(true)
|
164
190
|
end
|
165
|
-
|
191
|
+
|
166
192
|
it 'should be delete_dirty after a global remove_all' do
|
167
193
|
@session.remove_all
|
168
|
-
@session.delete_dirty
|
194
|
+
expect(@session.delete_dirty?).to be(true)
|
169
195
|
end
|
170
|
-
|
196
|
+
|
171
197
|
it 'should not be dirty after a commit' do
|
172
198
|
@session.index(Post.new)
|
173
199
|
@session.commit
|
174
|
-
@session.dirty
|
200
|
+
expect(@session.dirty?).to be(false)
|
175
201
|
end
|
176
202
|
|
177
203
|
it 'should not be dirty after an optimize' do
|
178
204
|
@session.index(Post.new)
|
179
205
|
@session.optimize
|
180
|
-
@session.dirty
|
206
|
+
expect(@session.dirty?).to be(false)
|
181
207
|
end
|
182
208
|
|
183
209
|
it 'should not be delete_dirty after a commit' do
|
184
210
|
@session.remove(Post.new)
|
185
211
|
@session.commit
|
186
|
-
@session.delete_dirty
|
212
|
+
expect(@session.delete_dirty?).to be(false)
|
187
213
|
end
|
188
214
|
|
189
215
|
it 'should not be delete_dirty after an optimize' do
|
190
216
|
@session.remove(Post.new)
|
191
217
|
@session.optimize
|
192
|
-
@session.delete_dirty
|
218
|
+
expect(@session.delete_dirty?).to be(false)
|
193
219
|
end
|
194
220
|
|
195
221
|
it 'should not commit when commit_if_dirty called on clean session' do
|
196
222
|
@session.commit_if_dirty
|
197
|
-
connection.
|
223
|
+
expect(connection.commits.size).to eq(0)
|
198
224
|
end
|
199
225
|
|
200
226
|
it 'should not commit when commit_if_delete_dirty called on clean session' do
|
201
227
|
@session.commit_if_delete_dirty
|
202
|
-
connection.
|
228
|
+
expect(connection.commits.size).to eq(0)
|
203
229
|
end
|
204
230
|
|
205
|
-
it 'should commit when commit_if_dirty called on dirty session' do
|
231
|
+
it 'should hard commit when commit_if_dirty called on dirty session' do
|
206
232
|
@session.index(Post.new)
|
207
233
|
@session.commit_if_dirty
|
208
|
-
connection.
|
234
|
+
expect(connection.commits.size).to eq(1)
|
209
235
|
end
|
210
|
-
|
211
|
-
it 'should commit when
|
236
|
+
|
237
|
+
it 'should soft commit when commit_if_dirty called on dirty session' do
|
238
|
+
@session.index(Post.new)
|
239
|
+
@session.commit_if_dirty(true)
|
240
|
+
expect(connection.commits.size).to eq(1)
|
241
|
+
expect(connection.soft_commits.size).to eq(1)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'should hard commit when commit_if_delete_dirty called on delete_dirty session' do
|
212
245
|
@session.remove(Post.new)
|
213
246
|
@session.commit_if_delete_dirty
|
214
|
-
connection.
|
247
|
+
expect(connection.commits.size).to eq(1)
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should soft commit when commit_if_delete_dirty called on delete_dirty session' do
|
251
|
+
@session.remove(Post.new)
|
252
|
+
@session.commit_if_delete_dirty(true)
|
253
|
+
expect(connection.commits.size).to eq(1)
|
254
|
+
expect(connection.soft_commits.size).to eq(1)
|
215
255
|
end
|
216
256
|
end
|
217
257
|
|
218
258
|
context 'session proxy' do
|
219
259
|
it 'should send messages to manually assigned session proxy' do
|
220
|
-
stub_session =
|
260
|
+
stub_session = double('session')
|
221
261
|
Sunspot.session = stub_session
|
222
262
|
post = Post.new
|
223
|
-
stub_session.
|
263
|
+
expect(stub_session).to receive(:index).with(post)
|
224
264
|
Sunspot.index(post)
|
225
265
|
Sunspot.reset!
|
226
266
|
end
|