ebeigarts-thinking-sphinx 1.1.22 → 1.2.10

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 (61) hide show
  1. data/README.textile +14 -0
  2. data/VERSION.yml +4 -0
  3. data/lib/thinking_sphinx.rb +60 -64
  4. data/lib/thinking_sphinx/active_record.rb +35 -7
  5. data/lib/thinking_sphinx/active_record/scopes.rb +39 -0
  6. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +3 -2
  7. data/lib/thinking_sphinx/attribute.rb +62 -22
  8. data/lib/thinking_sphinx/configuration.rb +21 -1
  9. data/lib/thinking_sphinx/core/array.rb +7 -0
  10. data/lib/thinking_sphinx/deltas/delayed_delta.rb +3 -0
  11. data/lib/thinking_sphinx/deploy/capistrano.rb +26 -8
  12. data/lib/thinking_sphinx/excerpter.rb +22 -0
  13. data/lib/thinking_sphinx/facet.rb +8 -2
  14. data/lib/thinking_sphinx/facet_search.rb +134 -0
  15. data/lib/thinking_sphinx/index.rb +2 -2
  16. data/lib/thinking_sphinx/index/builder.rb +0 -1
  17. data/lib/thinking_sphinx/property.rb +2 -0
  18. data/lib/thinking_sphinx/rails_additions.rb +14 -0
  19. data/lib/thinking_sphinx/search.rb +633 -671
  20. data/lib/thinking_sphinx/search_methods.rb +421 -0
  21. data/lib/thinking_sphinx/source.rb +5 -5
  22. data/lib/thinking_sphinx/source/internal_properties.rb +1 -1
  23. data/lib/thinking_sphinx/source/sql.rb +10 -8
  24. data/lib/thinking_sphinx/tasks.rb +14 -9
  25. data/spec/{unit → lib}/thinking_sphinx/active_record/delta_spec.rb +1 -1
  26. data/spec/{unit → lib}/thinking_sphinx/active_record/has_many_association_spec.rb +0 -0
  27. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +96 -0
  28. data/spec/{unit → lib}/thinking_sphinx/active_record_spec.rb +44 -5
  29. data/spec/{unit → lib}/thinking_sphinx/association_spec.rb +0 -0
  30. data/spec/{unit → lib}/thinking_sphinx/attribute_spec.rb +110 -3
  31. data/spec/{unit → lib}/thinking_sphinx/configuration_spec.rb +87 -41
  32. data/spec/lib/thinking_sphinx/core/array_spec.rb +9 -0
  33. data/spec/{unit → lib}/thinking_sphinx/core/string_spec.rb +0 -0
  34. data/spec/lib/thinking_sphinx/excerpter_spec.rb +49 -0
  35. data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
  36. data/spec/{unit → lib}/thinking_sphinx/facet_spec.rb +34 -15
  37. data/spec/{unit → lib}/thinking_sphinx/field_spec.rb +0 -0
  38. data/spec/{unit → lib}/thinking_sphinx/index/builder_spec.rb +100 -0
  39. data/spec/{unit → lib}/thinking_sphinx/index/faux_column_spec.rb +0 -0
  40. data/spec/{unit → lib}/thinking_sphinx/index_spec.rb +0 -0
  41. data/spec/{unit → lib}/thinking_sphinx/rails_additions_spec.rb +12 -0
  42. data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
  43. data/spec/lib/thinking_sphinx/search_spec.rb +1066 -0
  44. data/spec/{unit → lib}/thinking_sphinx/source_spec.rb +10 -0
  45. data/spec/{unit → lib}/thinking_sphinx_spec.rb +10 -0
  46. data/tasks/distribution.rb +20 -38
  47. data/tasks/testing.rb +3 -1
  48. data/vendor/riddle/lib/riddle.rb +1 -1
  49. data/vendor/riddle/lib/riddle/client.rb +3 -0
  50. data/vendor/riddle/lib/riddle/client/message.rb +4 -3
  51. data/vendor/riddle/lib/riddle/configuration/section.rb +1 -1
  52. data/vendor/riddle/lib/riddle/controller.rb +17 -7
  53. metadata +63 -83
  54. data/lib/thinking_sphinx/active_record/search.rb +0 -57
  55. data/lib/thinking_sphinx/collection.rb +0 -148
  56. data/lib/thinking_sphinx/facet_collection.rb +0 -59
  57. data/lib/thinking_sphinx/search/facets.rb +0 -104
  58. data/spec/unit/thinking_sphinx/active_record/search_spec.rb +0 -107
  59. data/spec/unit/thinking_sphinx/collection_spec.rb +0 -15
  60. data/spec/unit/thinking_sphinx/facet_collection_spec.rb +0 -64
  61. data/spec/unit/thinking_sphinx/search_spec.rb +0 -228
@@ -1,15 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::Collection do
4
- it "should behave like WillPaginate::Collection" do
5
- instance_methods = ThinkingSphinx::Collection.instance_methods.collect { |m| m.to_s }
6
- instance_methods.should include("previous_page")
7
- instance_methods.should include("next_page")
8
- instance_methods.should include("current_page")
9
- instance_methods.should include("total_pages")
10
- instance_methods.should include("total_entries")
11
- instance_methods.should include("offset")
12
-
13
- ThinkingSphinx::Collection.ancestors.should include(Array)
14
- end
15
- end
@@ -1,64 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::FacetCollection do
4
- before do
5
- @facet_collection = ThinkingSphinx::FacetCollection.new([])
6
- end
7
-
8
- # TODO fix nasty hack when we have internet!
9
- def mock_results
10
- return @results if defined? @results
11
- @result = Person.find(:first)
12
- @results = [@result]
13
- @results.stub!(:each_with_groupby_and_count).and_yield(@result, @result.city.to_crc32, 1)
14
- @results
15
- end
16
-
17
- describe "#add_from_results" do
18
- describe "with empty result set" do
19
- before do
20
- @facet_collection.add_from_results('attribute_facet', [])
21
- end
22
-
23
- it "should add key as attribute" do
24
- @facet_collection.should have_key(:attribute)
25
- end
26
-
27
- it "should return an empty hash for the facet results" do
28
- @facet_collection[:attribute].should be_empty
29
- end
30
- end
31
-
32
- describe "with non-empty result set" do
33
- before do
34
- @facet_collection.add_from_results('city_facet', mock_results)
35
- end
36
-
37
- it "should return a hash" do
38
- @facet_collection.should be_a_kind_of(Hash)
39
- end
40
-
41
- it "should add key as attribute" do
42
- @facet_collection.keys.should include(:city)
43
- end
44
-
45
- it "should return a hash" do
46
- @facet_collection[:city].should == {@result.city => 1}
47
- end
48
- end
49
- end
50
-
51
- describe "#for" do
52
- before do
53
- @facet_collection.add_from_results('city_facet', mock_results)
54
- end
55
-
56
- it "should return the search results for the attribute and key pair" do
57
- ThinkingSphinx::Search.should_receive(:search) do |options|
58
- options[:with].should have_key('city_facet')
59
- options[:with]['city_facet'].should == @result.city.to_crc32
60
- end
61
- @facet_collection.for(:city => @result.city)
62
- end
63
- end
64
- end
@@ -1,228 +0,0 @@
1
- require 'spec/spec_helper'
2
- require 'will_paginate/collection'
3
-
4
- describe ThinkingSphinx::Search do
5
- describe "search method" do
6
- describe ":star option" do
7
- before :each do
8
- @client = Riddle::Client.new
9
- @client.stub!(
10
- :filters => [],
11
- :filters= => true,
12
- :id_range= => true,
13
- :sort_mode => :asc,
14
- :limit => 5,
15
- :offset= => 0,
16
- :sort_mode= => true,
17
- :query => {
18
- :matches => [],
19
- :total => 50
20
- }
21
- )
22
-
23
- ThinkingSphinx::Search.stub_methods(
24
- :client_from_options => @client,
25
- :search_conditions => ["", []]
26
- )
27
- end
28
-
29
- it "should not apply by default" do
30
- @client.should_receive(:query).with("foo bar",'*','')
31
-
32
- ThinkingSphinx::Search.search "foo bar"
33
- end
34
-
35
- it "should apply when passed, and handle full extended syntax" do
36
- 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)}
37
- 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*)}
38
- @client.should_receive(:query).with(expected,'*','')
39
-
40
- ThinkingSphinx::Search.search input, :star => true
41
- end
42
-
43
- it "should default to /\w+/ as token" do
44
- @client.should_receive(:query).with("*foo*@*bar*.*com*",'*','')
45
-
46
- ThinkingSphinx::Search.search "foo@bar.com", :star => true
47
- end
48
-
49
- it "should honour custom token" do
50
- @client.should_receive(:query).with("*foo@bar.com* -*foo-bar*",'*','')
51
-
52
- ThinkingSphinx::Search.search "foo@bar.com -foo-bar", :star => /[\w@.-]+/u
53
- end
54
- end
55
-
56
- describe "sort modes" do
57
- before :each do
58
- @client = Riddle::Client.new
59
- @client.stub_method(:query => {:matches => []})
60
- Riddle::Client.stub_method(:new => @client)
61
- end
62
-
63
- it "should use :relevance as a default" do
64
- ThinkingSphinx::Search.search "foo"
65
- @client.sort_mode.should == :relevance
66
- end
67
-
68
- it "should use :attr_asc if a symbol is supplied to :order" do
69
- ThinkingSphinx::Search.search "foo", :order => :created_at
70
- @client.sort_mode.should == :attr_asc
71
- end
72
-
73
- it "should use :attr_desc if a symbol is supplied and :desc is the mode" do
74
- ThinkingSphinx::Search.search "foo", :order => :created_at, :sort_mode => :desc
75
- @client.sort_mode.should == :attr_desc
76
- end
77
-
78
- it "should use :extended if a string is supplied to :order" do
79
- ThinkingSphinx::Search.search "foo", :order => "created_at ASC"
80
- @client.sort_mode.should == :extended
81
- end
82
-
83
- it "should use :expr if explicitly requested with a string supplied to :order" do
84
- ThinkingSphinx::Search.search "foo", :order => "created_at ASC", :sort_mode => :expr
85
- @client.sort_mode.should == :expr
86
- end
87
-
88
- it "should use :attr_desc if explicitly requested with a string supplied to :order" do
89
- ThinkingSphinx::Search.search "foo", :order => "created_at", :sort_mode => :desc
90
- @client.sort_mode.should == :attr_desc
91
- end
92
- end
93
-
94
- describe "grouping" do
95
- before :each do
96
- @client = Riddle::Client.new
97
- @client.stub_method(:query => {:matches => []})
98
- Riddle::Client.stub_method(:new => @client)
99
- end
100
-
101
- it "should convert group into group_by and group_function" do
102
- ThinkingSphinx::Search.search "foo", :group => :edition
103
- @client.group_function.should == :attr
104
- @client.group_by.should == "edition"
105
- end
106
- end
107
-
108
- describe ":comment option" do
109
- before :each do
110
- @client = Riddle::Client.new
111
- @client.stub_method(:query => {:matches => []})
112
- Riddle::Client.stub_method(:new => @client)
113
- end
114
-
115
- it "should add comment to log" do
116
- ThinkingSphinx::Search.search 'foo bar', :comment => 'custom log'
117
- @client.should have_received(:query).with('foo bar', '*', 'custom log')
118
- end
119
-
120
- it "should use a blank string when no comment is specified" do
121
- ThinkingSphinx::Search.search 'foo bar'
122
- @client.should have_received(:query).with('foo bar', '*', '')
123
- end
124
- end
125
- end
126
-
127
- describe "facets method" do
128
- before :each do
129
- @person = Person.find(:first)
130
-
131
- @city_results = [@person]
132
- @city_results.stub!(:each_with_groupby_and_count).
133
- and_yield(@person, @person.city.to_crc32, 1)
134
-
135
- @birthday_results = [@person]
136
- @birthday_results.stub!(:each_with_groupby_and_count).
137
- and_yield(@person, @person.birthday.to_i, 1)
138
-
139
- @config = ThinkingSphinx::Configuration.instance
140
- @config.configuration.searchd.max_matches = 10_000
141
- end
142
-
143
- it "should use the system-set max_matches for limit on facet calls" do
144
- ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
145
-
146
- ThinkingSphinx::Search.should_receive(:search) do |options|
147
- options[:max_matches].should == 10_000
148
- options[:limit].should == 10_000
149
- end
150
-
151
- ThinkingSphinx::Search.facets :all_attributes => true
152
- end
153
-
154
- it "should use the default max-matches if there is no explicit setting" do
155
- ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
156
-
157
- @config.configuration.searchd.max_matches = nil
158
- ThinkingSphinx::Search.should_receive(:search) do |options|
159
- options[:max_matches].should == 1000
160
- options[:limit].should == 1000
161
- end
162
-
163
- ThinkingSphinx::Search.facets :all_attributes => true
164
- end
165
-
166
- it "should ignore user-provided max_matches and limit on facet calls" do
167
- ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
168
-
169
- ThinkingSphinx::Search.should_receive(:search) do |options|
170
- options[:max_matches].should == 10_000
171
- options[:limit].should == 10_000
172
- end
173
-
174
- ThinkingSphinx::Search.facets(
175
- :all_attributes => true,
176
- :max_matches => 500,
177
- :limit => 200
178
- )
179
- end
180
-
181
- it "should use explicit facet list if one is provided" do
182
- ThinkingSphinx::Search.should_receive(:search).once.and_return(@city_results)
183
-
184
- ThinkingSphinx::Search.facets(
185
- :facets => ['city'],
186
- :class => Person
187
- )
188
- end
189
-
190
- it "should not use an explicit :page" do
191
- ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
192
- ThinkingSphinx::Search.should_receive(:search) do |options|
193
- options[:page].should == 1
194
- end
195
-
196
- ThinkingSphinx::Search.facets(
197
- :all_attributes => true,
198
- :page => 3
199
- )
200
- end
201
-
202
- describe "conflicting facets" do
203
- before :each do
204
- @index = ThinkingSphinx::Index::Builder.generate(Alpha) do
205
- indexes :name
206
- has :value, :as => :city, :facet => true
207
- end
208
- end
209
-
210
- after :each do
211
- Alpha.sphinx_facets.delete_at(-1)
212
- Alpha.sphinx_indexes.delete_at(-1)
213
- end
214
-
215
- it "should raise an error if searching with facets of same name but different type" do
216
- lambda {
217
- ThinkingSphinx::Search.facets :all_attributes => true
218
- }.should raise_error
219
- end
220
- end
221
- end
222
- end
223
-
224
- describe ThinkingSphinx::Search, "playing nice with Search model" do
225
- it "should not conflict with models called Search" do
226
- lambda { Search.find(:all) }.should_not raise_error
227
- end
228
- end