DrMark-thinking-sphinx 1.1.6 → 1.1.14
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 → README.textile} +84 -84
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
- data/lib/thinking_sphinx/active_record/delta.rb +10 -1
- data/lib/thinking_sphinx/active_record.rb +10 -3
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +1 -1
- data/lib/thinking_sphinx/attribute.rb +44 -134
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/collection.rb +1 -0
- data/lib/thinking_sphinx/configuration.rb +7 -3
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +1 -1
- data/lib/thinking_sphinx/deltas/default_delta.rb +3 -2
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +4 -2
- data/lib/thinking_sphinx/deltas.rb +9 -6
- data/lib/thinking_sphinx/deploy/capistrano.rb +82 -0
- data/lib/thinking_sphinx/facet.rb +68 -18
- data/lib/thinking_sphinx/facet_collection.rb +16 -17
- data/lib/thinking_sphinx/field.rb +7 -97
- data/lib/thinking_sphinx/index/builder.rb +255 -232
- data/lib/thinking_sphinx/index.rb +37 -349
- data/lib/thinking_sphinx/property.rb +160 -0
- data/lib/thinking_sphinx/search/facets.rb +98 -0
- data/lib/thinking_sphinx/search.rb +4 -73
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +124 -0
- data/lib/thinking_sphinx/source.rb +150 -0
- data/lib/thinking_sphinx/tasks.rb +1 -1
- data/lib/thinking_sphinx.rb +3 -1
- data/spec/unit/thinking_sphinx/active_record_spec.rb +14 -12
- data/spec/unit/thinking_sphinx/attribute_spec.rb +16 -11
- data/spec/unit/thinking_sphinx/facet_collection_spec.rb +64 -0
- data/spec/unit/thinking_sphinx/facet_spec.rb +278 -0
- data/spec/unit/thinking_sphinx/field_spec.rb +18 -9
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +347 -1
- data/spec/unit/thinking_sphinx/index_spec.rb +22 -27
- data/spec/unit/thinking_sphinx/rails_additions_spec.rb +183 -0
- data/spec/unit/thinking_sphinx/search_spec.rb +71 -0
- data/spec/unit/thinking_sphinx/source_spec.rb +156 -0
- data/tasks/distribution.rb +1 -1
- data/tasks/testing.rb +7 -15
- metadata +19 -3
@@ -1,15 +1,6 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Index do
|
4
|
-
describe "generated sql_query" do
|
5
|
-
it "should include explicit groupings if requested" do
|
6
|
-
@index = ThinkingSphinx::Index.new(Person)
|
7
|
-
|
8
|
-
@index.groupings << "custom_sql"
|
9
|
-
@index.to_riddle_for_core(0, 0).sql_query.should match(/GROUP BY.+custom_sql/)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
4
|
describe "prefix_fields method" do
|
14
5
|
before :each do
|
15
6
|
@index = ThinkingSphinx::Index.new(Person)
|
@@ -18,7 +9,7 @@ describe ThinkingSphinx::Index do
|
|
18
9
|
@field_b = ThinkingSphinx::Field.stub_instance(:prefixes => false)
|
19
10
|
@field_c = ThinkingSphinx::Field.stub_instance(:prefixes => true)
|
20
11
|
|
21
|
-
@index.fields
|
12
|
+
@index.stub_method(:fields => [@field_a, @field_b, @field_c])
|
22
13
|
end
|
23
14
|
|
24
15
|
it "should return fields that are flagged as prefixed" do
|
@@ -39,7 +30,7 @@ describe ThinkingSphinx::Index do
|
|
39
30
|
@field_b = ThinkingSphinx::Field.stub_instance(:infixes => false)
|
40
31
|
@field_c = ThinkingSphinx::Field.stub_instance(:infixes => true)
|
41
32
|
|
42
|
-
@index.fields
|
33
|
+
@index.stub_method(:fields => [@field_a, @field_b, @field_c])
|
43
34
|
end
|
44
35
|
|
45
36
|
it "should return fields that are flagged as infixed" do
|
@@ -54,12 +45,12 @@ describe ThinkingSphinx::Index do
|
|
54
45
|
|
55
46
|
describe "multi-value attribute as ranged-query with has-many association" do
|
56
47
|
before :each do
|
57
|
-
@index = ThinkingSphinx::Index.
|
48
|
+
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
49
|
+
indexes first_name
|
58
50
|
has tags(:id), :as => :tag_ids, :source => :ranged_query
|
59
51
|
end
|
60
|
-
@index.link!
|
61
52
|
|
62
|
-
@sql = @index.to_riddle_for_core(0, 0).sql_query
|
53
|
+
@sql = @index.sources.first.to_riddle_for_core(0, 0).sql_query
|
63
54
|
end
|
64
55
|
|
65
56
|
it "should not include attribute in select-clause sql_query" do
|
@@ -72,8 +63,8 @@ describe ThinkingSphinx::Index do
|
|
72
63
|
end
|
73
64
|
|
74
65
|
it "should include sql_attr_multi as ranged-query" do
|
75
|
-
attribute = @index.
|
76
|
-
attribute.
|
66
|
+
attribute = @index.attributes.detect { |attrib| attrib.unique_name == :tag_ids }
|
67
|
+
attribute.type_to_config.should == :sql_attr_multi
|
77
68
|
|
78
69
|
declaration, query, range_query = attribute.send(:config_value).split('; ')
|
79
70
|
declaration.should == "uint tag_ids from ranged-query"
|
@@ -84,12 +75,12 @@ describe ThinkingSphinx::Index do
|
|
84
75
|
|
85
76
|
describe "multi-value attribute as ranged-query with has-many-through association" do
|
86
77
|
before :each do
|
87
|
-
@index = ThinkingSphinx::Index.
|
78
|
+
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
79
|
+
indexes first_name
|
88
80
|
has football_teams(:id), :as => :football_teams_ids, :source => :ranged_query
|
89
81
|
end
|
90
|
-
@index.link!
|
91
82
|
|
92
|
-
@sql = @index.to_riddle_for_core(0, 0).sql_query
|
83
|
+
@sql = @index.sources.first.to_riddle_for_core(0, 0).sql_query
|
93
84
|
end
|
94
85
|
|
95
86
|
it "should not include attribute in select-clause sql_query" do
|
@@ -102,8 +93,10 @@ describe ThinkingSphinx::Index do
|
|
102
93
|
end
|
103
94
|
|
104
95
|
it "should include sql_attr_multi as ranged-query" do
|
105
|
-
attribute = @index.
|
106
|
-
|
96
|
+
attribute = @index.attributes.detect { |attrib|
|
97
|
+
attrib.unique_name == :football_teams_ids
|
98
|
+
}
|
99
|
+
attribute.type_to_config.should == :sql_attr_multi
|
107
100
|
|
108
101
|
declaration, query, range_query = attribute.send(:config_value).split('; ')
|
109
102
|
declaration.should == "uint football_teams_ids from ranged-query"
|
@@ -114,12 +107,12 @@ describe ThinkingSphinx::Index do
|
|
114
107
|
|
115
108
|
describe "multi-value attribute as ranged-query with has-many-through association and foreign_key" do
|
116
109
|
before :each do
|
117
|
-
@index = ThinkingSphinx::Index.
|
110
|
+
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
111
|
+
indexes first_name
|
118
112
|
has friends(:id), :as => :friend_ids, :source => :ranged_query
|
119
113
|
end
|
120
|
-
@index.link!
|
121
114
|
|
122
|
-
@sql = @index.to_riddle_for_core(0, 0).sql_query
|
115
|
+
@sql = @index.sources.first.to_riddle_for_core(0, 0).sql_query
|
123
116
|
end
|
124
117
|
|
125
118
|
it "should not include attribute in select-clause sql_query" do
|
@@ -132,8 +125,10 @@ describe ThinkingSphinx::Index do
|
|
132
125
|
end
|
133
126
|
|
134
127
|
it "should include sql_attr_multi as ranged-query" do
|
135
|
-
attribute = @index.
|
136
|
-
|
128
|
+
attribute = @index.attributes.detect { |attrib|
|
129
|
+
attrib.unique_name == :friend_ids
|
130
|
+
}
|
131
|
+
attribute.type_to_config.should == :sql_attr_multi
|
137
132
|
|
138
133
|
declaration, query, range_query = attribute.send(:config_value).split('; ')
|
139
134
|
declaration.should == "uint friend_ids from ranged-query"
|
@@ -141,4 +136,4 @@ describe ThinkingSphinx::Index do
|
|
141
136
|
range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
|
142
137
|
end
|
143
138
|
end
|
144
|
-
end
|
139
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::HashExcept do
|
4
|
+
before(:each) do
|
5
|
+
@hash = { :number => 20, :letter => 'b', :shape => 'rectangle' }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "except method" do
|
9
|
+
it "returns a hash without the specified keys" do
|
10
|
+
new_hash = @hash.except(:number)
|
11
|
+
new_hash.should_not have_key(:number)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "except! method" do
|
16
|
+
it "modifies hash removing specified keys" do
|
17
|
+
@hash.except!(:number)
|
18
|
+
@hash.should_not have_key(:number)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "extends Hash" do
|
23
|
+
it 'with except' do
|
24
|
+
Hash.instance_methods.include?('except').should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'with except!' do
|
28
|
+
Hash.instance_methods.include?('except!').should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ThinkingSphinx::ArrayExtractOptions do
|
34
|
+
describe 'extract_options! method' do
|
35
|
+
it 'returns a hash' do
|
36
|
+
array = []
|
37
|
+
array.extract_options!.should be_kind_of(Hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the last option if it is a hash' do
|
41
|
+
array = ['a', 'b', {:c => 'd'}]
|
42
|
+
array.extract_options!.should == {:c => 'd'}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "extends Array" do
|
47
|
+
it 'with extract_options!' do
|
48
|
+
Array.instance_methods.include?('extract_options!').should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ThinkingSphinx::AbstractQuotedTableName do
|
54
|
+
describe 'quote_table_name method' do
|
55
|
+
it 'calls quote_column_name' do
|
56
|
+
adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql')
|
57
|
+
adapter.should_receive(:quote_column_name).with('messages')
|
58
|
+
adapter.quote_table_name('messages')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "extends ActiveRecord::ConnectionAdapters::AbstractAdapter" do
|
63
|
+
it 'with quote_table_name' do
|
64
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_methods.include?('quote_table_name').should be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe ThinkingSphinx::MysqlQuotedTableName do
|
70
|
+
describe "quote_table_name method" do
|
71
|
+
it 'correctly quotes' do
|
72
|
+
adapter = ActiveRecord::Base.connection
|
73
|
+
adapter.quote_table_name('thinking_sphinx.messages').should == "`thinking_sphinx`.`messages`"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "extends ActiveRecord::ConnectionAdapters::MysqlAdapter" do
|
78
|
+
it 'with quote_table_name' do
|
79
|
+
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
|
80
|
+
ActiveRecord::ConnectionAdapters.const_get(adapter).instance_methods.include?("quote_table_name").should be_true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ThinkingSphinx::ActiveRecordQuotedName do
|
86
|
+
describe "quoted_table_name method" do
|
87
|
+
it 'returns table name wrappd in quotes' do
|
88
|
+
Person.quoted_table_name.should == '`people`'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "extends ActiveRecord::Base" do
|
93
|
+
it 'with quoted_table_name' do
|
94
|
+
ActiveRecord::Base.respond_to?("quoted_table_name").should be_true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe ThinkingSphinx::ActiveRecordStoreFullSTIClass do
|
100
|
+
describe "store_full_sti_class method" do
|
101
|
+
it 'returns false' do
|
102
|
+
Person.store_full_sti_class.should be_false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "extends ActiveRecord::Base" do
|
107
|
+
it 'with store_full_sti_class' do
|
108
|
+
ActiveRecord::Base.respond_to?(:store_full_sti_class).should be_true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class TestModel
|
114
|
+
@@squares = 89
|
115
|
+
@@circles = 43
|
116
|
+
|
117
|
+
def number_of_polygons
|
118
|
+
@@polygons
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe ThinkingSphinx::ClassAttributeMethods do
|
123
|
+
describe "cattr_reader method" do
|
124
|
+
it 'creates getters' do
|
125
|
+
TestModel.cattr_reader :herbivores
|
126
|
+
test_model = TestModel.new
|
127
|
+
test_model.respond_to?(:herbivores).should be_true
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'sets the initial value to nil' do
|
131
|
+
TestModel.cattr_reader :carnivores
|
132
|
+
test_model = TestModel.new
|
133
|
+
test_model.carnivores.should be_nil
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'does not override an existing definition' do
|
137
|
+
TestModel.cattr_reader :squares
|
138
|
+
test_model = TestModel.new
|
139
|
+
test_model.squares.should == 89
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "cattr_writer method" do
|
144
|
+
it 'creates setters' do
|
145
|
+
TestModel.cattr_writer :herbivores
|
146
|
+
test_model = TestModel.new
|
147
|
+
test_model.respond_to?(:herbivores=).should be_true
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'does not override an existing definition' do
|
151
|
+
TestModel.cattr_writer :polygons
|
152
|
+
test_model = TestModel.new
|
153
|
+
test_model.polygons = 100
|
154
|
+
test_model.number_of_polygons.should == 100
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "cattr_accessor method" do
|
159
|
+
it 'calls cattr_reader' do
|
160
|
+
Class.should_receive(:cattr_reader).with('polygons')
|
161
|
+
Class.cattr_accessor('polygons')
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'calls cattr_writer' do
|
165
|
+
Class.should_receive(:cattr_writer).with('polygons')
|
166
|
+
Class.cattr_accessor('polygons')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "extends Class" do
|
171
|
+
it 'with cattr_reader' do
|
172
|
+
Class.respond_to?('cattr_reader').should be_true
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'with cattr_writer' do
|
176
|
+
Class.respond_to?('cattr_writer').should be_true
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'with cattr_accessor' do
|
180
|
+
Class.respond_to?('cattr_accessor').should be_true
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -50,6 +50,77 @@ describe ThinkingSphinx::Search do
|
|
50
50
|
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
describe "facets method" do
|
55
|
+
before :each do
|
56
|
+
@person = Person.find(:first)
|
57
|
+
|
58
|
+
@city_results = [@person]
|
59
|
+
@city_results.stub!(:each_with_groupby_and_count).
|
60
|
+
and_yield(@person, @person.city.to_crc32, 1)
|
61
|
+
|
62
|
+
@birthday_results = [@person]
|
63
|
+
@birthday_results.stub!(:each_with_groupby_and_count).
|
64
|
+
and_yield(@person, @person.birthday.to_i, 1)
|
65
|
+
|
66
|
+
ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
|
67
|
+
|
68
|
+
@config = ThinkingSphinx::Configuration.instance
|
69
|
+
@config.configuration.searchd.max_matches = 10_000
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should use the system-set max_matches for limit on facet calls" do
|
73
|
+
ThinkingSphinx::Search.should_receive(:search) do |options|
|
74
|
+
options[:max_matches].should == 10_000
|
75
|
+
options[:limit].should == 10_000
|
76
|
+
end
|
77
|
+
|
78
|
+
ThinkingSphinx::Search.facets :all_attributes => true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should use the default max-matches if there is no explicit setting" do
|
82
|
+
@config.configuration.searchd.max_matches = nil
|
83
|
+
ThinkingSphinx::Search.should_receive(:search) do |options|
|
84
|
+
options[:max_matches].should == 1000
|
85
|
+
options[:limit].should == 1000
|
86
|
+
end
|
87
|
+
|
88
|
+
ThinkingSphinx::Search.facets :all_attributes => true
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should ignore user-provided max_matches and limit on facet calls" do
|
92
|
+
ThinkingSphinx::Search.should_receive(:search) do |options|
|
93
|
+
options[:max_matches].should == 10_000
|
94
|
+
options[:limit].should == 10_000
|
95
|
+
end
|
96
|
+
|
97
|
+
ThinkingSphinx::Search.facets(
|
98
|
+
:all_attributes => true,
|
99
|
+
:max_matches => 500,
|
100
|
+
:limit => 200
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "conflicting facets" do
|
105
|
+
before :each do
|
106
|
+
@index = ThinkingSphinx::Index::Builder.generate(Alpha) do
|
107
|
+
indexes :name
|
108
|
+
has :value, :as => :city, :facet => true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
after :each do
|
113
|
+
Alpha.sphinx_facets.delete_at(-1)
|
114
|
+
Alpha.sphinx_indexes.delete_at(-1)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise an error if searching with facets of same name but different type" do
|
118
|
+
lambda {
|
119
|
+
ThinkingSphinx::Search.facets :all_attributes => true
|
120
|
+
}.should raise_error
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
53
124
|
end
|
54
125
|
|
55
126
|
describe ThinkingSphinx::Search, "playing nice with Search model" do
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Source do
|
4
|
+
before :each do
|
5
|
+
@index = ThinkingSphinx::Index.new(Person)
|
6
|
+
@source = ThinkingSphinx::Source.new(@index, :sql_range_step => 1000)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should generate the name from the model" do
|
10
|
+
@source.name.should == "person"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle namespaced models for name generation" do
|
14
|
+
index = ThinkingSphinx::Index.new(Admin::Person)
|
15
|
+
source = ThinkingSphinx::Source.new(index)
|
16
|
+
source.name.should == "admin_person"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#to_riddle_for_core" do
|
20
|
+
before :each do
|
21
|
+
config = ThinkingSphinx::Configuration.instance
|
22
|
+
config.source_options[:sql_ranged_throttle] = 100
|
23
|
+
|
24
|
+
ThinkingSphinx::Field.new(
|
25
|
+
@source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
|
26
|
+
)
|
27
|
+
ThinkingSphinx::Field.new(
|
28
|
+
@source, ThinkingSphinx::Index::FauxColumn.new(:last_name)
|
29
|
+
)
|
30
|
+
|
31
|
+
ThinkingSphinx::Attribute.new(
|
32
|
+
@source, ThinkingSphinx::Index::FauxColumn.new(:id), :as => :internal_id
|
33
|
+
)
|
34
|
+
ThinkingSphinx::Attribute.new(
|
35
|
+
@source, ThinkingSphinx::Index::FauxColumn.new(:birthday)
|
36
|
+
)
|
37
|
+
ThinkingSphinx::Attribute.new(
|
38
|
+
@source, ThinkingSphinx::Index::FauxColumn.new(:tags, :id), :as => :tag_ids
|
39
|
+
)
|
40
|
+
|
41
|
+
@source.conditions << "`birthday` <= NOW()"
|
42
|
+
@source.groupings << "`first_name`"
|
43
|
+
|
44
|
+
@riddle = @source.to_riddle_for_core(1, 0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should generate a Riddle Source object" do
|
48
|
+
@riddle.should be_a_kind_of(Riddle::Configuration::SQLSource)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should use the index and name its own name" do
|
52
|
+
@riddle.name.should == "person_core_0"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should use the model's database connection to determine type" do
|
56
|
+
@riddle.type.should == "mysql"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should match the model's database settings" do
|
60
|
+
config = Person.connection.instance_variable_get(:@config)
|
61
|
+
@riddle.sql_db.should == config[:database]
|
62
|
+
@riddle.sql_user.should == config[:username]
|
63
|
+
@riddle.sql_pass.should == config[:password].to_s
|
64
|
+
@riddle.sql_host.should == config[:host]
|
65
|
+
@riddle.sql_port.should == config[:port]
|
66
|
+
@riddle.sql_sock.should == config[:socket]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should assign attributes" do
|
70
|
+
# 3 internal attributes plus the one requested
|
71
|
+
@riddle.sql_attr_uint.length.should == 4
|
72
|
+
@riddle.sql_attr_uint.last.should == :internal_id
|
73
|
+
|
74
|
+
@riddle.sql_attr_timestamp.length.should == 1
|
75
|
+
@riddle.sql_attr_timestamp.first.should == :birthday
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should set Sphinx Source options" do
|
79
|
+
@riddle.sql_range_step.should == 1000
|
80
|
+
@riddle.sql_ranged_throttle.should == 100
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#sql_query" do
|
84
|
+
before :each do
|
85
|
+
@query = @riddle.sql_query
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should select data from the model table" do
|
89
|
+
@query.should match(/FROM `people`/)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should select each of the fields" do
|
93
|
+
@query.should match(/`first_name`.+FROM/)
|
94
|
+
@query.should match(/`last_name`.+FROM/)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should select each of the attributes" do
|
98
|
+
@query.should match(/`id` AS `internal_id`.+FROM/)
|
99
|
+
@query.should match(/`birthday`.+FROM/)
|
100
|
+
@query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should include joins for required associations" do
|
104
|
+
@query.should match(/LEFT OUTER JOIN `tags`/)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should include any defined conditions" do
|
108
|
+
@query.should match(/WHERE.+`birthday` <= NOW()/)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should include any defined groupings" do
|
112
|
+
@query.should match(/GROUP BY.+`first_name`/)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#sql_query_range" do
|
117
|
+
before :each do
|
118
|
+
@query = @riddle.sql_query_range
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should select data from the model table" do
|
122
|
+
@query.should match(/FROM `people`/)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should select the minimum and the maximum ids" do
|
126
|
+
@query.should match(/SELECT.+MIN.+MAX.+FROM/)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#sql_query_info" do
|
131
|
+
before :each do
|
132
|
+
@query = @riddle.sql_query_info
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should select all fields from the model table" do
|
136
|
+
@query.should match(/SELECT \* FROM `people`/)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should filter the primary key with the offset" do
|
140
|
+
model_count = ThinkingSphinx.indexed_models.size
|
141
|
+
@query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#sql_query_pre" do
|
146
|
+
before :each do
|
147
|
+
@queries = @riddle.sql_query_pre
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should default to just the UTF8 statement" do
|
151
|
+
@queries.length.should == 1
|
152
|
+
@queries.first.should == "SET NAMES utf8"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
data/tasks/distribution.rb
CHANGED
data/tasks/testing.rb
CHANGED
@@ -20,13 +20,7 @@ namespace :features do
|
|
20
20
|
def add_task(name, description)
|
21
21
|
Cucumber::Rake::Task.new(name, description) do |t|
|
22
22
|
t.cucumber_opts = "--format pretty"
|
23
|
-
t.
|
24
|
-
"features/support/env",
|
25
|
-
"features/support/db/#{name}",
|
26
|
-
"features/support/db/active_record",
|
27
|
-
"features/support/post_database",
|
28
|
-
"features/step_definitions/**.rb"
|
29
|
-
]
|
23
|
+
t.profile = name
|
30
24
|
end
|
31
25
|
end
|
32
26
|
|
@@ -46,13 +40,7 @@ namespace :rcov do
|
|
46
40
|
def add_task(name, description)
|
47
41
|
Cucumber::Rake::Task.new(name, description) do |t|
|
48
42
|
t.cucumber_opts = "--format pretty"
|
49
|
-
t.
|
50
|
-
"features/support/env",
|
51
|
-
"features/support/db/#{name}",
|
52
|
-
"features/support/db/active_record",
|
53
|
-
"features/support/post_database",
|
54
|
-
"features/step_definitions/**.rb"
|
55
|
-
]
|
43
|
+
t.profile = name
|
56
44
|
t.rcov = true
|
57
45
|
t.rcov_opts = [
|
58
46
|
'--exclude', 'spec',
|
@@ -80,7 +68,11 @@ task :cucumber_defaults do
|
|
80
68
|
"--require #{path}"
|
81
69
|
}.join(" ")
|
82
70
|
|
71
|
+
features = FileList["features/*.feature"].join(" ")
|
72
|
+
|
83
73
|
File.open('cucumber.yml', 'w') { |f|
|
84
|
-
f.write "default: \"#{default_requires} #{step_definitions}\""
|
74
|
+
f.write "default: \"#{default_requires} #{step_definitions}\"\n\n"
|
75
|
+
f.write "mysql: \"#{default_requires} #{step_definitions} #{features}\"\n\n"
|
76
|
+
f.write "postgresql: \"#{default_requires.gsub(/mysql/, 'postgresql')} #{step_definitions} #{features}\""
|
85
77
|
}
|
86
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: DrMark-thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.14
|
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
|
+
date: 2009-05-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,6 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
+
- lib/thinking_sphinx/active_record/attribute_updates.rb
|
25
26
|
- lib/thinking_sphinx/active_record/delta.rb
|
26
27
|
- lib/thinking_sphinx/active_record/has_many_association.rb
|
27
28
|
- lib/thinking_sphinx/active_record/search.rb
|
@@ -31,6 +32,7 @@ files:
|
|
31
32
|
- lib/thinking_sphinx/adapters/postgresql_adapter.rb
|
32
33
|
- lib/thinking_sphinx/association.rb
|
33
34
|
- lib/thinking_sphinx/attribute.rb
|
35
|
+
- lib/thinking_sphinx/class_facet.rb
|
34
36
|
- lib/thinking_sphinx/collection.rb
|
35
37
|
- lib/thinking_sphinx/configuration.rb
|
36
38
|
- lib/thinking_sphinx/core/string.rb
|
@@ -41,18 +43,24 @@ files:
|
|
41
43
|
- lib/thinking_sphinx/deltas/delayed_delta/job.rb
|
42
44
|
- lib/thinking_sphinx/deltas/delayed_delta.rb
|
43
45
|
- lib/thinking_sphinx/deltas.rb
|
46
|
+
- lib/thinking_sphinx/deploy/capistrano.rb
|
44
47
|
- lib/thinking_sphinx/facet.rb
|
45
48
|
- lib/thinking_sphinx/facet_collection.rb
|
46
49
|
- lib/thinking_sphinx/field.rb
|
47
50
|
- lib/thinking_sphinx/index/builder.rb
|
48
51
|
- lib/thinking_sphinx/index/faux_column.rb
|
49
52
|
- lib/thinking_sphinx/index.rb
|
53
|
+
- lib/thinking_sphinx/property.rb
|
50
54
|
- lib/thinking_sphinx/rails_additions.rb
|
55
|
+
- lib/thinking_sphinx/search/facets.rb
|
51
56
|
- lib/thinking_sphinx/search.rb
|
57
|
+
- lib/thinking_sphinx/source/internal_properties.rb
|
58
|
+
- lib/thinking_sphinx/source/sql.rb
|
59
|
+
- lib/thinking_sphinx/source.rb
|
52
60
|
- lib/thinking_sphinx/tasks.rb
|
53
61
|
- lib/thinking_sphinx.rb
|
54
62
|
- LICENCE
|
55
|
-
- README
|
63
|
+
- README.textile
|
56
64
|
- tasks/distribution.rb
|
57
65
|
- tasks/testing.rb
|
58
66
|
- tasks/rails.rake
|
@@ -105,11 +113,15 @@ files:
|
|
105
113
|
- spec/unit/thinking_sphinx/collection_spec.rb
|
106
114
|
- spec/unit/thinking_sphinx/configuration_spec.rb
|
107
115
|
- spec/unit/thinking_sphinx/core/string_spec.rb
|
116
|
+
- spec/unit/thinking_sphinx/facet_collection_spec.rb
|
117
|
+
- spec/unit/thinking_sphinx/facet_spec.rb
|
108
118
|
- spec/unit/thinking_sphinx/field_spec.rb
|
109
119
|
- spec/unit/thinking_sphinx/index/builder_spec.rb
|
110
120
|
- spec/unit/thinking_sphinx/index/faux_column_spec.rb
|
111
121
|
- spec/unit/thinking_sphinx/index_spec.rb
|
122
|
+
- spec/unit/thinking_sphinx/rails_additions_spec.rb
|
112
123
|
- spec/unit/thinking_sphinx/search_spec.rb
|
124
|
+
- spec/unit/thinking_sphinx/source_spec.rb
|
113
125
|
- spec/unit/thinking_sphinx_spec.rb
|
114
126
|
has_rdoc: true
|
115
127
|
homepage: http://ts.freelancing-gods.com
|
@@ -149,9 +161,13 @@ test_files:
|
|
149
161
|
- spec/unit/thinking_sphinx/collection_spec.rb
|
150
162
|
- spec/unit/thinking_sphinx/configuration_spec.rb
|
151
163
|
- spec/unit/thinking_sphinx/core/string_spec.rb
|
164
|
+
- spec/unit/thinking_sphinx/facet_collection_spec.rb
|
165
|
+
- spec/unit/thinking_sphinx/facet_spec.rb
|
152
166
|
- spec/unit/thinking_sphinx/field_spec.rb
|
153
167
|
- spec/unit/thinking_sphinx/index/builder_spec.rb
|
154
168
|
- spec/unit/thinking_sphinx/index/faux_column_spec.rb
|
155
169
|
- spec/unit/thinking_sphinx/index_spec.rb
|
170
|
+
- spec/unit/thinking_sphinx/rails_additions_spec.rb
|
156
171
|
- spec/unit/thinking_sphinx/search_spec.rb
|
172
|
+
- spec/unit/thinking_sphinx/source_spec.rb
|
157
173
|
- spec/unit/thinking_sphinx_spec.rb
|