sunspot 2.0.0 → 2.5.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.
- 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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
2
|
+
|
|
3
|
+
describe Sunspot::DataExtractor do
|
|
4
|
+
it "removes special characters from strings" do
|
|
5
|
+
extractor = Sunspot::DataExtractor::AttributeExtractor.new(:name)
|
|
6
|
+
blog = Blog.new(:name => "Te\x0\x1\x7\x6\x8st\xB\xC\xE Bl\x1Fo\x7fg")
|
|
7
|
+
|
|
8
|
+
expect(extractor.value_for(blog)).to eq "Test Blog"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "removes special characters from arrays" do
|
|
12
|
+
extractor = Sunspot::DataExtractor::BlockExtractor.new { tags }
|
|
13
|
+
post = Post.new(:tags => ["Te\x0\x1\x7\x6\x8st Ta\x1Fg\x7f 1", "Test\xB\xC\xE Tag 2"])
|
|
14
|
+
|
|
15
|
+
expect(extractor.value_for(post)).to eq ["Test Tag 1", "Test Tag 2"]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "removes special characters from hashes" do
|
|
19
|
+
extractor = Sunspot::DataExtractor::Constant.new({ "Te\x0\x1\x7\x6\x8st" => "Ta\x1Fg\x7f" })
|
|
20
|
+
|
|
21
|
+
expect(extractor.value_for(Post.new)).to eq({ "Test" => "Tag" })
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "skips other data types" do
|
|
25
|
+
[
|
|
26
|
+
:"Te\x0\x1\x7\x6\x8st",
|
|
27
|
+
123,
|
|
28
|
+
123.0,
|
|
29
|
+
nil,
|
|
30
|
+
false,
|
|
31
|
+
true,
|
|
32
|
+
Sunspot::Util::Coordinates.new(40.7, -73.5)
|
|
33
|
+
].each do |value|
|
|
34
|
+
extractor = Sunspot::DataExtractor::Constant.new(value)
|
|
35
|
+
|
|
36
|
+
expect(extractor.value_for(Post.new)).to eq value
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -9,37 +9,60 @@ describe Sunspot::Search::HitEnumerable do
|
|
|
9
9
|
|
|
10
10
|
describe "#hits" do
|
|
11
11
|
before do
|
|
12
|
-
subject.
|
|
13
|
-
subject.
|
|
12
|
+
allow(subject).to receive(:solr_docs).and_return([{"id" => "Post 1", "score" => 3.14}])
|
|
13
|
+
allow(subject).to receive(:highlights_for)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "retrieves the raw Solr response from #solr_docs and constructs Hit objects" do
|
|
17
|
-
Sunspot::Search::Hit.
|
|
17
|
+
expect(Sunspot::Search::Hit).to receive(:new).
|
|
18
18
|
with({"id" => "Post 1", "score" => 3.14}, anything, anything)
|
|
19
19
|
|
|
20
20
|
subject.hits
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "constructs Hit objects with highlights" do
|
|
24
|
-
subject.
|
|
24
|
+
expect(subject).to receive(:highlights_for).with({"id" => "Post 1", "score" => 3.14})
|
|
25
25
|
|
|
26
26
|
subject.hits
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "returns only verified hits if :verify => true is passed" do
|
|
30
|
-
Sunspot::Search::Hit.
|
|
30
|
+
allow_any_instance_of(Sunspot::Search::Hit).to receive(:result).and_return(nil)
|
|
31
31
|
|
|
32
|
-
subject.hits(:verify => true).
|
|
32
|
+
expect(subject.hits(:verify => true)).to be_empty
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "returns an empty array if no results are available from Solr" do
|
|
36
|
-
subject.
|
|
36
|
+
allow(subject).to receive(:solr_docs).and_return(nil)
|
|
37
37
|
|
|
38
|
-
subject.hits.
|
|
38
|
+
expect(subject.hits).to eq([])
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "provides #populate_hits so that querying for one hit result will eager load the rest" do
|
|
42
|
-
Sunspot::Search::Hit.
|
|
42
|
+
expect_any_instance_of(Sunspot::Search::Hit).to receive(:result=)
|
|
43
|
+
|
|
44
|
+
subject.populate_hits
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "#populate_hits" do
|
|
49
|
+
let(:post_1) { Post.new(id: "1", title: "Title 1") }
|
|
50
|
+
|
|
51
|
+
before do
|
|
52
|
+
allow(subject).to receive(:solr_docs).and_return([{ "id" => "Post 1", "score" => 3.14 }])
|
|
53
|
+
allow(subject).to receive(:highlights_for)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "populates the hit object with the result from the data accessor" do
|
|
57
|
+
allow_any_instance_of(MockAdapter::DataAccessor).to receive(:load_all).and_return([post_1])
|
|
58
|
+
expect_any_instance_of(Sunspot::Search::Hit).to receive(:result=).with(post_1)
|
|
59
|
+
|
|
60
|
+
subject.populate_hits
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "populates the hit object only once if there are duplicate entries in the database (ex: db missing unique constraints)" do
|
|
64
|
+
allow_any_instance_of(MockAdapter::DataAccessor).to receive(:load_all).and_return([post_1, post_1])
|
|
65
|
+
expect_any_instance_of(Sunspot::Search::Hit).to receive(:result=).with(post_1)
|
|
43
66
|
|
|
44
67
|
subject.populate_hits
|
|
45
68
|
end
|
|
@@ -4,146 +4,151 @@ require 'bigdecimal'
|
|
|
4
4
|
describe 'indexing attribute fields', :type => :indexer do
|
|
5
5
|
it 'should correctly index a stored string attribute field' do
|
|
6
6
|
session.index(post(:title => 'A Title'))
|
|
7
|
-
connection.
|
|
7
|
+
expect(connection).to have_add_with(:title_ss => 'A Title')
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it 'should correctly index an integer attribute field' do
|
|
11
11
|
session.index(post(:blog_id => 4))
|
|
12
|
-
connection.
|
|
12
|
+
expect(connection).to have_add_with(:blog_id_i => '4')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'should correctly index a long attribute field' do
|
|
16
16
|
session.index(Namespaced::Comment.new(:hash => 2**30))
|
|
17
|
-
connection.
|
|
17
|
+
expect(connection).to have_add_with(:hash_l => '1073741824')
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'should correctly index a float attribute field' do
|
|
21
21
|
session.index(post(:ratings_average => 2.23))
|
|
22
|
-
connection.
|
|
22
|
+
expect(connection).to have_add_with(:average_rating_ft => '2.23')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'should correctly index a double attribute field' do
|
|
26
26
|
session.index(Namespaced::Comment.new(:average_rating => 2.23))
|
|
27
|
-
connection.
|
|
27
|
+
expect(connection).to have_add_with(:average_rating_e => '2.23')
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'should correctly index a trie integer attribute field' do
|
|
31
31
|
session.index(Photo.new(:size => 104856))
|
|
32
|
-
connection.
|
|
32
|
+
expect(connection).to have_add_with(:size_it => '104856')
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it 'should correctly index a trie float attribute field' do
|
|
36
36
|
session.index(Photo.new(:average_rating => 2.23))
|
|
37
|
-
connection.
|
|
37
|
+
expect(connection).to have_add_with(:average_rating_ft => '2.23')
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it 'should correctly index a trie time attribute field' do
|
|
41
41
|
session.index(Photo.new(:created_at => Time.parse('2009-12-16 15:00:00 -0400')))
|
|
42
|
-
connection.
|
|
42
|
+
expect(connection).to have_add_with(:created_at_dt => '2009-12-16T19:00:00Z')
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it 'should allow indexing by a multiple-value field' do
|
|
46
46
|
session.index(post(:category_ids => [3, 14]))
|
|
47
|
-
connection.
|
|
47
|
+
expect(connection).to have_add_with(:category_ids_im => ['3', '14'])
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it 'should not index a single-value field with newlines as multiple' do
|
|
51
51
|
session.index(post(:title => "Multi\nLine"))
|
|
52
|
-
connection.adds.last.first.field_by_name(:title_ss).value.
|
|
52
|
+
expect(connection.adds.last.first.field_by_name(:title_ss).value).to eq("Multi\nLine")
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it 'should correctly index a time field' do
|
|
56
56
|
session.index(
|
|
57
57
|
post(:published_at => Time.parse('1983-07-08 05:00:00 -0400'))
|
|
58
58
|
)
|
|
59
|
-
connection.
|
|
59
|
+
expect(connection).to have_add_with(:published_at_dt => '1983-07-08T09:00:00Z')
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it 'should correctly index a time field that\'s after 32-bit Y2K' do
|
|
63
63
|
session.index(
|
|
64
64
|
post(:published_at => DateTime.parse('2050-07-08 05:00:00 -0400'))
|
|
65
65
|
)
|
|
66
|
-
connection.
|
|
66
|
+
expect(connection).to have_add_with(:published_at_dt => '2050-07-08T09:00:00Z')
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it 'should correctly index a date field' do
|
|
70
70
|
session.index(post(:expire_date => Date.new(2009, 07, 13)))
|
|
71
|
-
connection.
|
|
71
|
+
expect(connection).to have_add_with(:expire_date_d => '2009-07-13T00:00:00Z')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'should correctly index a date range field' do
|
|
75
|
+
session.index(post(:featured_for => Date.new(2009, 07, 13)..Date.new(2009, 12, 25)))
|
|
76
|
+
expect(connection).to have_add_with(:featured_for_dr => '[2009-07-13T00:00:00Z TO 2009-12-25T00:00:00Z]')
|
|
72
77
|
end
|
|
73
78
|
|
|
74
79
|
it 'should correctly index a boolean field' do
|
|
75
80
|
session.index(post(:featured => true))
|
|
76
|
-
connection.
|
|
81
|
+
expect(connection).to have_add_with(:featured_bs => 'true')
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
it 'should correctly index a false boolean field' do
|
|
80
85
|
session.index(post(:featured => false))
|
|
81
|
-
connection.
|
|
86
|
+
expect(connection).to have_add_with(:featured_bs => 'false')
|
|
82
87
|
end
|
|
83
88
|
|
|
84
89
|
it 'should not index a nil boolean field' do
|
|
85
90
|
session.index(post)
|
|
86
|
-
connection.
|
|
91
|
+
expect(connection).not_to have_add_with(:featured_bs)
|
|
87
92
|
end
|
|
88
93
|
|
|
89
94
|
it 'should index latitude and longitude as a pair' do
|
|
90
95
|
session.index(post(:coordinates => Sunspot::Util::Coordinates.new(40.7, -73.5)))
|
|
91
|
-
connection.
|
|
96
|
+
expect(connection).to have_add_with(:coordinates_s => 'dr5xx3nytvgs')
|
|
92
97
|
end
|
|
93
98
|
|
|
94
99
|
it 'should index latitude and longitude passed as non-Floats' do
|
|
95
100
|
coordinates = Sunspot::Util::Coordinates.new(
|
|
96
101
|
BigDecimal.new('40.7'), BigDecimal.new('-73.5'))
|
|
97
102
|
session.index(post(:coordinates => coordinates))
|
|
98
|
-
connection.
|
|
103
|
+
expect(connection).to have_add_with(:coordinates_s => 'dr5xx3nytvgs')
|
|
99
104
|
end
|
|
100
105
|
|
|
101
106
|
it 'should correctly index an attribute field with block access' do
|
|
102
107
|
session.index(post(:title => 'The Blog Post'))
|
|
103
|
-
connection.
|
|
108
|
+
expect(connection).to have_add_with(:sort_title_s => 'blog post')
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
it 'should correctly index an attribute field with instance-external block access' do
|
|
107
112
|
session.index(post(:category_ids => [1, 2, 3]))
|
|
108
|
-
connection.
|
|
113
|
+
expect(connection).to have_add_with(:primary_category_id_i => '1')
|
|
109
114
|
end
|
|
110
115
|
|
|
111
116
|
it 'should correctly index a field that is defined on a superclass' do
|
|
112
117
|
Sunspot.setup(SuperClass) { string :author_name }
|
|
113
118
|
session.index(post(:author_name => 'Mat Brown'))
|
|
114
|
-
connection.
|
|
119
|
+
expect(connection).to have_add_with(:author_name_s => 'Mat Brown')
|
|
115
120
|
end
|
|
116
121
|
|
|
117
122
|
it 'should throw a NoMethodError only if a nonexistent type is defined' do
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
expect { Sunspot.setup(Post) { string :author_name }}.not_to raise_error
|
|
124
|
+
expect { Sunspot.setup(Post) { bogus :journey }}.to raise_error(NoMethodError)
|
|
120
125
|
end
|
|
121
126
|
|
|
122
127
|
it 'should throw a NoMethodError if a nonexistent field argument is passed' do
|
|
123
|
-
|
|
128
|
+
expect { Sunspot.setup(Post) { string :author_name, :bogus => :argument }}.to raise_error(ArgumentError)
|
|
124
129
|
end
|
|
125
130
|
|
|
126
131
|
it 'should throw an ArgumentError if single-value field tries to index multiple values' do
|
|
127
|
-
|
|
132
|
+
expect do
|
|
128
133
|
Sunspot.setup(Post) { string :author_name }
|
|
129
134
|
session.index(post(:author_name => ['Mat Brown', 'Matthew Brown']))
|
|
130
|
-
end.
|
|
135
|
+
end.to raise_error(ArgumentError)
|
|
131
136
|
end
|
|
132
137
|
|
|
133
138
|
it 'should throw an ArgumentError if specifying more_like_this on type that does not support it' do
|
|
134
|
-
|
|
139
|
+
expect do
|
|
135
140
|
Sunspot.setup(Post) { integer :popularity, :more_like_this => true }
|
|
136
|
-
end.
|
|
141
|
+
end.to raise_error(ArgumentError)
|
|
137
142
|
end
|
|
138
143
|
|
|
139
144
|
it 'should use a specified field name when the :as option is set' do
|
|
140
145
|
session.index(post(:title => 'A Title'))
|
|
141
|
-
connection.
|
|
146
|
+
expect(connection).to have_add_with(:legacy_field_s => 'legacy A Title')
|
|
142
147
|
end
|
|
143
148
|
|
|
144
149
|
it 'should use a specified field name when the :as option is set for array values' do
|
|
145
150
|
session.index(post(:title => 'Another Title'))
|
|
146
|
-
connection.
|
|
151
|
+
expect(connection).to have_add_with(:legacy_array_field_sm => ['first string', 'second string'])
|
|
147
152
|
end
|
|
148
153
|
end
|
|
149
154
|
|
|
@@ -9,7 +9,7 @@ describe 'batch indexing', :type => :indexer do
|
|
|
9
9
|
session.index(post)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
-
connection.adds.length.
|
|
12
|
+
expect(connection.adds.length).to eq(1)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'should add all batched adds' do
|
|
@@ -19,8 +19,9 @@ describe 'batch indexing', :type => :indexer do
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
add = connection.adds.last
|
|
22
|
-
connection.adds.first.map { |add| add.field_by_name(:id).value }.
|
|
22
|
+
expect(connection.adds.first.map { |add| add.field_by_name(:id).value }).to eq(
|
|
23
23
|
posts.map { |post| "Post #{post.id}" }
|
|
24
|
+
)
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
it 'should not index changes to models that happen after index call' do
|
|
@@ -29,13 +30,13 @@ describe 'batch indexing', :type => :indexer do
|
|
|
29
30
|
session.index(post)
|
|
30
31
|
post.title = 'Title'
|
|
31
32
|
end
|
|
32
|
-
connection.adds.first.first.field_by_name(:title_ss).
|
|
33
|
+
expect(connection.adds.first.first.field_by_name(:title_ss)).to be_nil
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
it 'should batch an add and a delete' do
|
|
36
|
-
|
|
37
|
-
connection.
|
|
38
|
-
connection.
|
|
37
|
+
skip 'batching all operations'
|
|
38
|
+
expect(connection).not_to receive(:add)
|
|
39
|
+
expect(connection).not_to receive(:remove)
|
|
39
40
|
session.batch do
|
|
40
41
|
session.index(posts[0])
|
|
41
42
|
session.remove(posts[1])
|
|
@@ -64,7 +65,7 @@ describe 'batch indexing', :type => :indexer do
|
|
|
64
65
|
a_nested_batch
|
|
65
66
|
nested_batches_adds = connection.adds
|
|
66
67
|
|
|
67
|
-
nested_batches_adds.first.first.field_by_name(:title_ss).value.
|
|
68
|
+
expect(nested_batches_adds.first.first.field_by_name(:title_ss).value).to eq(
|
|
68
69
|
two_sets_of_batches_adds.first.first.field_by_name(:title_ss).value
|
|
69
70
|
)
|
|
70
71
|
end
|
|
@@ -3,40 +3,40 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
|
3
3
|
describe 'indexing dynamic fields' do
|
|
4
4
|
it 'indexes string data' do
|
|
5
5
|
session.index(post(:custom_string => { :test => 'string' }))
|
|
6
|
-
connection.
|
|
6
|
+
expect(connection).to have_add_with(:"custom_string:test_ss" => 'string')
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it 'indexes integer data with virtual accessor' do
|
|
10
10
|
session.index(post(:category_ids => [1, 2]))
|
|
11
|
-
connection.
|
|
11
|
+
expect(connection).to have_add_with(:"custom_integer:1_i" => '1', :"custom_integer:2_i" => '1')
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it 'indexes float data' do
|
|
15
15
|
session.index(post(:custom_fl => { :test => 1.5 }))
|
|
16
|
-
connection.
|
|
16
|
+
expect(connection).to have_add_with(:"custom_float:test_fm" => '1.5')
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it 'indexes time data' do
|
|
20
20
|
session.index(post(:custom_time => { :test => Time.parse('2009-05-18 18:05:00 -0400') }))
|
|
21
|
-
connection.
|
|
21
|
+
expect(connection).to have_add_with(:"custom_time:test_d" => '2009-05-18T22:05:00Z')
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'indexes boolean data' do
|
|
25
25
|
session.index(post(:custom_boolean => { :test => false }))
|
|
26
|
-
connection.
|
|
26
|
+
expect(connection).to have_add_with(:"custom_boolean:test_b" => 'false')
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it 'indexes multiple values for a field' do
|
|
30
30
|
session.index(post(:custom_fl => { :test => [1.0, 2.1, 3.2] }))
|
|
31
|
-
connection.
|
|
31
|
+
expect(connection).to have_add_with(:"custom_float:test_fm" => %w(1.0 2.1 3.2))
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it 'should throw a NoMethodError if dynamic text field defined' do
|
|
35
|
-
|
|
35
|
+
expect do
|
|
36
36
|
Sunspot.setup(Post) do
|
|
37
37
|
dynamic_text :custom_text
|
|
38
38
|
end
|
|
39
|
-
end.
|
|
39
|
+
end.to raise_error(NoMethodError)
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -3,23 +3,28 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
|
3
3
|
describe 'indexing fixed fields', :type => :indexer do
|
|
4
4
|
it 'should index id' do
|
|
5
5
|
session.index post
|
|
6
|
-
connection.
|
|
6
|
+
expect(connection).to have_add_with(:id => "Post #{post.id}")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it 'should index type' do
|
|
10
10
|
session.index post
|
|
11
|
-
connection.
|
|
11
|
+
expect(connection).to have_add_with(:type => ['Post', 'SuperClass', 'MockRecord'])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should not index join fields' do
|
|
15
|
+
session.index PhotoContainer.new
|
|
16
|
+
expect(connection).not_to have_add_with(:photo_caption => 'blah')
|
|
12
17
|
end
|
|
13
18
|
|
|
14
19
|
it 'should index class name' do
|
|
15
20
|
session.index post
|
|
16
|
-
connection.
|
|
21
|
+
expect(connection).to have_add_with(:class_name => 'Post')
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
it 'should index the array of objects supplied' do
|
|
20
25
|
posts = Array.new(2) { Post.new }
|
|
21
26
|
session.index posts
|
|
22
|
-
connection.
|
|
27
|
+
expect(connection).to have_add_with(
|
|
23
28
|
{ :id => "Post #{posts.first.id}" },
|
|
24
29
|
{ :id => "Post #{posts.last.id}" }
|
|
25
30
|
)
|
|
@@ -28,7 +33,7 @@ describe 'indexing fixed fields', :type => :indexer do
|
|
|
28
33
|
it 'should index an array containing more than one type of object' do
|
|
29
34
|
post1, comment, post2 = objects = [Post.new, Namespaced::Comment.new, Post.new]
|
|
30
35
|
session.index objects
|
|
31
|
-
connection.
|
|
36
|
+
expect(connection).to have_add_with(
|
|
32
37
|
{ :id => "Post #{post1.id}", :type => ['Post', 'SuperClass', 'MockRecord'] },
|
|
33
38
|
{ :id => "Namespaced::Comment #{comment.id}", :type => ['Namespaced::Comment', 'MockRecord'] },
|
|
34
39
|
{ :id => "Post #{post2.id}", :type => ['Post', 'SuperClass', 'MockRecord'] }
|
|
@@ -36,22 +41,22 @@ describe 'indexing fixed fields', :type => :indexer do
|
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
it 'commits immediately after index! called' do
|
|
39
|
-
connection.
|
|
40
|
-
connection.
|
|
44
|
+
expect(connection).to receive(:add).ordered
|
|
45
|
+
expect(connection).to receive(:commit).ordered
|
|
41
46
|
session.index!(post)
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
it 'raises an ArgumentError if an attempt is made to index an object that has no configuration' do
|
|
45
|
-
|
|
50
|
+
expect { session.index(Blog.new) }.to raise_error(Sunspot::NoSetupError)
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
it 'raises a NoAdapterError if class without adapter is indexed' do
|
|
49
|
-
|
|
54
|
+
expect { session.index(User.new) }.to raise_error(Sunspot::NoAdapterError)
|
|
50
55
|
end
|
|
51
56
|
|
|
52
57
|
it 'raises an ArgumentError if a non-word character is included in the field name' do
|
|
53
|
-
|
|
58
|
+
expect do
|
|
54
59
|
Sunspot.setup(Post) { string :"bad name" }
|
|
55
|
-
end.
|
|
60
|
+
end.to raise_error(ArgumentError)
|
|
56
61
|
end
|
|
57
62
|
end
|