outoftime-sunspot 0.8.2 → 0.8.3

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.
data/README.rdoc CHANGED
@@ -152,6 +152,7 @@ http://outoftime.lighthouseapp.com/projects/20339-sunspot
152
152
  == Contributors
153
153
 
154
154
  Mat Brown (mat@patch.com)
155
+ Peer Allan
155
156
 
156
157
  == License
157
158
 
data/TODO CHANGED
@@ -1,6 +1,11 @@
1
1
  === 0.9 ===
2
+ * Descriptive error messages during indexing
3
+ * Date type
4
+ * High-endian fields
5
+ * Add omitNorms to typed fields
2
6
  * Instantiated facets!
3
7
  * Direct access to adapter
4
- * Facet by type (?)
8
+ * sunspot-configure-solr
5
9
  * Switch to RSolr
10
+ * Facet by type (?)
6
11
  * Query-based faceting (?)
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 8
4
- :patch: 2
4
+ :patch: 3
@@ -19,11 +19,7 @@ module Sunspot
19
19
  # model<Object>:: the model to index
20
20
  #
21
21
  def add(model)
22
- hash = static_hash_for(model)
23
- for field in @setup.all_fields
24
- hash.merge!(field.pairs_for(model))
25
- end
26
- @connection.add(hash)
22
+ @connection.add(Array(model).map { |m| prepare(m) })
27
23
  end
28
24
 
29
25
  #
@@ -42,6 +38,17 @@ module Sunspot
42
38
 
43
39
  protected
44
40
 
41
+ #
42
+ # Convert documents into hash of indexed properties
43
+ #
44
+ def prepare(model)
45
+ hash = static_hash_for(model)
46
+ for field in @setup.all_fields
47
+ hash.merge!(field.pairs_for(model))
48
+ end
49
+ hash
50
+ end
51
+
45
52
  #
46
53
  # All indexed documents index and store the +id+ and +type+ fields.
47
54
  # This method constructs the document hash containing those key-value
@@ -52,6 +59,7 @@ module Sunspot
52
59
  :type => Util.superclasses_for(model.class).map { |clazz| clazz.name }}
53
60
  end
54
61
 
62
+
55
63
  class <<self
56
64
  #
57
65
  # Delete all documents from the Solr index
@@ -44,11 +44,19 @@ module Sunspot
44
44
  #
45
45
  # See Sunspot.index
46
46
  #
47
+ #--
48
+ # FIXME The fact that we have to break this out by class and index each
49
+ # class separately is artificial, imposed by the fact that indexers
50
+ # are initialized with a particular setup, and are responsible for
51
+ # sending add messages to Solr. It might be worth considering a
52
+ # singleton indexer (per session) and have the indexer itself find
53
+ # the appropriate setup to use for each object.
54
+ #
47
55
  def index(*objects)
48
56
  objects.flatten!
49
57
  @updates += objects.length
50
- for object in objects
51
- indexer_for(object).add(object)
58
+ objects.group_by { |object| object.class }.each_pair do |clazz, objs|
59
+ indexer_for(objs.first).add(objs)
52
60
  end
53
61
  end
54
62
 
@@ -3,86 +3,101 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
  describe 'indexer' do
4
4
  describe 'when indexing an object' do
5
5
  it 'should index id and type' do
6
- connection.should_receive(:add).with(hash_including(:id => "Post #{post.id}", :type => ['Post', 'BaseClass']))
6
+ connection.should_receive(:add).with([hash_including(:id => "Post #{post.id}", :type => ['Post', 'BaseClass'])])
7
7
  session.index post
8
8
  end
9
9
 
10
+ it 'should index the array of objects supplied' do
11
+ posts = Array.new(2) { Post.new }
12
+ connection.should_receive(:add).with([hash_including(:id => "Post #{posts.first.id}", :type => ['Post', 'BaseClass']),
13
+ hash_including(:id => "Post #{posts.last.id}", :type => ['Post', 'BaseClass'])])
14
+ session.index posts
15
+ end
16
+
17
+ it 'should index an array containing more than one type of object' do
18
+ post1, comment, post2 = objects = [Post.new, Comment.new, Post.new]
19
+ connection.should_receive(:add).with([hash_including(:id => "Post #{post1.id}", :type => ['Post', 'BaseClass']),
20
+ hash_including(:id => "Post #{post2.id}", :type => ['Post', 'BaseClass'])])
21
+ connection.should_receive(:add).with([hash_including(:id => "Comment #{comment.id}", :type => ['Comment', 'BaseClass'])])
22
+ session.index objects
23
+ end
24
+
10
25
  it 'should index text' do
11
26
  post :title => 'A Title', :body => 'A Post'
12
- connection.should_receive(:add).with(hash_including(:title_text => 'A Title', :body_text => 'A Post'))
27
+ connection.should_receive(:add).with([hash_including(:title_text => 'A Title', :body_text => 'A Post')])
13
28
  session.index post
14
29
  end
15
30
 
16
31
  it 'should index text via a virtual field' do
17
32
  post :title => 'backwards'
18
- connection.should_receive(:add).with(hash_including(:backwards_title_text => 'backwards'.reverse))
19
- session.index(post)
33
+ connection.should_receive(:add).with([hash_including(:backwards_title_text => 'backwards'.reverse)])
34
+ session.index post
20
35
  end
21
36
 
22
37
  it 'should correctly index a string attribute field' do
23
38
  post :title => 'A Title'
24
- connection.should_receive(:add).with(hash_including(:title_s => 'A Title'))
39
+ connection.should_receive(:add).with([hash_including(:title_s => 'A Title')])
25
40
  session.index post
26
41
  end
27
42
 
28
43
  it 'should correctly index an integer attribute field' do
29
44
  post :blog_id => 4
30
- connection.should_receive(:add).with(hash_including(:blog_id_i => '4'))
45
+ connection.should_receive(:add).with([hash_including(:blog_id_i => '4')])
31
46
  session.index post
32
47
  end
33
48
 
34
49
  it 'should correctly index a float attribute field' do
35
50
  post :ratings_average => 2.23
36
- connection.should_receive(:add).with(hash_including(:average_rating_f => '2.23'))
51
+ connection.should_receive(:add).with([hash_including(:average_rating_f => '2.23')])
37
52
  session.index post
38
53
  end
39
54
 
40
55
  it 'should allow indexing by a multiple-value field' do
41
56
  post :category_ids => [3, 14]
42
- connection.should_receive(:add).with(hash_including(:category_ids_im => ['3', '14']))
57
+ connection.should_receive(:add).with([hash_including(:category_ids_im => ['3', '14'])])
43
58
  session.index post
44
59
  end
45
60
 
46
61
  it 'should correctly index a time field' do
47
62
  post :published_at => Time.parse('1983-07-08 05:00:00 -0400')
48
- connection.should_receive(:add).with(hash_including(:published_at_d => '1983-07-08T09:00:00Z'))
63
+ connection.should_receive(:add).with([hash_including(:published_at_d => '1983-07-08T09:00:00Z')])
49
64
  session.index post
50
65
  end
51
66
 
52
67
  it 'should correctly index a boolean field' do
53
68
  post :featured => true
54
- connection.should_receive(:add).with(hash_including(:featured_b => 'true'))
69
+ connection.should_receive(:add).with([hash_including(:featured_b => 'true')])
55
70
  session.index post
56
71
  end
57
72
 
58
73
  it 'should correctly index a false boolean field' do
59
74
  post :featured => false
60
- connection.should_receive(:add).with(hash_including(:featured_b => 'false'))
75
+ connection.should_receive(:add).with([hash_including(:featured_b => 'false')])
61
76
  session.index post
62
77
  end
63
78
 
64
79
  it 'should not index a nil boolean field' do
65
80
  post
66
- connection.should_receive(:add).with(hash_not_including(:featured_b))
81
+ connection.should_receive(:add).with([hash_not_including(:featured_b)])
67
82
  session.index post
68
83
  end
69
84
 
70
85
  it 'should correctly index a virtual field' do
71
86
  post :title => 'The Blog Post'
72
- connection.should_receive(:add).with(hash_including(:sort_title_s => 'blog post'))
87
+ connection.should_receive(:add).with([hash_including(:sort_title_s => 'blog post')])
73
88
  session.index post
74
89
  end
75
90
 
76
91
  it 'should correctly index an external virtual field' do
77
92
  post :category_ids => [1, 2, 3]
78
- connection.should_receive(:add).with(hash_including(:primary_category_id_i => '1'))
93
+ connection.should_receive(:add).with([hash_including(:primary_category_id_i => '1')])
79
94
  session.index post
80
95
  end
81
96
 
82
97
  it 'should correctly index a field that is defined on a superclass' do
83
98
  Sunspot.setup(BaseClass) { string :author_name }
84
99
  post :author_name => 'Mat Brown'
85
- connection.should_receive(:add).with(hash_including(:author_name_s => 'Mat Brown'))
100
+ connection.should_receive(:add).with([hash_including(:author_name_s => 'Mat Brown')])
86
101
  session.index post
87
102
  end
88
103
 
@@ -124,37 +139,37 @@ describe 'indexer' do
124
139
  describe 'dynamic fields' do
125
140
  it 'should index string data' do
126
141
  post(:custom_string => { :test => 'string' })
127
- connection.should_receive(:add).with(hash_including(:"custom_string:test_s" => 'string'))
142
+ connection.should_receive(:add).with([hash_including(:"custom_string:test_s" => 'string')])
128
143
  session.index(post)
129
144
  end
130
145
 
131
146
  it 'should index integer data with virtual accessor' do
132
147
  post(:category_ids => [1, 2])
133
- connection.should_receive(:add).with(hash_including(:"custom_integer:1_i" => '1', :"custom_integer:2_i" => '1'))
148
+ connection.should_receive(:add).with([hash_including(:"custom_integer:1_i" => '1', :"custom_integer:2_i" => '1')])
134
149
  session.index(post)
135
150
  end
136
151
 
137
152
  it 'should index float data' do
138
153
  post(:custom_fl => { :test => 1.5 })
139
- connection.should_receive(:add).with(hash_including(:"custom_float:test_fm" => '1.5'))
154
+ connection.should_receive(:add).with([hash_including(:"custom_float:test_fm" => '1.5')])
140
155
  session.index(post)
141
156
  end
142
157
 
143
158
  it 'should index time data' do
144
159
  post(:custom_time => { :test => Time.parse('2009-05-18 18:05:00 -0400') })
145
- connection.should_receive(:add).with(hash_including(:"custom_time:test_d" => '2009-05-18T22:05:00Z'))
160
+ connection.should_receive(:add).with([hash_including(:"custom_time:test_d" => '2009-05-18T22:05:00Z')])
146
161
  session.index(post)
147
162
  end
148
163
 
149
164
  it 'should index boolean data' do
150
165
  post(:custom_boolean => { :test => false })
151
- connection.should_receive(:add).with(hash_including(:"custom_boolean:test_b" => 'false'))
166
+ connection.should_receive(:add).with([hash_including(:"custom_boolean:test_b" => 'false')])
152
167
  session.index(post)
153
168
  end
154
169
 
155
170
  it 'should index multiple values for a field' do
156
171
  post(:custom_fl => { :test => [1.0, 2.1, 3.2] })
157
- connection.should_receive(:add).with(hash_including(:"custom_float:test_fm" => %w(1.0 2.1 3.2)))
172
+ connection.should_receive(:add).with([hash_including(:"custom_float:test_fm" => %w(1.0 2.1 3.2))])
158
173
  session.index(post)
159
174
  end
160
175
  end
@@ -3,7 +3,7 @@ class Comment < BaseClass
3
3
  @@comments = [nil]
4
4
 
5
5
  attr_reader :id
6
- attr_accessor :author_name, :published_at, :body
6
+ attr_accessor :author_name, :published_at, :body, :average_rating
7
7
 
8
8
  def initialize(attrs = {})
9
9
  @id = @@id += 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outoftime-sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-27 00:00:00 -07:00
12
+ date: 2009-06-03 00:00:00 -07:00
13
13
  default_executable: sunspot-solr
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency