DrMark-thinking-sphinx 0.9.8 → 0.9.9
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 +9 -1
- data/lib/thinking_sphinx/active_record/delta.rb +11 -1
- data/lib/thinking_sphinx/active_record/search.rb +8 -1
- data/lib/thinking_sphinx/active_record.rb +6 -0
- data/lib/thinking_sphinx/association.rb +4 -0
- data/lib/thinking_sphinx/attribute.rb +4 -2
- data/lib/thinking_sphinx/collection.rb +23 -0
- data/lib/thinking_sphinx/configuration.rb +41 -30
- data/lib/thinking_sphinx/field.rb +11 -3
- data/lib/thinking_sphinx/index/builder.rb +2 -19
- data/lib/thinking_sphinx/index/faux_column.rb +13 -0
- data/lib/thinking_sphinx/index.rb +65 -28
- data/lib/thinking_sphinx/search.rb +38 -29
- data/lib/thinking_sphinx.rb +21 -2
- data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +27 -6
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +26 -0
- data/spec/unit/thinking_sphinx/active_record_spec.rb +14 -1
- data/spec/unit/thinking_sphinx/attribute_spec.rb +6 -2
- data/spec/unit/thinking_sphinx/configuration_spec.rb +45 -27
- data/spec/unit/thinking_sphinx/field_spec.rb +11 -2
- data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +27 -0
- data/spec/unit/thinking_sphinx/index_spec.rb +48 -23
- data/spec/unit/thinking_sphinx/search_spec.rb +80 -10
- data/spec/unit/thinking_sphinx_spec.rb +21 -0
- data/tasks/thinking_sphinx_tasks.rb +1 -1
- metadata +16 -2
@@ -28,7 +28,7 @@ describe ThinkingSphinx::Index do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should call link!" do
|
31
|
-
@index.to_config(0, @database, "utf-8")
|
31
|
+
@index.to_config(Person, 0, @database, "utf-8", 0)
|
32
32
|
|
33
33
|
@index.should have_received(:link!)
|
34
34
|
end
|
@@ -36,17 +36,17 @@ describe ThinkingSphinx::Index do
|
|
36
36
|
it "should raise an exception if the adapter isn't mysql or postgres" do
|
37
37
|
@index.stub_method(:adapter => :sqlite)
|
38
38
|
|
39
|
-
lambda { @index.to_config(0, @database, "utf-8") }.should raise_error
|
39
|
+
lambda { @index.to_config(Person, 0, @database, "utf-8", 0) }.should raise_error
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should set the core source name to {model}_{index}_core" do
|
43
|
-
@index.to_config(0, @database, "utf-8").should match(
|
43
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
44
44
|
/source person_0_core/
|
45
45
|
)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should include the database config supplied" do
|
49
|
-
conf = @index.to_config(0, @database, "utf-8")
|
49
|
+
conf = @index.to_config(Person, 0, @database, "utf-8", 0)
|
50
50
|
conf.should match(/type\s+= mysql/)
|
51
51
|
conf.should match(/sql_host\s+= localhost/)
|
52
52
|
conf.should match(/sql_user\s+= username/)
|
@@ -54,71 +54,96 @@ describe ThinkingSphinx::Index do
|
|
54
54
|
conf.should match(/sql_db\s+= db/)
|
55
55
|
end
|
56
56
|
|
57
|
+
it "should use 'user' if 'username' doesn't exist in database configuration" do
|
58
|
+
conf = @index.to_config(Person, 0,
|
59
|
+
@database.except(:username).merge(:user => "username"),
|
60
|
+
"utf-8", 0
|
61
|
+
)
|
62
|
+
conf.should match(/sql_user\s+= username/)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should include the database socket if set" do
|
66
|
+
conf = @index.to_config(Person, 0, @database.merge(:socket => "dbsocket"), "utf-8", 0)
|
67
|
+
conf.should match(/sql_sock\s+= dbsocket/)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not include the database socket if not set" do
|
71
|
+
conf = @index.to_config(Person, 0, @database, "utf-8", 0)
|
72
|
+
conf.should_not match(/sql_sock/)
|
73
|
+
end
|
74
|
+
|
57
75
|
it "should have a pre query 'SET NAMES utf8' if using mysql and utf8 charset" do
|
58
|
-
@index.to_config(0, @database, "utf-8").should match(
|
76
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
59
77
|
/sql_query_pre\s+= SET NAMES utf8/
|
60
78
|
)
|
61
79
|
|
62
80
|
@index.stub_method(:delta? => true)
|
63
|
-
@index.to_config(0, @database, "utf-8").should match(
|
81
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
64
82
|
/source person_0_delta.+sql_query_pre\s+= SET NAMES utf8/m
|
65
83
|
)
|
66
84
|
|
67
85
|
@index.stub_method(:delta? => false)
|
68
|
-
@index.to_config(0, @database, "non-utf-8").should_not match(
|
86
|
+
@index.to_config(Person, 0, @database, "non-utf-8", 0).should_not match(
|
69
87
|
/SET NAMES utf8/
|
70
88
|
)
|
71
89
|
|
72
90
|
@index.stub_method(:adapter => :postgres)
|
73
|
-
@index.to_config(0, @database, "utf-8").should_not match(
|
91
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should_not match(
|
74
92
|
/SET NAMES utf8/
|
75
93
|
)
|
76
94
|
end
|
77
95
|
|
78
96
|
it "should use the pre query from the index" do
|
79
|
-
@index.to_config(0, @database, "utf-8").should match(
|
97
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
80
98
|
/sql_query_pre\s+= sql_query_pre/
|
81
99
|
)
|
82
100
|
end
|
83
101
|
|
84
102
|
it "should not set group_concat_max_len if not specified" do
|
85
|
-
@index.to_config(0, @database, "utf-8").should_not match(
|
103
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should_not match(
|
86
104
|
/group_concat_max_len/
|
87
105
|
)
|
88
106
|
end
|
89
107
|
|
90
108
|
it "should set group_concat_max_len if specified" do
|
91
109
|
@index.options.merge! :group_concat_max_len => 2056
|
92
|
-
@index.to_config(0, @database, "utf-8").should match(
|
110
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
93
111
|
/sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/
|
94
112
|
)
|
95
113
|
|
96
114
|
@index.stub_method(:delta? => true)
|
97
|
-
@index.to_config(0, @database, "utf-8").should match(
|
115
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
98
116
|
/source person_0_delta.+sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/m
|
99
117
|
)
|
100
118
|
end
|
101
119
|
|
102
120
|
it "should use the main query from the index" do
|
103
|
-
@index.to_config(0, @database, "utf-8").should match(
|
121
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
104
122
|
/sql_query\s+= SQL/
|
105
123
|
)
|
106
124
|
end
|
107
125
|
|
108
126
|
it "should use the range query from the index" do
|
109
|
-
@index.to_config(0, @database, "utf-8").should match(
|
127
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
110
128
|
/sql_query_range\s+= sql_query_range/
|
111
129
|
)
|
112
130
|
end
|
113
131
|
|
132
|
+
it "should pass the offset to the range query" do
|
133
|
+
@index.unstub_method(:to_sql_query_range)
|
134
|
+
@index.to_config(Person, 0, @database, "utf-8", 7).should include(
|
135
|
+
"sql_query_range = SELECT MIN(`id` * 3 + 7), MAX(`id` * 3 + 7)"
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
114
139
|
it "should use the info query from the index" do
|
115
|
-
@index.to_config(0, @database, "utf-8").should match(
|
140
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
116
141
|
/sql_query_info\s+= sql_query_info/
|
117
142
|
)
|
118
143
|
end
|
119
144
|
|
120
145
|
it "should include the attribute sources" do
|
121
|
-
@index.to_config(0, @database, "utf-8").should match(
|
146
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
122
147
|
/attr a\n\s+attr b/
|
123
148
|
)
|
124
149
|
end
|
@@ -126,13 +151,13 @@ describe ThinkingSphinx::Index do
|
|
126
151
|
it "should add a delta index with name {model}_{index}_delta if requested" do
|
127
152
|
@index.stub_method(:delta? => true)
|
128
153
|
|
129
|
-
@index.to_config(0, @database, "utf-8").should match(
|
154
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
130
155
|
/source person_0_delta/
|
131
156
|
)
|
132
157
|
end
|
133
158
|
|
134
159
|
it "should not add a delta index unless requested" do
|
135
|
-
@index.to_config(0, @database, "utf-8").should_not match(
|
160
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should_not match(
|
136
161
|
/source person_0_delta/
|
137
162
|
)
|
138
163
|
end
|
@@ -140,7 +165,7 @@ describe ThinkingSphinx::Index do
|
|
140
165
|
it "should have the delta index inherit from the core index" do
|
141
166
|
@index.stub_method(:delta? => true)
|
142
167
|
|
143
|
-
@index.to_config(0, @database, "utf-8").should match(
|
168
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
144
169
|
/source person_0_delta : person_0_core/
|
145
170
|
)
|
146
171
|
end
|
@@ -148,7 +173,7 @@ describe ThinkingSphinx::Index do
|
|
148
173
|
it "should redefine the main query for the delta index" do
|
149
174
|
@index.stub_method(:delta? => true)
|
150
175
|
|
151
|
-
@index.to_config(0, @database, "utf-8").should match(
|
176
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
152
177
|
/source person_0_delta.+sql_query\s+= SQL/m
|
153
178
|
)
|
154
179
|
end
|
@@ -156,7 +181,7 @@ describe ThinkingSphinx::Index do
|
|
156
181
|
it "should redefine the range query for the delta index" do
|
157
182
|
@index.stub_method(:delta? => true)
|
158
183
|
|
159
|
-
@index.to_config(0, @database, "utf-8").should match(
|
184
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
160
185
|
/source person_0_delta.+sql_query_range\s+= sql_query_range/m
|
161
186
|
)
|
162
187
|
end
|
@@ -164,7 +189,7 @@ describe ThinkingSphinx::Index do
|
|
164
189
|
it "should redefine the pre query for the delta index" do
|
165
190
|
@index.stub_method(:delta? => true)
|
166
191
|
|
167
|
-
@index.to_config(0, @database, "utf-8").should match(
|
192
|
+
@index.to_config(Person, 0, @database, "utf-8", 0).should match(
|
168
193
|
/source person_0_delta.+sql_query_pre\s+=\s*\n/m
|
169
194
|
)
|
170
195
|
end
|
@@ -238,7 +263,7 @@ describe ThinkingSphinx::Index do
|
|
238
263
|
end
|
239
264
|
|
240
265
|
after :each do
|
241
|
-
|
266
|
+
FileUtils.rm(@file_path, :force => true)
|
242
267
|
end
|
243
268
|
|
244
269
|
it "should return true if the core index files are empty" do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
|
+
require 'will_paginate/collection'
|
2
3
|
|
3
4
|
describe ThinkingSphinx::Search do
|
4
5
|
describe "search method" do
|
@@ -61,21 +62,29 @@ describe ThinkingSphinx::Search do
|
|
61
62
|
it "should honour the :include option" do
|
62
63
|
ThinkingSphinx::Search.send(
|
63
64
|
:instance_from_result,
|
64
|
-
{
|
65
|
+
{
|
66
|
+
:doc => 1, :attributes => {
|
67
|
+
"sphinx_internal_id" => 2, "class_crc" => 123
|
68
|
+
}
|
69
|
+
},
|
65
70
|
{:include => :assoc}
|
66
71
|
)
|
67
72
|
|
68
|
-
Person.should have_received(:find).with(
|
73
|
+
Person.should have_received(:find).with(2, :include => :assoc, :select => nil)
|
69
74
|
end
|
70
75
|
|
71
76
|
it "should honour the :select option" do
|
72
77
|
ThinkingSphinx::Search.send(
|
73
78
|
:instance_from_result,
|
74
|
-
{
|
79
|
+
{
|
80
|
+
:doc => 1, :attributes => {
|
81
|
+
"sphinx_internal_id" => 2, "class_crc" => 123
|
82
|
+
}
|
83
|
+
},
|
75
84
|
{:select => :columns}
|
76
85
|
)
|
77
86
|
|
78
|
-
Person.should have_received(:find).with(
|
87
|
+
Person.should have_received(:find).with(2, :include => nil, :select => :columns)
|
79
88
|
end
|
80
89
|
|
81
90
|
end
|
@@ -91,9 +100,9 @@ describe ThinkingSphinx::Search do
|
|
91
100
|
@person_c.stub_method(:attributes => [])
|
92
101
|
|
93
102
|
@results = [
|
94
|
-
{:
|
95
|
-
{:
|
96
|
-
{:
|
103
|
+
{:attributes => {"sphinx_internal_id" => @person_a.id}},
|
104
|
+
{:attributes => {"sphinx_internal_id" => @person_b.id}},
|
105
|
+
{:attributes => {"sphinx_internal_id" => @person_c.id}}
|
97
106
|
]
|
98
107
|
|
99
108
|
Person.stub_method(
|
@@ -113,13 +122,13 @@ describe ThinkingSphinx::Search do
|
|
113
122
|
)
|
114
123
|
|
115
124
|
ThinkingSphinx::Search.should have_received(:instance_from_result).with(
|
116
|
-
{:
|
125
|
+
{:attributes => {"sphinx_internal_id" => @person_a.id}}, {}
|
117
126
|
)
|
118
127
|
ThinkingSphinx::Search.should have_received(:instance_from_result).with(
|
119
|
-
{:
|
128
|
+
{:attributes => {"sphinx_internal_id" => @person_b.id}}, {}
|
120
129
|
)
|
121
130
|
ThinkingSphinx::Search.should have_received(:instance_from_result).with(
|
122
|
-
{:
|
131
|
+
{:attributes => {"sphinx_internal_id" => @person_c.id}}, {}
|
123
132
|
)
|
124
133
|
end
|
125
134
|
|
@@ -185,4 +194,65 @@ describe ThinkingSphinx::Search do
|
|
185
194
|
|
186
195
|
it "should have a test for the append_distances function"
|
187
196
|
end
|
197
|
+
|
198
|
+
describe "count method" do
|
199
|
+
before :each do
|
200
|
+
@client = Riddle::Client.stub_instance(
|
201
|
+
:filters => [],
|
202
|
+
:filters= => true,
|
203
|
+
:id_range= => true,
|
204
|
+
:sort_mode => :asc,
|
205
|
+
:limit => 5,
|
206
|
+
:offset= => 0,
|
207
|
+
:sort_mode= => true,
|
208
|
+
:query => {
|
209
|
+
:matches => [],
|
210
|
+
:total => 50
|
211
|
+
}
|
212
|
+
)
|
213
|
+
|
214
|
+
ThinkingSphinx::Search.stub_methods(
|
215
|
+
:client_from_options => @client,
|
216
|
+
:search_conditions => ["", []]
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should return query total" do
|
221
|
+
ThinkingSphinx::Search.count(42, "an_index").should == 50
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "search result" do
|
226
|
+
before :each do
|
227
|
+
@results = ThinkingSphinx::Search.search "nothing will match this"
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should respond to previous_page" do
|
231
|
+
@results.should respond_to(:previous_page)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should respond to next_page" do
|
235
|
+
@results.should respond_to(:next_page)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should respond to current_page" do
|
239
|
+
@results.should respond_to(:current_page)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should respond to total_pages" do
|
243
|
+
@results.should respond_to(:total_pages)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should respond to total_entries" do
|
247
|
+
@results.should respond_to(:total_entries)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should respond to offset" do
|
251
|
+
@results.should respond_to(:offset)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should be a subclass of Array" do
|
255
|
+
@results.should be_kind_of(Array)
|
256
|
+
end
|
257
|
+
end
|
188
258
|
end
|
@@ -40,6 +40,23 @@ describe ThinkingSphinx do
|
|
40
40
|
ThinkingSphinx.deltas_enabled?.should be_true
|
41
41
|
end
|
42
42
|
|
43
|
+
it "should update indexes by default" do
|
44
|
+
ThinkingSphinx.updates_enabled = nil
|
45
|
+
ThinkingSphinx.updates_enabled?.should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should disable index updating" do
|
49
|
+
ThinkingSphinx.updates_enabled = false
|
50
|
+
ThinkingSphinx.updates_enabled?.should be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should enable index updating" do
|
54
|
+
ThinkingSphinx.updates_enabled = false
|
55
|
+
ThinkingSphinx.updates_enabled?.should be_false
|
56
|
+
ThinkingSphinx.updates_enabled = true
|
57
|
+
ThinkingSphinx.updates_enabled?.should be_true
|
58
|
+
end
|
59
|
+
|
43
60
|
describe "use_group_by_shortcut? method" do
|
44
61
|
after :each do
|
45
62
|
::ActiveRecord::Base.connection.unstub_method(:select_all)
|
@@ -82,6 +99,10 @@ describe ThinkingSphinx do
|
|
82
99
|
|
83
100
|
describe "if not using MySQL" do
|
84
101
|
before :each do
|
102
|
+
unless ::ActiveRecord::ConnectionAdapters.const_defined?(:PostgreSQLAdapter)
|
103
|
+
pending "No PostgreSQL"
|
104
|
+
return
|
105
|
+
end
|
85
106
|
@connection = ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.stub_instance(
|
86
107
|
:select_all => true
|
87
108
|
)
|
@@ -3,7 +3,7 @@ require 'fileutils'
|
|
3
3
|
namespace :thinking_sphinx do
|
4
4
|
task :app_env do
|
5
5
|
Rake::Task[:environment].invoke if defined?(RAILS_ROOT)
|
6
|
-
Rake::Task[:
|
6
|
+
Rake::Task[:merb_init].invoke if defined?(Merb)
|
7
7
|
end
|
8
8
|
|
9
9
|
desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
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: 0.9.
|
4
|
+
version: 0.9.9
|
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: 2008-
|
12
|
+
date: 2008-08-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/thinking_sphinx/active_record.rb
|
35
35
|
- lib/thinking_sphinx/association.rb
|
36
36
|
- lib/thinking_sphinx/attribute.rb
|
37
|
+
- lib/thinking_sphinx/collection.rb
|
37
38
|
- lib/thinking_sphinx/configuration.rb
|
38
39
|
- lib/thinking_sphinx/field.rb
|
39
40
|
- lib/thinking_sphinx/index/builder.rb
|
@@ -46,6 +47,19 @@ files:
|
|
46
47
|
- README
|
47
48
|
- tasks/thinking_sphinx_tasks.rb
|
48
49
|
- tasks/thinking_sphinx_tasks.rake
|
50
|
+
- spec/unit/thinking_sphinx/active_record/delta_spec.rb
|
51
|
+
- spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
|
52
|
+
- spec/unit/thinking_sphinx/active_record/search_spec.rb
|
53
|
+
- spec/unit/thinking_sphinx/active_record_spec.rb
|
54
|
+
- spec/unit/thinking_sphinx/association_spec.rb
|
55
|
+
- spec/unit/thinking_sphinx/attribute_spec.rb
|
56
|
+
- spec/unit/thinking_sphinx/configuration_spec.rb
|
57
|
+
- spec/unit/thinking_sphinx/field_spec.rb
|
58
|
+
- spec/unit/thinking_sphinx/index/builder_spec.rb
|
59
|
+
- spec/unit/thinking_sphinx/index/faux_column_spec.rb
|
60
|
+
- spec/unit/thinking_sphinx/index_spec.rb
|
61
|
+
- spec/unit/thinking_sphinx/search_spec.rb
|
62
|
+
- spec/unit/thinking_sphinx_spec.rb
|
49
63
|
has_rdoc: true
|
50
64
|
homepage: http://ts.freelancing-gods.com
|
51
65
|
post_install_message:
|