nuatt_sunspot 1.1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/History.txt +198 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +239 -0
  4. data/Rakefile +11 -0
  5. data/TODO +13 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/sunspot-installer +19 -0
  8. data/bin/sunspot-solr +74 -0
  9. data/installer/config/schema.yml +95 -0
  10. data/lib/light_config.rb +40 -0
  11. data/lib/sunspot.rb +529 -0
  12. data/lib/sunspot/adapters.rb +265 -0
  13. data/lib/sunspot/composite_setup.rb +202 -0
  14. data/lib/sunspot/configuration.rb +46 -0
  15. data/lib/sunspot/data_extractor.rb +50 -0
  16. data/lib/sunspot/dsl.rb +5 -0
  17. data/lib/sunspot/dsl/adjustable.rb +47 -0
  18. data/lib/sunspot/dsl/field_query.rb +266 -0
  19. data/lib/sunspot/dsl/fields.rb +113 -0
  20. data/lib/sunspot/dsl/fulltext.rb +243 -0
  21. data/lib/sunspot/dsl/function.rb +14 -0
  22. data/lib/sunspot/dsl/functional.rb +41 -0
  23. data/lib/sunspot/dsl/more_like_this_query.rb +56 -0
  24. data/lib/sunspot/dsl/paginatable.rb +28 -0
  25. data/lib/sunspot/dsl/query_facet.rb +36 -0
  26. data/lib/sunspot/dsl/restriction.rb +25 -0
  27. data/lib/sunspot/dsl/scope.rb +229 -0
  28. data/lib/sunspot/dsl/search.rb +30 -0
  29. data/lib/sunspot/dsl/standard_query.rb +125 -0
  30. data/lib/sunspot/field.rb +192 -0
  31. data/lib/sunspot/field_factory.rb +147 -0
  32. data/lib/sunspot/indexer.rb +131 -0
  33. data/lib/sunspot/installer.rb +31 -0
  34. data/lib/sunspot/installer/library_installer.rb +45 -0
  35. data/lib/sunspot/installer/schema_builder.rb +219 -0
  36. data/lib/sunspot/installer/solrconfig_updater.rb +106 -0
  37. data/lib/sunspot/installer/task_helper.rb +18 -0
  38. data/lib/sunspot/query.rb +10 -0
  39. data/lib/sunspot/query/abstract_field_facet.rb +52 -0
  40. data/lib/sunspot/query/boost_query.rb +24 -0
  41. data/lib/sunspot/query/common_query.rb +85 -0
  42. data/lib/sunspot/query/composite_fulltext.rb +31 -0
  43. data/lib/sunspot/query/connective.rb +191 -0
  44. data/lib/sunspot/query/date_field_facet.rb +14 -0
  45. data/lib/sunspot/query/dismax.rb +127 -0
  46. data/lib/sunspot/query/field_facet.rb +41 -0
  47. data/lib/sunspot/query/filter.rb +38 -0
  48. data/lib/sunspot/query/function_query.rb +52 -0
  49. data/lib/sunspot/query/highlighting.rb +55 -0
  50. data/lib/sunspot/query/local.rb +26 -0
  51. data/lib/sunspot/query/more_like_this.rb +60 -0
  52. data/lib/sunspot/query/more_like_this_query.rb +12 -0
  53. data/lib/sunspot/query/pagination.rb +38 -0
  54. data/lib/sunspot/query/query_facet.rb +16 -0
  55. data/lib/sunspot/query/restriction.rb +262 -0
  56. data/lib/sunspot/query/scope.rb +9 -0
  57. data/lib/sunspot/query/sort.rb +95 -0
  58. data/lib/sunspot/query/sort_composite.rb +33 -0
  59. data/lib/sunspot/query/standard_query.rb +20 -0
  60. data/lib/sunspot/query/text_field_boost.rb +17 -0
  61. data/lib/sunspot/schema.rb +151 -0
  62. data/lib/sunspot/search.rb +9 -0
  63. data/lib/sunspot/search/abstract_search.rb +302 -0
  64. data/lib/sunspot/search/date_facet.rb +35 -0
  65. data/lib/sunspot/search/facet_row.rb +27 -0
  66. data/lib/sunspot/search/field_facet.rb +88 -0
  67. data/lib/sunspot/search/highlight.rb +38 -0
  68. data/lib/sunspot/search/hit.rb +136 -0
  69. data/lib/sunspot/search/more_like_this_search.rb +31 -0
  70. data/lib/sunspot/search/query_facet.rb +62 -0
  71. data/lib/sunspot/search/standard_search.rb +21 -0
  72. data/lib/sunspot/server.rb +152 -0
  73. data/lib/sunspot/session.rb +252 -0
  74. data/lib/sunspot/session_proxy.rb +71 -0
  75. data/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
  76. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
  77. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
  78. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
  79. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +215 -0
  80. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +37 -0
  81. data/lib/sunspot/setup.rb +366 -0
  82. data/lib/sunspot/text_field_setup.rb +29 -0
  83. data/lib/sunspot/type.rb +340 -0
  84. data/lib/sunspot/util.rb +253 -0
  85. data/lib/sunspot/version.rb +3 -0
  86. data/solr/etc/jetty.xml +214 -0
  87. data/solr/etc/webdefault.xml +379 -0
  88. data/solr/lib/jetty-6.1.3.jar +0 -0
  89. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  90. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  91. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  92. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  93. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  94. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  95. data/solr/solr/conf/admin-extra.html +31 -0
  96. data/solr/solr/conf/elevate.xml +36 -0
  97. data/solr/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  98. data/solr/solr/conf/protwords.txt +21 -0
  99. data/solr/solr/conf/schema.xml +240 -0
  100. data/solr/solr/conf/scripts.conf +24 -0
  101. data/solr/solr/conf/solrconfig.xml +938 -0
  102. data/solr/solr/conf/spellings.txt +2 -0
  103. data/solr/solr/conf/stopwords.es.txt +345 -0
  104. data/solr/solr/conf/stopwords.txt +58 -0
  105. data/solr/solr/conf/synonyms.txt +31 -0
  106. data/solr/solr/lib/lucene-spatial-2.9.1.jar +0 -0
  107. data/solr/solr/lib/solr-spatial-light-0.0.6.jar +0 -0
  108. data/solr/start.jar +0 -0
  109. data/solr/webapps/solr.war +0 -0
  110. data/spec/api/adapters_spec.rb +33 -0
  111. data/spec/api/binding_spec.rb +38 -0
  112. data/spec/api/indexer/attributes_spec.rb +149 -0
  113. data/spec/api/indexer/batch_spec.rb +46 -0
  114. data/spec/api/indexer/dynamic_fields_spec.rb +42 -0
  115. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  116. data/spec/api/indexer/fulltext_spec.rb +43 -0
  117. data/spec/api/indexer/removal_spec.rb +53 -0
  118. data/spec/api/indexer/spec_helper.rb +1 -0
  119. data/spec/api/indexer_spec.rb +14 -0
  120. data/spec/api/query/advanced_manipulation_examples.rb +35 -0
  121. data/spec/api/query/connectives_examples.rb +176 -0
  122. data/spec/api/query/dsl_spec.rb +18 -0
  123. data/spec/api/query/dynamic_fields_examples.rb +165 -0
  124. data/spec/api/query/faceting_examples.rb +399 -0
  125. data/spec/api/query/fulltext_examples.rb +315 -0
  126. data/spec/api/query/function_spec.rb +70 -0
  127. data/spec/api/query/highlighting_examples.rb +225 -0
  128. data/spec/api/query/local_examples.rb +38 -0
  129. data/spec/api/query/more_like_this_spec.rb +140 -0
  130. data/spec/api/query/ordering_pagination_examples.rb +97 -0
  131. data/spec/api/query/scope_examples.rb +256 -0
  132. data/spec/api/query/spec_helper.rb +1 -0
  133. data/spec/api/query/standard_spec.rb +28 -0
  134. data/spec/api/query/text_field_scoping_examples.rb +30 -0
  135. data/spec/api/query/types_spec.rb +20 -0
  136. data/spec/api/search/dynamic_fields_spec.rb +33 -0
  137. data/spec/api/search/faceting_spec.rb +356 -0
  138. data/spec/api/search/highlighting_spec.rb +69 -0
  139. data/spec/api/search/hits_spec.rb +138 -0
  140. data/spec/api/search/results_spec.rb +79 -0
  141. data/spec/api/search/search_spec.rb +23 -0
  142. data/spec/api/search/spec_helper.rb +1 -0
  143. data/spec/api/server_spec.rb +91 -0
  144. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
  145. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
  146. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
  147. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
  148. data/spec/api/session_proxy/spec_helper.rb +9 -0
  149. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +50 -0
  150. data/spec/api/session_spec.rb +198 -0
  151. data/spec/api/spec_helper.rb +3 -0
  152. data/spec/api/sunspot_spec.rb +18 -0
  153. data/spec/ext.rb +11 -0
  154. data/spec/helpers/indexer_helper.rb +29 -0
  155. data/spec/helpers/query_helper.rb +38 -0
  156. data/spec/helpers/search_helper.rb +80 -0
  157. data/spec/integration/dynamic_fields_spec.rb +55 -0
  158. data/spec/integration/faceting_spec.rb +238 -0
  159. data/spec/integration/highlighting_spec.rb +22 -0
  160. data/spec/integration/indexing_spec.rb +33 -0
  161. data/spec/integration/keyword_search_spec.rb +317 -0
  162. data/spec/integration/local_search_spec.rb +91 -0
  163. data/spec/integration/more_like_this_spec.rb +43 -0
  164. data/spec/integration/scoped_search_spec.rb +324 -0
  165. data/spec/integration/spec_helper.rb +7 -0
  166. data/spec/integration/stored_fields_spec.rb +10 -0
  167. data/spec/integration/test_pagination.rb +32 -0
  168. data/spec/mocks/adapters.rb +32 -0
  169. data/spec/mocks/blog.rb +3 -0
  170. data/spec/mocks/comment.rb +21 -0
  171. data/spec/mocks/connection.rb +122 -0
  172. data/spec/mocks/mock_adapter.rb +30 -0
  173. data/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
  174. data/spec/mocks/mock_record.rb +52 -0
  175. data/spec/mocks/mock_sharding_session_proxy.rb +15 -0
  176. data/spec/mocks/photo.rb +12 -0
  177. data/spec/mocks/post.rb +76 -0
  178. data/spec/mocks/super_class.rb +2 -0
  179. data/spec/mocks/user.rb +8 -0
  180. data/spec/spec_helper.rb +52 -0
  181. data/tasks/gemspec.rake +33 -0
  182. data/tasks/rcov.rake +28 -0
  183. data/tasks/rdoc.rake +27 -0
  184. data/tasks/schema.rake +19 -0
  185. data/tasks/spec.rake +24 -0
  186. data/tasks/todo.rake +4 -0
  187. metadata +355 -0
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Sunspot::Adapters::InstanceAdapter do
4
+ it "finds adapter by superclass" do
5
+ Sunspot::Adapters::InstanceAdapter::for(Model).should be(AbstractModelInstanceAdapter)
6
+ end
7
+
8
+ it "finds adapter by mixin" do
9
+ Sunspot::Adapters::InstanceAdapter::for(MixModel).should be(MixInModelInstanceAdapter)
10
+ end
11
+
12
+ it 'throws NoAdapterError if anonymous module passed in' do
13
+ lambda do
14
+ Sunspot::Adapters::InstanceAdapter::for(Module.new)
15
+ end.should raise_error(Sunspot::NoAdapterError)
16
+ end
17
+ end
18
+
19
+ describe Sunspot::Adapters::DataAccessor do
20
+ it "finds adapter by superclass" do
21
+ Sunspot::Adapters::DataAccessor::for(Model).should be(AbstractModelDataAccessor)
22
+ end
23
+
24
+ it "finds adapter by mixin" do
25
+ Sunspot::Adapters::DataAccessor::for(MixModel).should be(MixInModelDataAccessor)
26
+ end
27
+
28
+ it 'throws NoAdapterError if anonymous module passed in' do
29
+ lambda do
30
+ Sunspot::Adapters::DataAccessor::for(Module.new)
31
+ end.should raise_error(Sunspot::NoAdapterError)
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "DSL bindings" do
4
+ it 'should give access to calling context\'s methods in search DSL' do
5
+ value = nil
6
+ session.search(Post) do
7
+ value = test_method
8
+ end
9
+ value.should == 'value'
10
+ end
11
+
12
+ it 'should give access to calling context\'s methods in nested DSL block' do
13
+ value = nil
14
+ session.search(Post) do
15
+ any_of do
16
+ value = test_method
17
+ end
18
+ end
19
+ value.should == 'value'
20
+ end
21
+
22
+ it 'should give access to calling context\'s methods in double-nested DSL block' do
23
+ value = nil
24
+ session.search(Post) do
25
+ any_of do
26
+ all_of do
27
+ value = test_method
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def test_method
36
+ 'value'
37
+ end
38
+ end
@@ -0,0 +1,149 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'indexing attribute fields', :type => :indexer do
4
+ it 'should correctly index a stored string attribute field' do
5
+ session.index(post(:title => 'A Title'))
6
+ connection.should have_add_with(:title_ss => 'A Title')
7
+ end
8
+
9
+ it 'should correctly index an integer attribute field' do
10
+ session.index(post(:blog_id => 4))
11
+ connection.should have_add_with(:blog_id_i => '4')
12
+ end
13
+
14
+ it 'should correctly index a long attribute field' do
15
+ session.index(Namespaced::Comment.new(:hash => 2**30))
16
+ connection.should have_add_with(:hash_l => '1073741824')
17
+ end
18
+
19
+ it 'should correctly index a float attribute field' do
20
+ session.index(post(:ratings_average => 2.23))
21
+ connection.should have_add_with(:average_rating_ft => '2.23')
22
+ end
23
+
24
+ it 'should correctly index a double attribute field' do
25
+ session.index(Namespaced::Comment.new(:average_rating => 2.23))
26
+ connection.should have_add_with(:average_rating_e => '2.23')
27
+ end
28
+
29
+ it 'should correctly index a trie integer attribute field' do
30
+ session.index(Photo.new(:size => 104856))
31
+ connection.should have_add_with(:size_it => '104856')
32
+ end
33
+
34
+ it 'should correctly index a trie float attribute field' do
35
+ session.index(Photo.new(:average_rating => 2.23))
36
+ connection.should have_add_with(:average_rating_ft => '2.23')
37
+ end
38
+
39
+ it 'should correctly index a trie time attribute field' do
40
+ session.index(Photo.new(:created_at => Time.parse('2009-12-16 15:00:00 -0400')))
41
+ connection.should have_add_with(:created_at_dt => '2009-12-16T19:00:00Z')
42
+ end
43
+
44
+ it 'should allow indexing by a multiple-value field' do
45
+ session.index(post(:category_ids => [3, 14]))
46
+ connection.should have_add_with(:category_ids_im => ['3', '14'])
47
+ end
48
+
49
+ it 'should not index a single-value field with newlines as multiple' do
50
+ session.index(post(:title => "Multi\nLine"))
51
+ connection.adds.last.first.field_by_name(:title_ss).value.should == "Multi\nLine"
52
+ end
53
+
54
+ it 'should correctly index a time field' do
55
+ session.index(
56
+ post(:published_at => Time.parse('1983-07-08 05:00:00 -0400'))
57
+ )
58
+ connection.should have_add_with(:published_at_dt => '1983-07-08T09:00:00Z')
59
+ end
60
+
61
+ it 'should correctly index a time field that\'s after 32-bit Y2K' do
62
+ session.index(
63
+ post(:published_at => DateTime.parse('2050-07-08 05:00:00 -0400'))
64
+ )
65
+ connection.should have_add_with(:published_at_dt => '2050-07-08T09:00:00Z')
66
+ end
67
+
68
+ it 'should correctly index a date field' do
69
+ session.index(post(:expire_date => Date.new(2009, 07, 13)))
70
+ connection.should have_add_with(:expire_date_d => '2009-07-13T00:00:00Z')
71
+ end
72
+
73
+ it 'should correctly index a boolean field' do
74
+ session.index(post(:featured => true))
75
+ connection.should have_add_with(:featured_b => 'true')
76
+ end
77
+
78
+ it 'should correctly index a false boolean field' do
79
+ session.index(post(:featured => false))
80
+ connection.should have_add_with(:featured_b => 'false')
81
+ end
82
+
83
+ it 'should not index a nil boolean field' do
84
+ session.index(post)
85
+ connection.should_not have_add_with(:featured_b)
86
+ end
87
+
88
+ it 'should index latitude and longitude as a pair' do
89
+ session.index(post(:coordinates => [40.7, -73.5]))
90
+ connection.should have_add_with(:lat => 40.7, :lng => -73.5)
91
+ end
92
+
93
+ [
94
+ [:lat, :lng],
95
+ [:lat, :lon],
96
+ [:lat, :long],
97
+ [:latitude, :longitude]
98
+ ].each do |lat_attr, lng_attr|
99
+ it "should index latitude and longitude from #{lat_attr.inspect}, #{lng_attr.inspect}" do
100
+ session.index(post(
101
+ :coordinates => OpenStruct.new(lat_attr => 40.7, lng_attr => -73.5)
102
+ ))
103
+ connection.should have_add_with(:lat => 40.7, :lng => -73.5)
104
+ end
105
+ end
106
+
107
+ it 'should index latitude and longitude from a block' do
108
+ session.index(Photo.new(:lat => 30, :lng => -60))
109
+ connection.should have_add_with(:lat => 30.0, :lng => -60.0)
110
+ end
111
+
112
+ it 'should correctly index an attribute field with block access' do
113
+ session.index(post(:title => 'The Blog Post'))
114
+ connection.should have_add_with(:sort_title_s => 'blog post')
115
+ end
116
+
117
+ it 'should correctly index an attribute field with instance-external block access' do
118
+ session.index(post(:category_ids => [1, 2, 3]))
119
+ connection.should have_add_with(:primary_category_id_i => '1')
120
+ end
121
+
122
+ it 'should correctly index a field that is defined on a superclass' do
123
+ Sunspot.setup(SuperClass) { string :author_name }
124
+ session.index(post(:author_name => 'Mat Brown'))
125
+ connection.should have_add_with(:author_name_s => 'Mat Brown')
126
+ end
127
+
128
+ it 'should throw a NoMethodError only if a nonexistent type is defined' do
129
+ lambda { Sunspot.setup(Post) { string :author_name }}.should_not raise_error
130
+ lambda { Sunspot.setup(Post) { bogus :journey }}.should raise_error(NoMethodError)
131
+ end
132
+
133
+ it 'should throw a NoMethodError if a nonexistent field argument is passed' do
134
+ lambda { Sunspot.setup(Post) { string :author_name, :bogus => :argument }}.should raise_error(ArgumentError)
135
+ end
136
+
137
+ it 'should throw an ArgumentError if single-value field tries to index multiple values' do
138
+ lambda do
139
+ Sunspot.setup(Post) { string :author_name }
140
+ session.index(post(:author_name => ['Mat Brown', 'Matthew Brown']))
141
+ end.should raise_error(ArgumentError)
142
+ end
143
+
144
+ it 'should throw an ArgumentError if specifying more_like_this on type that does not support it' do
145
+ lambda do
146
+ Sunspot.setup(Post) { integer :popularity, :more_like_this => true }
147
+ end.should raise_error(ArgumentError)
148
+ end
149
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'batch indexing', :type => :indexer do
4
+ it 'should send all batched adds in a single request' do
5
+ posts = Array.new(2) { Post.new }
6
+ session.batch do
7
+ for post in posts
8
+ session.index(post)
9
+ end
10
+ end
11
+ connection.adds.length.should == 1
12
+ end
13
+
14
+ it 'should add all batched adds' do
15
+ posts = Array.new(2) { Post.new }
16
+ session.batch do
17
+ for post in posts
18
+ session.index(post)
19
+ end
20
+ end
21
+ add = connection.adds.last
22
+ connection.adds.first.map { |add| add.field_by_name(:id).value }.should ==
23
+ posts.map { |post| "Post #{post.id}" }
24
+ end
25
+
26
+ it 'should not index changes to models that happen after index call' do
27
+ post = Post.new
28
+ session.batch do
29
+ session.index(post)
30
+ post.title = 'Title'
31
+ end
32
+ connection.adds.first.first.field_by_name(:title_ss).should be_nil
33
+ end
34
+
35
+ it 'should batch an add and a delete' do
36
+ pending 'batching all operations'
37
+ connection.should_not_receive(:add)
38
+ connection.should_not_receive(:remove)
39
+ posts = Array.new(2) { Post.new }
40
+ session.batch do
41
+ session.index(posts[0])
42
+ session.remove(posts[1])
43
+ end
44
+ connection.adds
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'indexing dynamic fields' do
4
+ it 'indexes string data' do
5
+ session.index(post(:custom_string => { :test => 'string' }))
6
+ connection.should have_add_with(:"custom_string:test_ss" => 'string')
7
+ end
8
+
9
+ it 'indexes integer data with virtual accessor' do
10
+ session.index(post(:category_ids => [1, 2]))
11
+ connection.should have_add_with(:"custom_integer:1_i" => '1', :"custom_integer:2_i" => '1')
12
+ end
13
+
14
+ it 'indexes float data' do
15
+ session.index(post(:custom_fl => { :test => 1.5 }))
16
+ connection.should have_add_with(:"custom_float:test_fm" => '1.5')
17
+ end
18
+
19
+ it 'indexes time data' do
20
+ session.index(post(:custom_time => { :test => Time.parse('2009-05-18 18:05:00 -0400') }))
21
+ connection.should have_add_with(:"custom_time:test_d" => '2009-05-18T22:05:00Z')
22
+ end
23
+
24
+ it 'indexes boolean data' do
25
+ session.index(post(:custom_boolean => { :test => false }))
26
+ connection.should have_add_with(:"custom_boolean:test_b" => 'false')
27
+ end
28
+
29
+ it 'indexes multiple values for a field' do
30
+ session.index(post(:custom_fl => { :test => [1.0, 2.1, 3.2] }))
31
+ connection.should have_add_with(:"custom_float:test_fm" => %w(1.0 2.1 3.2))
32
+ end
33
+
34
+ it 'should throw a NoMethodError if dynamic text field defined' do
35
+ lambda do
36
+ Sunspot.setup(Post) do
37
+ dynamic_text :custom_text
38
+ end
39
+ end.should raise_error(NoMethodError)
40
+ end
41
+ end
42
+
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'indexing fixed fields', :type => :indexer do
4
+ it 'should index id' do
5
+ session.index post
6
+ connection.should have_add_with(:id => "Post #{post.id}")
7
+ end
8
+
9
+ it 'should index type' do
10
+ session.index post
11
+ connection.should have_add_with(:type => ['Post', 'SuperClass', 'MockRecord'])
12
+ end
13
+
14
+ it 'should index class name' do
15
+ session.index post
16
+ connection.should have_add_with(:class_name => 'Post')
17
+ end
18
+
19
+ it 'should index the array of objects supplied' do
20
+ posts = Array.new(2) { Post.new }
21
+ session.index posts
22
+ connection.should have_add_with(
23
+ { :id => "Post #{posts.first.id}" },
24
+ { :id => "Post #{posts.last.id}" }
25
+ )
26
+ end
27
+
28
+ it 'should index an array containing more than one type of object' do
29
+ post1, comment, post2 = objects = [Post.new, Namespaced::Comment.new, Post.new]
30
+ session.index objects
31
+ connection.should have_add_with(
32
+ { :id => "Post #{post1.id}", :type => ['Post', 'SuperClass', 'MockRecord'] },
33
+ { :id => "Namespaced::Comment #{comment.id}", :type => ['Namespaced::Comment', 'MockRecord'] },
34
+ { :id => "Post #{post2.id}", :type => ['Post', 'SuperClass', 'MockRecord'] }
35
+ )
36
+ end
37
+
38
+ it 'commits immediately after index! called' do
39
+ connection.should_receive(:add).ordered
40
+ connection.should_receive(:commit).ordered
41
+ session.index!(post)
42
+ end
43
+
44
+ it 'raises an ArgumentError if an attempt is made to index an object that has no configuration' do
45
+ lambda { session.index(Blog.new) }.should raise_error(Sunspot::NoSetupError)
46
+ end
47
+
48
+ it 'raises a NoAdapterError if class without adapter is indexed' do
49
+ lambda { session.index(User.new) }.should raise_error(Sunspot::NoAdapterError)
50
+ end
51
+
52
+ it 'raises an ArgumentError if a non-word character is included in the field name' do
53
+ lambda do
54
+ Sunspot.setup(Post) { string :"bad name" }
55
+ end.should raise_error(ArgumentError)
56
+ end
57
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'indexing fulltext fields' do
4
+ it 'indexes text field' do
5
+ session.index(post(:title => 'A Title'))
6
+ connection.should have_add_with(:title_text => 'A Title')
7
+ end
8
+
9
+ it 'indexes stored text field' do
10
+ session.index(post(:body => 'Test body'))
11
+ connection.should have_add_with(:body_textsv => 'Test body')
12
+ end
13
+
14
+ it 'indexes text field with boost' do
15
+ session.index(post(:title => 'A Title'))
16
+ connection.adds.last.first.field_by_name(:title_text).attrs[:boost].should == 2
17
+ end
18
+
19
+ it 'indexes multiple values for a text field' do
20
+ session.index(post(:body => %w(some title)))
21
+ connection.should have_add_with(:body_textsv => %w(some title))
22
+ end
23
+
24
+ it 'indexes text via a block accessor' do
25
+ session.index(post(:title => 'backwards'))
26
+ connection.should have_add_with(:backwards_title_text => 'sdrawkcab')
27
+ end
28
+
29
+ it 'indexes document level boost using block' do
30
+ session.index(post(:ratings_average => 4.0))
31
+ connection.adds.last.first.attrs[:boost].should == 1.25
32
+ end
33
+
34
+ it 'indexes document level boost using attribute' do
35
+ session.index(Namespaced::Comment.new(:boost => 1.5))
36
+ connection.adds.last.first.attrs[:boost].should == 1.5
37
+ end
38
+
39
+ it 'indexes document level boost defined statically' do
40
+ session.index(Photo.new)
41
+ connection.adds.last.first.attrs[:boost].should == 0.75
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'document removal', :type => :indexer do
4
+ it 'removes an object from the index' do
5
+ session.remove(post)
6
+ connection.should have_delete("Post #{post.id}")
7
+ end
8
+
9
+ it 'removes an object by type and id' do
10
+ session.remove_by_id(Post, 1)
11
+ connection.should have_delete('Post 1')
12
+ end
13
+
14
+ it 'removes an object by type and id and immediately commits' do
15
+ connection.should_receive(:delete_by_id).with(['Post 1']).ordered
16
+ connection.should_receive(:commit).ordered
17
+ session.remove_by_id!(Post, 1)
18
+ end
19
+
20
+ it 'removes an object from the index and immediately commits' do
21
+ connection.should_receive(:delete_by_id).ordered
22
+ connection.should_receive(:commit).ordered
23
+ session.remove!(post)
24
+ end
25
+
26
+ it 'removes everything from the index' do
27
+ session.remove_all
28
+ connection.should have_delete_by_query("*:*")
29
+ end
30
+
31
+ it 'removes everything from the index and immediately commits' do
32
+ connection.should_receive(:delete_by_query).ordered
33
+ connection.should_receive(:commit).ordered
34
+ session.remove_all!
35
+ end
36
+
37
+ it 'removes everything of a given class from the index' do
38
+ session.remove_all(Post)
39
+ connection.should have_delete_by_query("type:Post")
40
+ end
41
+
42
+ it 'correctly escapes namespaced classes when removing everything from the index' do
43
+ connection.should_receive(:delete_by_query).with('type:Namespaced\:\:Comment')
44
+ session.remove_all(Namespaced::Comment)
45
+ end
46
+
47
+ it 'should remove by query' do
48
+ session.remove(Post) do
49
+ with(:title, 'monkeys')
50
+ end
51
+ connection.should have_delete_by_query("(type:Post AND title_ss:monkeys)")
52
+ end
53
+ end