pixeltrix-thinking-sphinx 1.1.5 → 1.2.1
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.textile +147 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
- data/lib/thinking_sphinx/active_record/delta.rb +14 -1
- data/lib/thinking_sphinx/active_record/scopes.rb +37 -0
- data/lib/thinking_sphinx/active_record.rb +46 -12
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +9 -1
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +3 -2
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +12 -5
- data/lib/thinking_sphinx/association.rb +20 -0
- data/lib/thinking_sphinx/attribute.rb +187 -116
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +46 -14
- data/lib/thinking_sphinx/core/string.rb +3 -10
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +3 -3
- data/lib/thinking_sphinx/deltas/default_delta.rb +9 -6
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +1 -1
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +4 -2
- data/lib/thinking_sphinx/deltas.rb +14 -6
- data/lib/thinking_sphinx/deploy/capistrano.rb +98 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet.rb +68 -18
- data/lib/thinking_sphinx/facet_search.rb +134 -0
- data/lib/thinking_sphinx/field.rb +7 -97
- data/lib/thinking_sphinx/index/builder.rb +255 -201
- data/lib/thinking_sphinx/index.rb +28 -343
- data/lib/thinking_sphinx/property.rb +160 -0
- data/lib/thinking_sphinx/rails_additions.rb +7 -4
- data/lib/thinking_sphinx/search.rb +593 -587
- data/lib/thinking_sphinx/search_methods.rb +421 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +128 -0
- data/lib/thinking_sphinx/source.rb +150 -0
- data/lib/thinking_sphinx/tasks.rb +45 -11
- data/lib/thinking_sphinx.rb +88 -14
- data/rails/init.rb +14 -0
- data/spec/{unit → lib}/thinking_sphinx/active_record/delta_spec.rb +7 -7
- data/spec/{unit → lib}/thinking_sphinx/active_record/has_many_association_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +92 -0
- data/spec/{unit → lib}/thinking_sphinx/active_record_spec.rb +115 -42
- data/spec/{unit → lib}/thinking_sphinx/association_spec.rb +4 -5
- data/spec/lib/thinking_sphinx/attribute_spec.rb +465 -0
- data/spec/{unit → lib}/thinking_sphinx/configuration_spec.rb +118 -7
- data/spec/{unit → lib}/thinking_sphinx/core/string_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/excerpter_spec.rb +49 -0
- data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/lib/thinking_sphinx/facet_spec.rb +302 -0
- data/spec/{unit → lib}/thinking_sphinx/field_spec.rb +26 -17
- data/spec/lib/thinking_sphinx/index/builder_spec.rb +355 -0
- data/spec/{unit → lib}/thinking_sphinx/index/faux_column_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/index_spec.rb +3 -12
- data/spec/lib/thinking_sphinx/rails_additions_spec.rb +191 -0
- data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/lib/thinking_sphinx/search_spec.rb +887 -0
- data/spec/lib/thinking_sphinx/source_spec.rb +217 -0
- data/spec/{unit → lib}/thinking_sphinx_spec.rb +30 -8
- data/tasks/distribution.rb +20 -1
- data/tasks/testing.rb +7 -15
- data/vendor/after_commit/init.rb +3 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +27 -4
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +1 -1
- data/vendor/after_commit/lib/after_commit.rb +4 -1
- data/vendor/riddle/lib/riddle/client/message.rb +4 -3
- data/vendor/riddle/lib/riddle/client.rb +3 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +8 -2
- data/vendor/riddle/lib/riddle/controller.rb +1 -1
- data/vendor/riddle/lib/riddle.rb +1 -1
- metadata +75 -39
- data/README +0 -107
- data/lib/thinking_sphinx/active_record/search.rb +0 -57
- data/lib/thinking_sphinx/collection.rb +0 -142
- data/lib/thinking_sphinx/facet_collection.rb +0 -44
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +0 -107
- data/spec/unit/thinking_sphinx/attribute_spec.rb +0 -212
- data/spec/unit/thinking_sphinx/collection_spec.rb +0 -14
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +0 -5
- data/spec/unit/thinking_sphinx/search_spec.rb +0 -59
@@ -1,212 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
describe ThinkingSphinx::Attribute do
|
4
|
-
describe '#initialize' do
|
5
|
-
it 'raises if no columns are provided so that configuration errors are easier to track down' do
|
6
|
-
lambda {
|
7
|
-
ThinkingSphinx::Attribute.new([])
|
8
|
-
}.should raise_error(RuntimeError)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'raises if an element of the columns param is an integer - as happens when you use id instead of :id - so that configuration errors are easier to track down' do
|
12
|
-
lambda {
|
13
|
-
ThinkingSphinx::Attribute.new([1234])
|
14
|
-
}.should raise_error(RuntimeError)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "unique_name method" do
|
19
|
-
before :each do
|
20
|
-
@attribute = ThinkingSphinx::Attribute.new [
|
21
|
-
Object.stub_instance(:__stack => [], :__name => "col_name")
|
22
|
-
]
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should use the alias if there is one" do
|
26
|
-
@attribute.alias = "alias"
|
27
|
-
@attribute.unique_name.should == "alias"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should use the alias if there's multiple columns" do
|
31
|
-
@attribute.columns << Object.stub_instance(:__stack => [], :__name => "col_name")
|
32
|
-
@attribute.unique_name.should be_nil
|
33
|
-
|
34
|
-
@attribute.alias = "alias"
|
35
|
-
@attribute.unique_name.should == "alias"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should use the column name if there's no alias and just one column" do
|
39
|
-
@attribute.unique_name.should == "col_name"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "column_with_prefix method" do
|
44
|
-
before :each do
|
45
|
-
@attribute = ThinkingSphinx::Attribute.new [
|
46
|
-
ThinkingSphinx::Index::FauxColumn.new(:col_name)
|
47
|
-
]
|
48
|
-
@attribute.columns.each { |col| @attribute.associations[col] = [] }
|
49
|
-
@attribute.model = Person
|
50
|
-
|
51
|
-
@first_join = Object.stub_instance(:aliased_table_name => "tabular")
|
52
|
-
@second_join = Object.stub_instance(:aliased_table_name => "data")
|
53
|
-
|
54
|
-
@first_assoc = ThinkingSphinx::Association.stub_instance(
|
55
|
-
:join => @first_join, :has_column? => true
|
56
|
-
)
|
57
|
-
@second_assoc = ThinkingSphinx::Association.stub_instance(
|
58
|
-
:join => @second_join, :has_column? => true
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return the column name if the column is a string" do
|
63
|
-
@attribute.columns = [ThinkingSphinx::Index::FauxColumn.new("string")]
|
64
|
-
@attribute.send(:column_with_prefix, @attribute.columns.first).should == "string"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return the column with model's table prefix if there's no associations for the column" do
|
68
|
-
@attribute.send(:column_with_prefix, @attribute.columns.first).should == "`people`.`col_name`"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should return the column with its join table prefix if an association exists" do
|
72
|
-
column = @attribute.columns.first
|
73
|
-
@attribute.associations[column] = [@first_assoc]
|
74
|
-
@attribute.send(:column_with_prefix, column).should == "`tabular`.`col_name`"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should return multiple columns concatenated if more than one association exists" do
|
78
|
-
column = @attribute.columns.first
|
79
|
-
@attribute.associations[column] = [@first_assoc, @second_assoc]
|
80
|
-
@attribute.send(:column_with_prefix, column).should == "`tabular`.`col_name`, `data`.`col_name`"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "is_many? method" do
|
85
|
-
before :each do
|
86
|
-
@assoc_a = Object.stub_instance(:is_many? => true)
|
87
|
-
@assoc_b = Object.stub_instance(:is_many? => true)
|
88
|
-
@assoc_c = Object.stub_instance(:is_many? => true)
|
89
|
-
|
90
|
-
@attribute = ThinkingSphinx::Attribute.new(
|
91
|
-
[ThinkingSphinx::Index::FauxColumn.new(:col_name)]
|
92
|
-
)
|
93
|
-
@attribute.associations = {
|
94
|
-
:a => @assoc_a, :b => @assoc_b, :c => @assoc_c
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should return true if all associations return true to is_many?" do
|
99
|
-
@attribute.send(:is_many?).should be_true
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return true if one association returns true to is_many?" do
|
103
|
-
@assoc_b.stub_method(:is_many? => false)
|
104
|
-
@assoc_c.stub_method(:is_many? => false)
|
105
|
-
|
106
|
-
@attribute.send(:is_many?).should be_true
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should return false if all associations return false to is_many?" do
|
110
|
-
@assoc_a.stub_method(:is_many? => false)
|
111
|
-
@assoc_b.stub_method(:is_many? => false)
|
112
|
-
@assoc_c.stub_method(:is_many? => false)
|
113
|
-
|
114
|
-
@attribute.send(:is_many?).should be_false
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "is_string? method" do
|
119
|
-
before :each do
|
120
|
-
@col_a = ThinkingSphinx::Index::FauxColumn.new("a")
|
121
|
-
@col_b = ThinkingSphinx::Index::FauxColumn.new("b")
|
122
|
-
@col_c = ThinkingSphinx::Index::FauxColumn.new("c")
|
123
|
-
|
124
|
-
@attribute = ThinkingSphinx::Attribute.new(
|
125
|
-
[@col_a, @col_b, @col_c]
|
126
|
-
)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should return true if all columns return true to is_string?" do
|
130
|
-
@attribute.send(:is_string?).should be_true
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should return false if one column returns true to is_string?" do
|
134
|
-
@col_a.send(:instance_variable_set, :@name, :a)
|
135
|
-
@attribute.send(:is_string?).should be_false
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should return false if all columns return false to is_string?" do
|
139
|
-
@col_a.send(:instance_variable_set, :@name, :a)
|
140
|
-
@col_b.send(:instance_variable_set, :@name, :b)
|
141
|
-
@col_c.send(:instance_variable_set, :@name, :c)
|
142
|
-
@attribute.send(:is_string?).should be_false
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe "type method" do
|
147
|
-
before :each do
|
148
|
-
@column = ThinkingSphinx::Index::FauxColumn.new(:col_name)
|
149
|
-
@attribute = ThinkingSphinx::Attribute.new([@column])
|
150
|
-
@attribute.model = Person
|
151
|
-
@attribute.stub_method(:is_many? => false)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should return :multi if is_many? is true" do
|
155
|
-
@attribute.stub_method(:is_many? => true)
|
156
|
-
@attribute.send(:type).should == :multi
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should return :string if there's more than one association" do
|
160
|
-
@attribute.associations = {:a => [:assoc], :b => [:assoc]}
|
161
|
-
@attribute.send(:type).should == :string
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should return the column type from the database if not :multi or more than one association" do
|
165
|
-
@column.send(:instance_variable_set, :@name, "birthday")
|
166
|
-
@attribute.send(:type).should == :datetime
|
167
|
-
|
168
|
-
@attribute.send(:instance_variable_set, :@type, nil)
|
169
|
-
@column.send(:instance_variable_set, :@name, "first_name")
|
170
|
-
@attribute.send(:type).should == :string
|
171
|
-
|
172
|
-
@attribute.send(:instance_variable_set, :@type, nil)
|
173
|
-
@column.send(:instance_variable_set, :@name, "id")
|
174
|
-
@attribute.send(:type).should == :integer
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe "all_ints? method" do
|
179
|
-
it "should return true if all columns are integers" do
|
180
|
-
attribute = ThinkingSphinx::Attribute.new(
|
181
|
-
[ ThinkingSphinx::Index::FauxColumn.new(:id),
|
182
|
-
ThinkingSphinx::Index::FauxColumn.new(:team_id) ]
|
183
|
-
)
|
184
|
-
attribute.model = Person
|
185
|
-
attribute.columns.each { |col| attribute.associations[col] = [] }
|
186
|
-
|
187
|
-
attribute.send(:all_ints?).should be_true
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should return false if only some columns are integers" do
|
191
|
-
attribute = ThinkingSphinx::Attribute.new(
|
192
|
-
[ ThinkingSphinx::Index::FauxColumn.new(:id),
|
193
|
-
ThinkingSphinx::Index::FauxColumn.new(:first_name) ]
|
194
|
-
)
|
195
|
-
attribute.model = Person
|
196
|
-
attribute.columns.each { |col| attribute.associations[col] = [] }
|
197
|
-
|
198
|
-
attribute.send(:all_ints?).should be_false
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should return false if no columns are integers" do
|
202
|
-
attribute = ThinkingSphinx::Attribute.new(
|
203
|
-
[ ThinkingSphinx::Index::FauxColumn.new(:first_name),
|
204
|
-
ThinkingSphinx::Index::FauxColumn.new(:last_name) ]
|
205
|
-
)
|
206
|
-
attribute.model = Person
|
207
|
-
attribute.columns.each { |col| attribute.associations[col] = [] }
|
208
|
-
|
209
|
-
attribute.send(:all_ints?).should be_false
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
describe ThinkingSphinx::Collection do
|
4
|
-
it "should behave like WillPaginate::Collection" do
|
5
|
-
ThinkingSphinx::Collection.instance_methods.should include("previous_page")
|
6
|
-
ThinkingSphinx::Collection.instance_methods.should include("next_page")
|
7
|
-
ThinkingSphinx::Collection.instance_methods.should include("current_page")
|
8
|
-
ThinkingSphinx::Collection.instance_methods.should include("total_pages")
|
9
|
-
ThinkingSphinx::Collection.instance_methods.should include("total_entries")
|
10
|
-
ThinkingSphinx::Collection.instance_methods.should include("offset")
|
11
|
-
|
12
|
-
ThinkingSphinx::Collection.ancestors.should include(Array)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
require 'will_paginate/collection'
|
3
|
-
|
4
|
-
describe ThinkingSphinx::Search do
|
5
|
-
describe "search method" do
|
6
|
-
before :each do
|
7
|
-
@client = Riddle::Client.stub_instance(
|
8
|
-
:filters => [],
|
9
|
-
:filters= => true,
|
10
|
-
:id_range= => true,
|
11
|
-
:sort_mode => :asc,
|
12
|
-
:limit => 5,
|
13
|
-
:offset= => 0,
|
14
|
-
:sort_mode= => true,
|
15
|
-
:query => {
|
16
|
-
:matches => [],
|
17
|
-
:total => 50
|
18
|
-
}
|
19
|
-
)
|
20
|
-
|
21
|
-
ThinkingSphinx::Search.stub_methods(
|
22
|
-
:client_from_options => @client,
|
23
|
-
:search_conditions => ["", []]
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
describe ":star option" do
|
28
|
-
|
29
|
-
it "should not apply by default" do
|
30
|
-
ThinkingSphinx::Search.search "foo bar"
|
31
|
-
@client.should have_received(:query).with("foo bar")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should apply when passed, and handle full extended syntax" do
|
35
|
-
input = %{a b* c (d | e) 123 5&6 (f_f g) !h "i j" "k l"~10 "m n"/3 @o p -(q|r)}
|
36
|
-
expected = %{*a* b* *c* (*d* | *e*) *123* *5*&*6* (*f_f* *g*) !*h* "i j" "k l"~10 "m n"/3 @o *p* -(*q*|*r*)}
|
37
|
-
ThinkingSphinx::Search.search input, :star => true
|
38
|
-
@client.should have_received(:query).with(expected)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should default to /\w+/ as token" do
|
42
|
-
ThinkingSphinx::Search.search "foo@bar.com", :star => true
|
43
|
-
@client.should have_received(:query).with("*foo*@*bar*.*com*")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should honour custom token" do
|
47
|
-
ThinkingSphinx::Search.search "foo@bar.com -foo-bar", :star => /[\w@.-]+/u
|
48
|
-
@client.should have_received(:query).with("*foo@bar.com* -*foo-bar*")
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe ThinkingSphinx::Search, "playing nice with Search model" do
|
56
|
-
it "should not conflict with models called Search" do
|
57
|
-
lambda { Search.find(:all) }.should_not raise_error
|
58
|
-
end
|
59
|
-
end
|