DrMark-thinking-sphinx 0.9.9 → 1.1.6

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.
Files changed (77) hide show
  1. data/README +64 -2
  2. data/lib/thinking_sphinx.rb +88 -11
  3. data/lib/thinking_sphinx/active_record.rb +136 -21
  4. data/lib/thinking_sphinx/active_record/delta.rb +43 -62
  5. data/lib/thinking_sphinx/active_record/has_many_association.rb +1 -1
  6. data/lib/thinking_sphinx/active_record/search.rb +7 -0
  7. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
  8. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  9. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +130 -0
  10. data/lib/thinking_sphinx/association.rb +17 -0
  11. data/lib/thinking_sphinx/attribute.rb +171 -97
  12. data/lib/thinking_sphinx/collection.rb +126 -2
  13. data/lib/thinking_sphinx/configuration.rb +120 -171
  14. data/lib/thinking_sphinx/core/string.rb +15 -0
  15. data/lib/thinking_sphinx/deltas.rb +27 -0
  16. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  17. data/lib/thinking_sphinx/deltas/default_delta.rb +67 -0
  18. data/lib/thinking_sphinx/deltas/delayed_delta.rb +25 -0
  19. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  20. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  21. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  22. data/lib/thinking_sphinx/facet.rb +58 -0
  23. data/lib/thinking_sphinx/facet_collection.rb +60 -0
  24. data/lib/thinking_sphinx/field.rb +18 -52
  25. data/lib/thinking_sphinx/index.rb +246 -199
  26. data/lib/thinking_sphinx/index/builder.rb +85 -16
  27. data/lib/thinking_sphinx/rails_additions.rb +85 -5
  28. data/lib/thinking_sphinx/search.rb +459 -190
  29. data/lib/thinking_sphinx/tasks.rb +128 -0
  30. data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +53 -124
  31. data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +2 -2
  32. data/spec/unit/thinking_sphinx/active_record_spec.rb +110 -30
  33. data/spec/unit/thinking_sphinx/attribute_spec.rb +16 -149
  34. data/spec/unit/thinking_sphinx/collection_spec.rb +14 -0
  35. data/spec/unit/thinking_sphinx/configuration_spec.rb +54 -412
  36. data/spec/unit/thinking_sphinx/core/string_spec.rb +9 -0
  37. data/spec/unit/thinking_sphinx/field_spec.rb +0 -79
  38. data/spec/unit/thinking_sphinx/index/builder_spec.rb +1 -29
  39. data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +1 -39
  40. data/spec/unit/thinking_sphinx/index_spec.rb +78 -226
  41. data/spec/unit/thinking_sphinx/search_spec.rb +29 -228
  42. data/spec/unit/thinking_sphinx_spec.rb +23 -19
  43. data/tasks/distribution.rb +48 -0
  44. data/tasks/rails.rake +1 -0
  45. data/tasks/testing.rb +86 -0
  46. data/vendor/after_commit/LICENSE +20 -0
  47. data/vendor/after_commit/README +16 -0
  48. data/vendor/after_commit/Rakefile +22 -0
  49. data/vendor/after_commit/init.rb +8 -0
  50. data/vendor/after_commit/lib/after_commit.rb +45 -0
  51. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  52. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  53. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  54. data/vendor/delayed_job/lib/delayed/job.rb +251 -0
  55. data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
  56. data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
  57. data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
  58. data/{lib → vendor/riddle/lib}/riddle.rb +9 -5
  59. data/{lib → vendor/riddle/lib}/riddle/client.rb +6 -26
  60. data/{lib → vendor/riddle/lib}/riddle/client/filter.rb +10 -1
  61. data/{lib → vendor/riddle/lib}/riddle/client/message.rb +0 -0
  62. data/{lib → vendor/riddle/lib}/riddle/client/response.rb +0 -0
  63. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  64. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  65. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  66. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  67. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  68. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  69. data/vendor/riddle/lib/riddle/configuration/section.rb +37 -0
  70. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  71. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  72. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  73. data/vendor/riddle/lib/riddle/controller.rb +44 -0
  74. metadata +63 -10
  75. data/lib/test.rb +0 -46
  76. data/tasks/thinking_sphinx_tasks.rake +0 -1
  77. data/tasks/thinking_sphinx_tasks.rb +0 -86
@@ -0,0 +1,9 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe String do
4
+ describe "to_crc32 instance method" do
5
+ it "should return an integer" do
6
+ 'to_crc32'.to_crc32.should be_a_kind_of(Integer)
7
+ end
8
+ end
9
+ end
@@ -15,73 +15,6 @@ describe ThinkingSphinx::Field do
15
15
  end
16
16
  end
17
17
 
18
- describe "to_select_sql method with MySQL" do
19
- before :each do
20
- @index = Person.indexes.first
21
- @index.link!
22
- end
23
-
24
- it "should concat with spaces if there are multiple columns" do
25
- @index.fields.first.to_select_sql.should match(/CONCAT_WS\(' ', /)
26
- end
27
-
28
- it "should concat with spaces if a column has more than one association" do
29
- @index.fields[1].to_select_sql.should match(/CONCAT_WS\(' ', /)
30
- end
31
-
32
- it "should group if any association for any column is a has_many or has_and_belongs_to_many" do
33
- @index.fields[2].to_select_sql.should match(/GROUP_CONCAT/)
34
- end
35
- end
36
-
37
- describe "to_select_sql method with PostgreSQL" do
38
- before :each do
39
- @index = Person.indexes.first
40
- Person.connection.class.stub_method(
41
- :name => "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
42
- )
43
- @index.link!
44
- end
45
-
46
- it "should concat with spaces if there are multiple columns" do
47
- @index.fields.first.to_select_sql.should match(/|| ' ' ||/)
48
- end
49
-
50
- it "should concat with spaces if a column has more than one association" do
51
- @index.fields[1].to_select_sql.should match(/|| ' ' ||/)
52
- end
53
-
54
- it "should group if any association for any column is a has_many or has_and_belongs_to_many" do
55
- @index.fields[2].to_select_sql.should match(/array_to_string\(array_accum\(/)
56
- end
57
- end
58
-
59
- describe "to_group_sql method" do
60
- before :each do
61
- @field = ThinkingSphinx::Field.new([Object.stub_instance(:__stack => [])])
62
- @field.stub_methods(:is_many? => false)
63
-
64
- ThinkingSphinx.stub_method(:use_group_by_shortcut? => false)
65
- end
66
-
67
- it "should return nil if is_many?" do
68
- @field.stub_method(:is_many? => true)
69
-
70
- @field.to_group_sql.should be_nil
71
- end
72
-
73
- it "should return nil if group_by shortcut is allowed" do
74
- ThinkingSphinx.stub_method(:use_group_by_shortcut? => true)
75
-
76
- @field.to_group_sql.should be_nil
77
- end
78
-
79
- it "should return an array if neither is_many? or shortcut allowed" do
80
- @field.stub_method(:column_with_prefix => 'hello')
81
- @field.to_group_sql.should be_a_kind_of(Array)
82
- end
83
- end
84
-
85
18
  describe "unique_name method" do
86
19
  before :each do
87
20
  @field = ThinkingSphinx::Field.new [
@@ -135,18 +68,6 @@ describe ThinkingSphinx::Field do
135
68
  end
136
69
  end
137
70
 
138
- describe "quote_column_name method" do
139
- it "should delegate the call to the model's connection" do
140
- @field = ThinkingSphinx::Field.new [
141
- ThinkingSphinx::Index::FauxColumn.new(:col_name)
142
- ]
143
- @field.model = Person
144
- Person.connection.stub_method(:quote_column_name => "quoted!")
145
-
146
- @field.send(:quote_column, "blah").should == "quoted!"
147
- end
148
- end
149
-
150
71
  describe "column_with_prefix method" do
151
72
  before :each do
152
73
  @field = ThinkingSphinx::Field.new [
@@ -1,33 +1,5 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::Index::Builder do
4
- before :each do
5
- @builder = Class.new(ThinkingSphinx::Index::Builder)
6
- @builder.setup
7
- end
8
-
9
- describe "setup method" do
10
- it "should set up the information arrays and properties hash" do
11
- @builder.fields.should == []
12
- @builder.attributes.should == []
13
- @builder.conditions.should == []
14
- @builder.properties.should == {}
15
- end
16
- end
17
-
18
- describe "indexes method" do
19
-
20
- end
21
-
22
- describe "has method" do
23
-
24
- end
25
-
26
- describe "where method" do
27
-
28
- end
29
-
30
- describe "set_property method" do
31
-
32
- end
4
+ #
33
5
  end
@@ -1,22 +1,6 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
- describe ThinkingSphinx::Index::FauxColumn do
4
- it "should use the last argument as the name, with preceeding ones going into the stack" do
5
- #
6
- end
7
-
8
- it "should access the name through __name" do
9
- #
10
- end
11
-
12
- it "should access the stack through __stack" do
13
- #
14
- end
15
-
16
- it "should return true from is_string? if the name is a string and the stack is empty" do
17
- #
18
- end
19
-
3
+ describe ThinkingSphinx::Index::FauxColumn do
20
4
  describe "coerce class method" do
21
5
  before :each do
22
6
  @column = ThinkingSphinx::Index::FauxColumn.stub_instance
@@ -43,26 +27,4 @@ describe ThinkingSphinx::Index::FauxColumn do
43
27
  ]
44
28
  end
45
29
  end
46
-
47
- describe "method_missing calls with no arguments" do
48
- it "should push any further method calls into name, and the old name goes into the stack" do
49
- #
50
- end
51
-
52
- it "should return itself" do
53
- #
54
- end
55
- end
56
-
57
- describe "method_missing calls with one argument" do
58
- it "should act as if calling method missing with method, then argument" do
59
- #
60
- end
61
- end
62
-
63
- describe "method_missing calls with more than one argument" do
64
- it "should return a collection of Faux Columns sharing the same stack, but with each argument as the name" do
65
- #
66
- end
67
- end
68
30
  end
@@ -1,213 +1,12 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::Index do
4
- describe "to_config method" do
5
- before :each do
6
- @index = ThinkingSphinx::Index.new(Person)
7
-
8
- @index.stub_methods(
9
- :attributes => [
10
- ThinkingSphinx::Attribute.stub_instance(:to_sphinx_clause => "attr a"),
11
- ThinkingSphinx::Attribute.stub_instance(:to_sphinx_clause => "attr b")
12
- ],
13
- :link! => true,
14
- :adapter => :mysql,
15
- :to_sql_query_pre => "sql_query_pre",
16
- :to_sql => "SQL",
17
- :to_sql_query_range => "sql_query_range",
18
- :to_sql_query_info => "sql_query_info",
19
- :delta? => false
20
- )
21
-
22
- @database = {
23
- :host => "localhost",
24
- :username => "username",
25
- :password => "blank",
26
- :database => "db"
27
- }
28
- end
29
-
30
- it "should call link!" do
31
- @index.to_config(Person, 0, @database, "utf-8", 0)
32
-
33
- @index.should have_received(:link!)
34
- end
35
-
36
- it "should raise an exception if the adapter isn't mysql or postgres" do
37
- @index.stub_method(:adapter => :sqlite)
38
-
39
- lambda { @index.to_config(Person, 0, @database, "utf-8", 0) }.should raise_error
40
- end
41
-
42
- it "should set the core source name to {model}_{index}_core" do
43
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
44
- /source person_0_core/
45
- )
46
- end
47
-
48
- it "should include the database config supplied" do
49
- conf = @index.to_config(Person, 0, @database, "utf-8", 0)
50
- conf.should match(/type\s+= mysql/)
51
- conf.should match(/sql_host\s+= localhost/)
52
- conf.should match(/sql_user\s+= username/)
53
- conf.should match(/sql_pass\s+= blank/)
54
- conf.should match(/sql_db\s+= db/)
55
- end
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
-
75
- it "should have a pre query 'SET NAMES utf8' if using mysql and utf8 charset" do
76
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
77
- /sql_query_pre\s+= SET NAMES utf8/
78
- )
79
-
80
- @index.stub_method(:delta? => true)
81
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
82
- /source person_0_delta.+sql_query_pre\s+= SET NAMES utf8/m
83
- )
84
-
85
- @index.stub_method(:delta? => false)
86
- @index.to_config(Person, 0, @database, "non-utf-8", 0).should_not match(
87
- /SET NAMES utf8/
88
- )
89
-
90
- @index.stub_method(:adapter => :postgres)
91
- @index.to_config(Person, 0, @database, "utf-8", 0).should_not match(
92
- /SET NAMES utf8/
93
- )
94
- end
95
-
96
- it "should use the pre query from the index" do
97
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
98
- /sql_query_pre\s+= sql_query_pre/
99
- )
100
- end
101
-
102
- it "should not set group_concat_max_len if not specified" do
103
- @index.to_config(Person, 0, @database, "utf-8", 0).should_not match(
104
- /group_concat_max_len/
105
- )
106
- end
107
-
108
- it "should set group_concat_max_len if specified" do
109
- @index.options.merge! :group_concat_max_len => 2056
110
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
111
- /sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/
112
- )
113
-
114
- @index.stub_method(:delta? => true)
115
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
116
- /source person_0_delta.+sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/m
117
- )
118
- end
119
-
120
- it "should use the main query from the index" do
121
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
122
- /sql_query\s+= SQL/
123
- )
124
- end
125
-
126
- it "should use the range query from the index" do
127
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
128
- /sql_query_range\s+= sql_query_range/
129
- )
130
- end
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
-
139
- it "should use the info query from the index" do
140
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
141
- /sql_query_info\s+= sql_query_info/
142
- )
143
- end
144
-
145
- it "should include the attribute sources" do
146
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
147
- /attr a\n\s+attr b/
148
- )
149
- end
150
-
151
- it "should add a delta index with name {model}_{index}_delta if requested" do
152
- @index.stub_method(:delta? => true)
153
-
154
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
155
- /source person_0_delta/
156
- )
157
- end
158
-
159
- it "should not add a delta index unless requested" do
160
- @index.to_config(Person, 0, @database, "utf-8", 0).should_not match(
161
- /source person_0_delta/
162
- )
163
- end
164
-
165
- it "should have the delta index inherit from the core index" do
166
- @index.stub_method(:delta? => true)
167
-
168
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
169
- /source person_0_delta : person_0_core/
170
- )
171
- end
172
-
173
- it "should redefine the main query for the delta index" do
174
- @index.stub_method(:delta? => true)
175
-
176
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
177
- /source person_0_delta.+sql_query\s+= SQL/m
178
- )
179
- end
180
-
181
- it "should redefine the range query for the delta index" do
182
- @index.stub_method(:delta? => true)
183
-
184
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
185
- /source person_0_delta.+sql_query_range\s+= sql_query_range/m
186
- )
187
- end
188
-
189
- it "should redefine the pre query for the delta index" do
190
- @index.stub_method(:delta? => true)
191
-
192
- @index.to_config(Person, 0, @database, "utf-8", 0).should match(
193
- /source person_0_delta.+sql_query_pre\s+=\s*\n/m
194
- )
195
- end
196
- end
197
-
198
- describe "to_sql_query_range method" do
199
- before :each do
4
+ describe "generated sql_query" do
5
+ it "should include explicit groupings if requested" do
200
6
  @index = ThinkingSphinx::Index.new(Person)
201
- end
202
-
203
- it "should add COALESCE around MIN and MAX calls if using PostgreSQL" do
204
- @index.stub_method(:adapter => :postgres)
205
7
 
206
- @index.to_sql_query_range.should match(/COALESCE\(MIN.+COALESCE\(MAX/)
207
- end
208
-
209
- it "shouldn't add COALESCE if using MySQL" do
210
- @index.to_sql_query_range.should_not match(/COALESCE/)
8
+ @index.groupings << "custom_sql"
9
+ @index.to_riddle_for_core(0, 0).sql_query.should match(/GROUP BY.+custom_sql/)
211
10
  end
212
11
  end
213
12
 
@@ -253,40 +52,93 @@ describe ThinkingSphinx::Index do
253
52
  end
254
53
  end
255
54
 
256
- describe "empty? method" do
257
- before :each do
258
- @index = ThinkingSphinx::Index.new(Person)
259
- config = ThinkingSphinx::Configuration.new
55
+ describe "multi-value attribute as ranged-query with has-many association" do
56
+ before :each do
57
+ @index = ThinkingSphinx::Index.new(Person) do
58
+ has tags(:id), :as => :tag_ids, :source => :ranged_query
59
+ end
60
+ @index.link!
260
61
 
261
- `mkdir -p #{config.searchd_file_path}`
262
- @file_path = "#{config.searchd_file_path}/#{@index.name}_core.spa"
62
+ @sql = @index.to_riddle_for_core(0, 0).sql_query
263
63
  end
264
64
 
265
- after :each do
266
- FileUtils.rm(@file_path, :force => true)
65
+ it "should not include attribute in select-clause sql_query" do
66
+ @sql.should_not match(/tag_ids/)
67
+ @sql.should_not match(/GROUP_CONCAT\(`tags`.`id`/)
267
68
  end
268
69
 
269
- it "should return true if the core index files are empty" do
270
- `touch #{@file_path}`
271
- @index.should be_empty
70
+ it "should not join with association table" do
71
+ @sql.should_not match(/LEFT OUTER JOIN `tags`/)
72
+ end
73
+
74
+ it "should include sql_attr_multi as ranged-query" do
75
+ attribute = @index.send(:attributes).first
76
+ attribute.send(:type_to_config).to_s.should == "sql_attr_multi"
77
+
78
+ declaration, query, range_query = attribute.send(:config_value).split('; ')
79
+ declaration.should == "uint tag_ids from ranged-query"
80
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
81
+ range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
82
+ end
83
+ end
84
+
85
+ describe "multi-value attribute as ranged-query with has-many-through association" do
86
+ before :each do
87
+ @index = ThinkingSphinx::Index.new(Person) do
88
+ has football_teams(:id), :as => :football_teams_ids, :source => :ranged_query
89
+ end
90
+ @index.link!
91
+
92
+ @sql = @index.to_riddle_for_core(0, 0).sql_query
272
93
  end
273
94
 
274
- it "should return true if the core index files don't exist" do
275
- @index.should be_empty
95
+ it "should not include attribute in select-clause sql_query" do
96
+ @sql.should_not match(/football_teams_ids/)
97
+ @sql.should_not match(/GROUP_CONCAT\(`tags`.`football_team_id`/)
276
98
  end
277
99
 
278
- it "should return false if the core index files aren't empty" do
279
- `echo 'a' > #{@file_path}`
280
- @index.should_not be_empty
100
+ it "should not join with association table" do
101
+ @sql.should_not match(/LEFT OUTER JOIN `tags`/)
281
102
  end
282
103
 
283
- it "should check the delta files if specified" do
284
- @index.should be_empty(:delta)
104
+ it "should include sql_attr_multi as ranged-query" do
105
+ attribute = @index.send(:attributes).first
106
+ attribute.send(:type_to_config).to_s.should == "sql_attr_multi"
285
107
 
286
- `echo 'a' > #{@file_path.gsub(/_core.spa$/, '_delta.spa')}`
287
- @index.should_not be_empty(:delta)
108
+ declaration, query, range_query = attribute.send(:config_value).split('; ')
109
+ declaration.should == "uint football_teams_ids from ranged-query"
110
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`football_team_id` AS `football_teams_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
111
+ range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
112
+ end
113
+ end
114
+
115
+ describe "multi-value attribute as ranged-query with has-many-through association and foreign_key" do
116
+ before :each do
117
+ @index = ThinkingSphinx::Index.new(Person) do
118
+ has friends(:id), :as => :friend_ids, :source => :ranged_query
119
+ end
120
+ @index.link!
121
+
122
+ @sql = @index.to_riddle_for_core(0, 0).sql_query
123
+ end
124
+
125
+ it "should not include attribute in select-clause sql_query" do
126
+ @sql.should_not match(/friend_ids/)
127
+ @sql.should_not match(/GROUP_CONCAT\(`friendships`.`friend_id`/)
128
+ end
129
+
130
+ it "should not join with association table" do
131
+ @sql.should_not match(/LEFT OUTER JOIN `friendships`/)
132
+ end
133
+
134
+ it "should include sql_attr_multi as ranged-query" do
135
+ attribute = @index.send(:attributes).first
136
+ attribute.send(:type_to_config).to_s.should == "sql_attr_multi"
288
137
 
289
- `rm #{@file_path}` if File.exists?(@file_path.gsub(/_core.spa$/, '_delta.spa'))
138
+ declaration, query, range_query = attribute.send(:config_value).split('; ')
139
+ declaration.should == "uint friend_ids from ranged-query"
140
+ query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
141
+ range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
290
142
  end
291
143
  end
292
144
  end