freelancing-god-thinking-sphinx 1.1.24 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -0
- data/lib/thinking_sphinx.rb +8 -5
- data/lib/thinking_sphinx/active_record.rb +5 -4
- data/lib/thinking_sphinx/active_record/scopes.rb +37 -0
- data/lib/thinking_sphinx/configuration.rb +6 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet_search.rb +134 -0
- data/lib/thinking_sphinx/search.rb +590 -673
- data/lib/thinking_sphinx/search_methods.rb +421 -0
- data/lib/thinking_sphinx/tasks.rb +3 -3
- data/spec/{unit → lib}/thinking_sphinx/active_record/delta_spec.rb +0 -0
- 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 +0 -0
- data/spec/{unit → lib}/thinking_sphinx/association_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/attribute_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/configuration_spec.rb +25 -0
- 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/{unit → lib}/thinking_sphinx/facet_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/field_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/index/builder_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/index/faux_column_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/index_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/rails_additions_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/lib/thinking_sphinx/search_spec.rb +879 -0
- data/spec/{unit → lib}/thinking_sphinx/source_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx_spec.rb +0 -0
- data/vendor/riddle/lib/riddle/client.rb +3 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +1 -1
- data/vendor/riddle/lib/riddle/controller.rb +1 -1
- metadata +46 -44
- data/lib/thinking_sphinx/active_record/search.rb +0 -57
- data/lib/thinking_sphinx/collection.rb +0 -148
- data/lib/thinking_sphinx/facet_collection.rb +0 -59
- data/lib/thinking_sphinx/search/facets.rb +0 -104
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +0 -107
- data/spec/unit/thinking_sphinx/collection_spec.rb +0 -15
- data/spec/unit/thinking_sphinx/facet_collection_spec.rb +0 -64
- data/spec/unit/thinking_sphinx/search_spec.rb +0 -228
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
describe "ThinkingSphinx::ActiveRecord::Search" do
|
4
|
-
it "should add search_for_ids to ActiveRecord::Base" do
|
5
|
-
ActiveRecord::Base.should respond_to("search_for_ids")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should add search_for_ids to ActiveRecord::Base" do
|
9
|
-
ActiveRecord::Base.should respond_to("search")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should add search_count to ActiveRecord::Base" do
|
13
|
-
ActiveRecord::Base.should respond_to("search_count")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should add search_for_id to ActiveRecord::Base" do
|
17
|
-
ActiveRecord::Base.should respond_to("search_for_id")
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "search_for_ids method" do
|
21
|
-
before :each do
|
22
|
-
ThinkingSphinx::Search.stub_method(:search_for_ids => true)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should call ThinkingSphinx::Search#search_for_ids with the class option set" do
|
26
|
-
Person.search_for_ids("search")
|
27
|
-
|
28
|
-
ThinkingSphinx::Search.should have_received(:search_for_ids).with(
|
29
|
-
"search", :class => Person
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should override the class option" do
|
34
|
-
Person.search_for_ids("search", :class => Friendship)
|
35
|
-
|
36
|
-
ThinkingSphinx::Search.should have_received(:search_for_ids).with(
|
37
|
-
"search", :class => Person
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "search method" do
|
43
|
-
before :each do
|
44
|
-
ThinkingSphinx::Search.stub_method(:search => true)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should call ThinkingSphinx::Search#search with the class option set" do
|
48
|
-
Person.search("search")
|
49
|
-
|
50
|
-
ThinkingSphinx::Search.should have_received(:search).with(
|
51
|
-
"search", :class => Person
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should override the class option" do
|
56
|
-
Person.search("search", :class => Friendship)
|
57
|
-
|
58
|
-
ThinkingSphinx::Search.should have_received(:search).with(
|
59
|
-
"search", :class => Person
|
60
|
-
)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "search_for_id method" do
|
65
|
-
before :each do
|
66
|
-
ThinkingSphinx::Search.stub_method(:search_for_id => true)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should call ThinkingSphinx::Search#search with the class option set" do
|
70
|
-
Person.search_for_id(10)
|
71
|
-
|
72
|
-
ThinkingSphinx::Search.should have_received(:search_for_id).with(
|
73
|
-
10, :class => Person
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should override the class option" do
|
78
|
-
Person.search_for_id(10, :class => Friendship)
|
79
|
-
|
80
|
-
ThinkingSphinx::Search.should have_received(:search_for_id).with(
|
81
|
-
10, :class => Person
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "search_count method" do
|
87
|
-
before :each do
|
88
|
-
ThinkingSphinx::Search.stub_method(:count => true)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should call ThinkingSphinx::Search#search with the class option set" do
|
92
|
-
Person.search_count("search")
|
93
|
-
|
94
|
-
ThinkingSphinx::Search.should have_received(:count).with(
|
95
|
-
"search", :class => Person
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should override the class option" do
|
100
|
-
Person.search_count("search", :class => Friendship)
|
101
|
-
|
102
|
-
ThinkingSphinx::Search.should have_received(:count).with(
|
103
|
-
"search", :class => Person
|
104
|
-
)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -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
|