thinking-sphinx 1.3.9 → 1.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -0
- data/VERSION +1 -1
- data/features/attribute_updates.feature +11 -0
- data/features/step_definitions/alpha_steps.rb +9 -0
- data/features/support/db/migrations/create_alphas.rb +1 -0
- data/features/support/models/alpha.rb +1 -0
- data/lib/thinking_sphinx.rb +4 -0
- data/lib/thinking_sphinx/active_record.rb +14 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +1 -6
- data/lib/thinking_sphinx/attribute.rb +16 -1
- data/lib/thinking_sphinx/configuration.rb +2 -2
- data/lib/thinking_sphinx/tasks.rb +1 -1
- data/spec/thinking_sphinx/active_record_spec.rb +8 -0
- data/spec/thinking_sphinx/attribute_spec.rb +39 -0
- data/spec/thinking_sphinx_spec.rb +11 -0
- data/tasks/distribution.rb +1 -1
- metadata +3 -3
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.10
|
@@ -37,3 +37,14 @@ Feature: Update attributes directly to Sphinx
|
|
37
37
|
|
38
38
|
When I search for the document id of beta eight in the beta_delta index
|
39
39
|
Then it should not exist
|
40
|
+
|
41
|
+
Scenario: Updating boolean attribute in Sphinx
|
42
|
+
Given Sphinx is running
|
43
|
+
And I am searching on alphas
|
44
|
+
When I filter by active alphas
|
45
|
+
Then I should get 10 results
|
46
|
+
|
47
|
+
When I flag alpha five as inactive
|
48
|
+
And I wait for Sphinx to catch up
|
49
|
+
And I filter by active alphas
|
50
|
+
Then I should get 9 results
|
@@ -5,3 +5,12 @@ end
|
|
5
5
|
When /^I change the (\w+) of alpha (\w+) to (\w+)$/ do |column, name, replacement|
|
6
6
|
Alpha.find_by_name(name).update_attributes(column.to_sym => replacement)
|
7
7
|
end
|
8
|
+
|
9
|
+
When /^I filter by active alphas$/ do
|
10
|
+
@results = nil
|
11
|
+
@with[:active] = true
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^I flag alpha (\w+) as inactive$/ do |name|
|
15
|
+
Alpha.find_by_name(name).update_attributes(:active => false)
|
16
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
ActiveRecord::Base.connection.create_table :alphas, :force => true do |t|
|
2
2
|
t.column :name, :string, :null => false
|
3
3
|
t.column :value, :integer, :null => false
|
4
|
+
t.column :active, :boolean, :null => false, :default => true
|
4
5
|
t.column :cost, :decimal, :precision => 10, :scale => 6
|
5
6
|
t.column :created_on, :date
|
6
7
|
t.column :created_at, :timestamp
|
data/lib/thinking_sphinx.rb
CHANGED
@@ -71,6 +71,10 @@ module ThinkingSphinx
|
|
71
71
|
|
72
72
|
Thread.current[:thinking_sphinx_context]
|
73
73
|
end
|
74
|
+
|
75
|
+
def self.reset_context!
|
76
|
+
Thread.current[:thinking_sphinx_context] = nil
|
77
|
+
end
|
74
78
|
|
75
79
|
def self.unique_id_expression(offset = nil)
|
76
80
|
"* #{context.indexed_models.size} + #{offset || 0}"
|
@@ -53,6 +53,20 @@ module ThinkingSphinx
|
|
53
53
|
self.name.underscore.tr(':/\\', '_')
|
54
54
|
end
|
55
55
|
|
56
|
+
#
|
57
|
+
# The above method to_crc32s is dependant on the subclasses being loaded consistently
|
58
|
+
# After a reset_subclasses is called (during a Dispatcher.cleanup_application in development)
|
59
|
+
# Our subclasses will be lost but our context will not reload them for us.
|
60
|
+
#
|
61
|
+
# We reset the context which causes the subclasses to be reloaded next time the context is called.
|
62
|
+
#
|
63
|
+
def reset_subclasses_with_thinking_sphinx
|
64
|
+
reset_subclasses_without_thinking_sphinx
|
65
|
+
ThinkingSphinx.reset_context!
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method_chain :reset_subclasses, :thinking_sphinx
|
69
|
+
|
56
70
|
private
|
57
71
|
|
58
72
|
def defined_indexes?
|
@@ -37,12 +37,7 @@ module ThinkingSphinx
|
|
37
37
|
|
38
38
|
def attribute_values_for_index(index)
|
39
39
|
updatable_attributes(index).inject({}) { |hash, attrib|
|
40
|
-
|
41
|
-
hash[attrib.unique_name.to_s] = attrib.live_value(self).to_time.to_i
|
42
|
-
else
|
43
|
-
hash[attrib.unique_name.to_s] = attrib.live_value self
|
44
|
-
end
|
45
|
-
|
40
|
+
hash[attrib.unique_name.to_s] = attrib.live_value self
|
46
41
|
hash
|
47
42
|
}
|
48
43
|
end
|
@@ -180,7 +180,7 @@ module ThinkingSphinx
|
|
180
180
|
object = instance
|
181
181
|
column = @columns.first
|
182
182
|
column.__stack.each { |method| object = object.send(method) }
|
183
|
-
object.send(column.__name)
|
183
|
+
sphinx_value object.send(column.__name)
|
184
184
|
end
|
185
185
|
|
186
186
|
def all_ints?
|
@@ -337,5 +337,20 @@ block:
|
|
337
337
|
}
|
338
338
|
}
|
339
339
|
end
|
340
|
+
|
341
|
+
def sphinx_value(value)
|
342
|
+
case value
|
343
|
+
when TrueClass
|
344
|
+
1
|
345
|
+
when FalseClass, NilClass
|
346
|
+
0
|
347
|
+
when Time
|
348
|
+
value.to_i
|
349
|
+
when Date
|
350
|
+
value.to_time.to_i
|
351
|
+
else
|
352
|
+
value
|
353
|
+
end
|
354
|
+
end
|
340
355
|
end
|
341
356
|
end
|
@@ -13,7 +13,7 @@ module ThinkingSphinx
|
|
13
13
|
# pid file:: log/searchd.#{environment}.pid
|
14
14
|
# searchd files:: db/sphinx/#{environment}/
|
15
15
|
# address:: 127.0.0.1
|
16
|
-
# port::
|
16
|
+
# port:: 9312
|
17
17
|
# allow star:: false
|
18
18
|
# min prefix length:: 1
|
19
19
|
# min infix length:: 1
|
@@ -94,7 +94,7 @@ module ThinkingSphinx
|
|
94
94
|
|
95
95
|
@configuration = Riddle::Configuration.new
|
96
96
|
@configuration.searchd.address = "127.0.0.1"
|
97
|
-
@configuration.searchd.port =
|
97
|
+
@configuration.searchd.port = 9312
|
98
98
|
@configuration.searchd.pid_file = "#{self.app_root}/log/searchd.#{environment}.pid"
|
99
99
|
@configuration.searchd.log = "#{self.app_root}/log/searchd.log"
|
100
100
|
@configuration.searchd.query_log = "#{self.app_root}/log/searchd.query.log"
|
@@ -611,4 +611,12 @@ describe ThinkingSphinx::ActiveRecord do
|
|
611
611
|
Alpha.should_not have_sphinx_indexes
|
612
612
|
end
|
613
613
|
end
|
614
|
+
|
615
|
+
describe '.reset_subclasses' do
|
616
|
+
it "should reset the stored context" do
|
617
|
+
ThinkingSphinx.should_receive(:reset_context!)
|
618
|
+
|
619
|
+
ActiveRecord::Base.reset_subclasses
|
620
|
+
end
|
621
|
+
end
|
614
622
|
end
|
@@ -504,4 +504,43 @@ describe ThinkingSphinx::Attribute do
|
|
504
504
|
@statement.should match(/SELECT cricket_team_id, id FROM tags/)
|
505
505
|
end
|
506
506
|
end
|
507
|
+
|
508
|
+
describe '#live_value' do
|
509
|
+
before :each do
|
510
|
+
@attribute = ThinkingSphinx::Attribute.new @source, [
|
511
|
+
stub('column', :__stack => [], :__name => "col_name")
|
512
|
+
]
|
513
|
+
@instance = stub('model')
|
514
|
+
end
|
515
|
+
|
516
|
+
it "should translate boolean values to integers" do
|
517
|
+
@instance.stub!(:col_name => true)
|
518
|
+
@attribute.live_value(@instance).should == 1
|
519
|
+
|
520
|
+
@instance.stub!(:col_name => false)
|
521
|
+
@attribute.live_value(@instance).should == 0
|
522
|
+
end
|
523
|
+
|
524
|
+
it "should translate timestamps to integers" do
|
525
|
+
now = Time.now
|
526
|
+
@instance.stub!(:col_name => now)
|
527
|
+
@attribute.live_value(@instance).should == now.to_i
|
528
|
+
end
|
529
|
+
|
530
|
+
it "should translate dates to timestamp integers" do
|
531
|
+
today = Date.today
|
532
|
+
@instance.stub!(:col_name => today)
|
533
|
+
@attribute.live_value(@instance).should == today.to_time.to_i
|
534
|
+
end
|
535
|
+
|
536
|
+
it "should translate nils to 0" do
|
537
|
+
@instance.stub!(:col_name => nil)
|
538
|
+
@attribute.live_value(@instance).should == 0
|
539
|
+
end
|
540
|
+
|
541
|
+
it "should return integers as integers" do
|
542
|
+
@instance.stub!(:col_name => 42)
|
543
|
+
@attribute.live_value(@instance).should == 42
|
544
|
+
end
|
545
|
+
end
|
507
546
|
end
|
@@ -16,6 +16,17 @@ describe ThinkingSphinx do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
describe '.reset_context!' do
|
20
|
+
it "should remove the existing Context instance" do
|
21
|
+
existing = ThinkingSphinx.context
|
22
|
+
|
23
|
+
ThinkingSphinx.reset_context!
|
24
|
+
ThinkingSphinx.context.should_not == existing
|
25
|
+
|
26
|
+
Thread.current[:thinking_sphinx_context] = existing
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
describe '.define_indexes?' do
|
20
31
|
it "should define indexes by default" do
|
21
32
|
ThinkingSphinx.define_indexes?.should be_true
|
data/tasks/distribution.rb
CHANGED
@@ -28,7 +28,7 @@ Jeweler::Tasks.new do |gem|
|
|
28
28
|
]
|
29
29
|
|
30
30
|
gem.add_dependency 'activerecord', '>= 1.15.6'
|
31
|
-
gem.add_dependency 'riddle', '>= 1.0.
|
31
|
+
gem.add_dependency 'riddle', '>= 1.0.8'
|
32
32
|
gem.add_dependency 'after_commit', '>= 1.0.5'
|
33
33
|
|
34
34
|
gem.post_install_message = <<-MESSAGE
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.10
|
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-12-
|
12
|
+
date: 2009-12-10 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.
|
33
|
+
version: 1.0.8
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: after_commit
|