freelancing-god-thinking-sphinx 1.1.23 → 1.1.24

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -141,3 +141,6 @@ Since I first released this library, there's been quite a few people who have su
141
141
  * Paul Campbell
142
142
  * Matthew Beale
143
143
  * Tom Simnett
144
+ * Erik Ostrom
145
+ * Ole Riesenberg
146
+ * Josh Kalderimis
@@ -37,7 +37,7 @@ module ThinkingSphinx
37
37
  module Version #:nodoc:
38
38
  Major = 1
39
39
  Minor = 1
40
- Tiny = 23
40
+ Tiny = 24
41
41
 
42
42
  String = [Major, Minor, Tiny].join('.')
43
43
  end
@@ -37,7 +37,8 @@ module ThinkingSphinx
37
37
  end
38
38
 
39
39
  def convert_nulls(clause, default = '')
40
- default = "'#{default}'" if default.is_a?(String)
40
+ default = "'#{default}'" if default.is_a?(String)
41
+ default = 'NULL' if default.nil?
41
42
 
42
43
  "COALESCE(#{clause}, #{default})"
43
44
  end
@@ -132,4 +133,4 @@ module ThinkingSphinx
132
133
  execute function, true
133
134
  end
134
135
  end
135
- end
136
+ end
@@ -89,14 +89,21 @@ module ThinkingSphinx
89
89
  def to_select_sql
90
90
  return nil unless include_as_association?
91
91
 
92
- separator = all_ints? || @crc ? ',' : ' '
92
+ separator = all_ints? || all_datetimes? || @crc ? ',' : ' '
93
93
 
94
94
  clause = @columns.collect { |column|
95
95
  part = column_with_prefix(column)
96
- type == :string ? adapter.convert_nulls(part) : part
96
+ case type
97
+ when :string
98
+ adapter.convert_nulls(part)
99
+ when :datetime
100
+ adapter.cast_to_datetime(part)
101
+ else
102
+ part
103
+ end
97
104
  }.join(', ')
98
105
 
99
- clause = adapter.cast_to_datetime(clause) if type == :datetime
106
+ # clause = adapter.cast_to_datetime(clause) if type == :datetime
100
107
  clause = adapter.crc(clause) if @crc
101
108
  clause = adapter.concatenate(clause, separator) if concat_ws?
102
109
  clause = adapter.group_concatenate(clause, separator) if is_many?
@@ -142,6 +149,8 @@ module ThinkingSphinx
142
149
  def type
143
150
  @type ||= begin
144
151
  base_type = case
152
+ when is_many_datetimes?
153
+ :datetime
145
154
  when is_many?, is_many_ints?
146
155
  :multi
147
156
  when @associations.values.flatten.length > 1
@@ -171,14 +180,11 @@ module ThinkingSphinx
171
180
  end
172
181
 
173
182
  def all_ints?
174
- @columns.all? { |col|
175
- klasses = @associations[col].empty? ? [@model] :
176
- @associations[col].collect { |assoc| assoc.reflection.klass }
177
- klasses.all? { |klass|
178
- column = klass.columns.detect { |column| column.name == col.__name.to_s }
179
- !column.nil? && column.type == :integer
180
- }
181
- }
183
+ all_of_type?(:integer)
184
+ end
185
+
186
+ def all_datetimes?
187
+ all_of_type?(:datetime, :date, :timestamp)
182
188
  end
183
189
 
184
190
  private
@@ -274,14 +280,19 @@ WHERE #{@source.index.delta_object.clause(model, true)})
274
280
  def is_many_ints?
275
281
  concat_ws? && all_ints?
276
282
  end
277
-
283
+
284
+ def is_many_datetimes?
285
+ is_many? && all_datetimes?
286
+ end
287
+
278
288
  def type_from_database
279
289
  klass = @associations.values.flatten.first ?
280
290
  @associations.values.flatten.first.reflection.klass : @model
281
291
 
282
- klass.columns.detect { |col|
292
+ column = klass.columns.detect { |col|
283
293
  @columns.collect { |c| c.__name.to_s }.include? col.name
284
- }.type
294
+ }
295
+ column.nil? ? nil : column.type
285
296
  end
286
297
 
287
298
  def translated_type_from_database
@@ -303,5 +314,16 @@ block:
303
314
  MESSAGE
304
315
  end
305
316
  end
317
+
318
+ def all_of_type?(*column_types)
319
+ @columns.all? { |col|
320
+ klasses = @associations[col].empty? ? [@model] :
321
+ @associations[col].collect { |assoc| assoc.reflection.klass }
322
+ klasses.all? { |klass|
323
+ column = klass.columns.detect { |column| column.name == col.__name.to_s }
324
+ !column.nil? && column_types.include?(column.type)
325
+ }
326
+ }
327
+ end
306
328
  end
307
329
  end
@@ -1,11 +1,26 @@
1
1
  Capistrano::Configuration.instance(:must_exist).load do
2
2
  namespace :thinking_sphinx do
3
3
  namespace :install do
4
- desc "Install Sphinx by source"
4
+ desc <<-DESC
5
+ Install Sphinx by source
6
+
7
+ If Postgres is available, Sphinx will use it.
8
+
9
+ If the variable :thinking_sphinx_configure_args is set, it will
10
+ be passed to the Sphinx configure script. You can use this to
11
+ install Sphinx in a non-standard location:
12
+
13
+ set :thinking_sphinx_configure_args, "--prefix=$HOME/software"
14
+ DESC
15
+
5
16
  task :sphinx do
6
17
  with_postgres = false
7
- run "which pg_config" do |channel, stream, data|
8
- with_postgres = !(data.nil? || data == "")
18
+ begin
19
+ run "which pg_config" do |channel, stream, data|
20
+ with_postgres = !(data.nil? || data == "")
21
+ end
22
+ rescue Capistrano::CommandError => e
23
+ puts "Continuing despite error: #{e.message}"
9
24
  end
10
25
 
11
26
  args = []
@@ -14,14 +29,15 @@ Capistrano::Configuration.instance(:must_exist).load do
14
29
  args << "--with-pgsql=#{data}"
15
30
  end
16
31
  end
17
-
32
+ args << fetch(:thinking_sphinx_configure_args, '')
33
+
18
34
  commands = <<-CMD
19
35
  wget -q http://www.sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz >> sphinx.log
20
36
  tar xzvf sphinx-0.9.8.1.tar.gz
21
37
  cd sphinx-0.9.8.1
22
38
  ./configure #{args.join(" ")}
23
39
  make
24
- sudo make install
40
+ #{try_sudo} make install
25
41
  rm -rf sphinx-0.9.8.1 sphinx-0.9.8.1.tar.gz
26
42
  CMD
27
43
  run commands.split(/\n\s+/).join(" && ")
@@ -29,7 +45,7 @@ Capistrano::Configuration.instance(:must_exist).load do
29
45
 
30
46
  desc "Install Thinking Sphinx as a gem from GitHub"
31
47
  task :ts do
32
- sudo "gem install freelancing-god-thinking-sphinx --source http://gems.github.com"
48
+ run "#{try_sudo} gem install freelancing-god-thinking-sphinx --source http://gems.github.com"
33
49
  end
34
50
  end
35
51
 
@@ -70,7 +86,7 @@ Capistrano::Configuration.instance(:must_exist).load do
70
86
 
71
87
  desc "Add the shared folder for sphinx files for the production environment"
72
88
  task :shared_sphinx_folder, :roles => :web do
73
- sudo "mkdir -p #{shared_path}/db/sphinx/production"
89
+ run "mkdir -p #{shared_path}/db/sphinx/production"
74
90
  end
75
91
 
76
92
  def rake(*tasks)
@@ -112,7 +112,9 @@ GROUP BY #{ sql_group_clause }
112
112
  end
113
113
 
114
114
  def crc_column
115
- if @model.column_names.include?(@model.inheritance_column)
115
+ if @model.table_exists? &&
116
+ @model.column_names.include?(@model.inheritance_column)
117
+
116
118
  adapter.cast_to_unsigned(adapter.convert_nulls(
117
119
  adapter.crc(adapter.quote_with_table(@model.inheritance_column), true),
118
120
  @model.to_crc32
@@ -88,6 +88,19 @@ describe ThinkingSphinx::Attribute do
88
88
  end
89
89
  end
90
90
 
91
+ describe '#to_select_sql' do
92
+ it "should convert a mixture of dates and datetimes to timestamps" do
93
+ attribute = ThinkingSphinx::Attribute.new(@source,
94
+ [ ThinkingSphinx::Index::FauxColumn.new(:created_at),
95
+ ThinkingSphinx::Index::FauxColumn.new(:created_on) ],
96
+ :as => :times
97
+ )
98
+ attribute.model = Friendship
99
+
100
+ attribute.to_select_sql.should == "CONCAT_WS(',', UNIX_TIMESTAMP(`friendships`.`created_at`), UNIX_TIMESTAMP(`friendships`.`created_on`)) AS `times`"
101
+ end
102
+ end
103
+
91
104
  describe "is_many? method" do
92
105
  before :each do
93
106
  @assoc_a = Object.stub_instance(:is_many? => true)
@@ -191,7 +204,7 @@ describe ThinkingSphinx::Attribute do
191
204
  attribute.model = Person
192
205
  attribute.columns.each { |col| attribute.associations[col] = [] }
193
206
 
194
- attribute.send(:all_ints?).should be_true
207
+ attribute.should be_all_ints
195
208
  end
196
209
 
197
210
  it "should return false if only some columns are integers" do
@@ -202,7 +215,7 @@ describe ThinkingSphinx::Attribute do
202
215
  attribute.model = Person
203
216
  attribute.columns.each { |col| attribute.associations[col] = [] }
204
217
 
205
- attribute.send(:all_ints?).should be_false
218
+ attribute.should_not be_all_ints
206
219
  end
207
220
 
208
221
  it "should return false if no columns are integers" do
@@ -213,7 +226,42 @@ describe ThinkingSphinx::Attribute do
213
226
  attribute.model = Person
214
227
  attribute.columns.each { |col| attribute.associations[col] = [] }
215
228
 
216
- attribute.send(:all_ints?).should be_false
229
+ attribute.should_not be_all_ints
230
+ end
231
+ end
232
+
233
+ describe "all_datetimes? method" do
234
+ it "should return true if all columns are datetimes" do
235
+ attribute = ThinkingSphinx::Attribute.new(@source,
236
+ [ ThinkingSphinx::Index::FauxColumn.new(:created_at),
237
+ ThinkingSphinx::Index::FauxColumn.new(:updated_at) ]
238
+ )
239
+ attribute.model = Friendship
240
+ attribute.columns.each { |col| attribute.associations[col] = [] }
241
+
242
+ attribute.should be_all_datetimes
243
+ end
244
+
245
+ it "should return false if only some columns are datetimes" do
246
+ attribute = ThinkingSphinx::Attribute.new(@source,
247
+ [ ThinkingSphinx::Index::FauxColumn.new(:id),
248
+ ThinkingSphinx::Index::FauxColumn.new(:created_at) ]
249
+ )
250
+ attribute.model = Friendship
251
+ attribute.columns.each { |col| attribute.associations[col] = [] }
252
+
253
+ attribute.should_not be_all_datetimes
254
+ end
255
+
256
+ it "should return true if all columns can be " do
257
+ attribute = ThinkingSphinx::Attribute.new(@source,
258
+ [ ThinkingSphinx::Index::FauxColumn.new(:created_at),
259
+ ThinkingSphinx::Index::FauxColumn.new(:created_on) ]
260
+ )
261
+ attribute.model = Friendship
262
+ attribute.columns.each { |col| attribute.associations[col] = [] }
263
+
264
+ attribute.should be_all_datetimes
217
265
  end
218
266
  end
219
267
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freelancing-god-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.23
4
+ version: 1.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-28 00:00:00 -07:00
12
+ date: 2009-07-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15