thinking-sphinx 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +4 -0
- data/VERSION +1 -1
- data/features/attribute_updates.feature +3 -3
- data/features/handling_edits.feature +5 -3
- data/features/step_definitions/search_steps.rb +4 -4
- data/features/thinking_sphinx/models/beta.rb +5 -0
- data/features/thinking_sphinx/models/developer.rb +11 -0
- data/lib/thinking_sphinx.rb +1 -0
- data/lib/thinking_sphinx/active_record.rb +17 -16
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +1 -1
- data/lib/thinking_sphinx/active_record/delta.rb +10 -6
- data/lib/thinking_sphinx/auto_version.rb +4 -1
- data/lib/thinking_sphinx/core/array.rb +1 -1
- data/lib/thinking_sphinx/search.rb +17 -2
- data/spec/thinking_sphinx/active_record/delta_spec.rb +1 -1
- data/spec/thinking_sphinx/active_record_spec.rb +6 -44
- data/spec/thinking_sphinx/auto_version_spec.rb +1 -1
- data/spec/thinking_sphinx/facet_search_spec.rb +8 -0
- metadata +4 -4
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.4
|
@@ -36,7 +36,7 @@ Feature: Update attributes directly to Sphinx
|
|
36
36
|
And I filter by 18 on value
|
37
37
|
Then I should get 1 result
|
38
38
|
|
39
|
-
When I search for the document id of beta eight in the
|
39
|
+
When I search for the document id of beta eight in the secondary_beta_delta index
|
40
40
|
Then it should not exist
|
41
41
|
|
42
42
|
Scenario: Updating attributes in a delta index
|
@@ -48,7 +48,7 @@ Feature: Update attributes directly to Sphinx
|
|
48
48
|
And I wait for Sphinx to catch up
|
49
49
|
|
50
50
|
When I filter by 19 on value
|
51
|
-
And I use index
|
51
|
+
And I use index secondary_beta_delta
|
52
52
|
Then I should get 1 result
|
53
53
|
|
54
54
|
Scenario: Updating attributes in a delta index with deltas disabled
|
@@ -61,7 +61,7 @@ Feature: Update attributes directly to Sphinx
|
|
61
61
|
And I wait for Sphinx to catch up
|
62
62
|
|
63
63
|
When I filter by 21 on value
|
64
|
-
And I use index
|
64
|
+
And I use index secondary_beta_delta
|
65
65
|
Then I should get 1 result
|
66
66
|
And I enable delta updates
|
67
67
|
|
@@ -31,12 +31,12 @@ Feature: Keeping Sphinx in line with model changes when requested
|
|
31
31
|
When I search for one
|
32
32
|
Then I should get 1 result
|
33
33
|
|
34
|
-
When I change the name of beta one to
|
34
|
+
When I change the name of beta one to eleventeen
|
35
35
|
And I wait for Sphinx to catch up
|
36
36
|
And I search for one
|
37
37
|
Then I should get 0 results
|
38
38
|
|
39
|
-
When I search for
|
39
|
+
When I search for eleventeen
|
40
40
|
Then I should get 1 result
|
41
41
|
|
42
42
|
Scenario: Returning new records if there's a delta
|
@@ -63,7 +63,9 @@ Feature: Keeping Sphinx in line with model changes when requested
|
|
63
63
|
|
64
64
|
When I search for the document id of beta five in the beta_core index
|
65
65
|
Then it should exist if using Rails 2.1 or newer
|
66
|
-
When I search for the document id of beta five in the
|
66
|
+
When I search for the document id of beta five in the secondary_beta_core index
|
67
|
+
Then it should exist if using Rails 2.1 or newer
|
68
|
+
When I search for the document id of beta five in the secondary_beta_delta index
|
67
69
|
Then it should not exist if using Rails 2.1 or newer
|
68
70
|
|
69
71
|
Scenario: Handling edits with a delta when Sphinx isn't running
|
@@ -11,24 +11,24 @@ When /^I search for the document id of (\w+) (\w+) in the (\w+) index$/ do |mode
|
|
11
11
|
end
|
12
12
|
|
13
13
|
Then "it should exist" do
|
14
|
-
ThinkingSphinx
|
14
|
+
ThinkingSphinx.search_for_id(@id, @index).should == true
|
15
15
|
end
|
16
16
|
|
17
17
|
Then "it should not exist" do
|
18
|
-
ThinkingSphinx
|
18
|
+
ThinkingSphinx.search_for_id(@id, @index).should == false
|
19
19
|
end
|
20
20
|
|
21
21
|
Then "it should exist if using Rails 2.1 or newer" do
|
22
22
|
require 'active_record/version'
|
23
23
|
unless ActiveRecord::VERSION::STRING.to_f < 2.1
|
24
|
-
ThinkingSphinx
|
24
|
+
ThinkingSphinx.search_for_id(@id, @index).should == true
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
Then "it should not exist if using Rails 2.1 or newer" do
|
29
29
|
require 'active_record/version'
|
30
30
|
unless ActiveRecord::VERSION::STRING.to_f < 2.1
|
31
|
-
ThinkingSphinx
|
31
|
+
ThinkingSphinx.search_for_id(@id, @index).should == false
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -17,4 +17,15 @@ class Developer < ActiveRecord::Base
|
|
17
17
|
|
18
18
|
group_by 'city'
|
19
19
|
end
|
20
|
+
|
21
|
+
define_index 'alternate' do
|
22
|
+
indexes "'foo'", :as => :foo
|
23
|
+
|
24
|
+
has age, :facet => true
|
25
|
+
has tags(:id), :as => :tag_ids, :facet => true
|
26
|
+
|
27
|
+
facet "LOWER(city)", :as => :city, :type => :string, :value => :city
|
28
|
+
|
29
|
+
group_by 'city'
|
30
|
+
end
|
20
31
|
end
|
data/lib/thinking_sphinx.rb
CHANGED
@@ -24,7 +24,18 @@ module ThinkingSphinx
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def primary_key_for_sphinx
|
27
|
-
|
27
|
+
if custom_primary_key_for_sphinx?
|
28
|
+
@sphinx_primary_key_attribute || superclass.primary_key_for_sphinx
|
29
|
+
else
|
30
|
+
primary_key
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def custom_primary_key_for_sphinx?
|
35
|
+
(
|
36
|
+
superclass.respond_to?(:custom_primary_key_for_sphinx?) &&
|
37
|
+
superclass.custom_primary_key_for_sphinx?
|
38
|
+
) || !@sphinx_primary_key_attribute.nil?
|
28
39
|
end
|
29
40
|
|
30
41
|
def sphinx_index_options
|
@@ -328,22 +339,12 @@ module ThinkingSphinx
|
|
328
339
|
attr_accessor :sphinx_attributes
|
329
340
|
attr_accessor :matching_fields
|
330
341
|
|
331
|
-
def in_index?(
|
332
|
-
self.class.search_for_id self.sphinx_document_id,
|
333
|
-
|
334
|
-
|
335
|
-
def in_core_index?
|
336
|
-
in_index? "core"
|
337
|
-
end
|
338
|
-
|
339
|
-
def in_delta_index?
|
340
|
-
in_index? "delta"
|
341
|
-
end
|
342
|
-
|
343
|
-
def in_both_indexes?
|
344
|
-
in_core_index? && in_delta_index?
|
342
|
+
def in_index?(index)
|
343
|
+
self.class.search_for_id self.sphinx_document_id, index
|
344
|
+
rescue Riddle::ResponseError
|
345
|
+
true
|
345
346
|
end
|
346
|
-
|
347
|
+
|
347
348
|
def toggle_deleted
|
348
349
|
return unless ThinkingSphinx.updates_enabled?
|
349
350
|
|
@@ -43,7 +43,7 @@ module ThinkingSphinx
|
|
43
43
|
config = ThinkingSphinx::Configuration.instance
|
44
44
|
config.client.update index_name, attribute_names, {
|
45
45
|
sphinx_document_id => attribute_values
|
46
|
-
} if
|
46
|
+
} if in_index?(index_name)
|
47
47
|
rescue Riddle::ConnectionError, ThinkingSphinx::SphinxError
|
48
48
|
# Not the end of the world if Sphinx isn't running.
|
49
49
|
end
|
@@ -16,30 +16,34 @@ module ThinkingSphinx
|
|
16
16
|
# if running in the test environment.
|
17
17
|
#
|
18
18
|
def index_delta(instance = nil)
|
19
|
-
|
19
|
+
delta_objects.each { |obj| obj.index(self, instance) }
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
self.sphinx_indexes.
|
22
|
+
def delta_objects
|
23
|
+
self.sphinx_indexes.collect(&:delta_object).compact
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def toggled_delta?
|
28
|
-
self.class.
|
28
|
+
self.class.delta_objects.any? { |obj| obj.toggled(self) }
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
33
|
# Set the delta value for the model to be true.
|
34
34
|
def toggle_delta
|
35
|
-
self.class.
|
35
|
+
self.class.delta_objects.each { |obj|
|
36
|
+
obj.toggle(self)
|
37
|
+
} if should_toggle_delta?
|
36
38
|
end
|
37
39
|
|
38
40
|
# Build the delta index for the related model. This won't be called
|
39
41
|
# if running in the test environment.
|
40
42
|
#
|
41
43
|
def index_delta
|
42
|
-
self.class.index_delta(self) if self.class.
|
44
|
+
self.class.index_delta(self) if self.class.delta_objects.any? { |obj|
|
45
|
+
obj.toggled(self)
|
46
|
+
}
|
43
47
|
end
|
44
48
|
|
45
49
|
def should_toggle_delta?
|
@@ -5,9 +5,12 @@ module ThinkingSphinx
|
|
5
5
|
case version
|
6
6
|
when '0.9.8', '0.9.9'
|
7
7
|
require "riddle/#{version}"
|
8
|
-
when '1.10-beta', '1.10-id64-beta'
|
8
|
+
when '1.10-beta', '1.10-id64-beta', '1.10-dev'
|
9
9
|
require 'riddle/1.10'
|
10
10
|
else
|
11
|
+
unless version.nil? or version.empty?
|
12
|
+
STDERR.puts "Unsupported version: #{version}"
|
13
|
+
end
|
11
14
|
STDERR.puts %Q{
|
12
15
|
Sphinx cannot be found on your system. You may need to configure the following
|
13
16
|
settings in your config/sphinx.yml file:
|
@@ -193,6 +193,12 @@ module ThinkingSphinx
|
|
193
193
|
@options[:page].blank? ? 1 : @options[:page].to_i
|
194
194
|
end
|
195
195
|
|
196
|
+
# Kaminari support
|
197
|
+
def page(page_number)
|
198
|
+
@options[:page] = page_number
|
199
|
+
self
|
200
|
+
end
|
201
|
+
|
196
202
|
# The next page number of the result set. If there are no more pages
|
197
203
|
# available, nil is returned.
|
198
204
|
#
|
@@ -221,6 +227,14 @@ module ThinkingSphinx
|
|
221
227
|
@options[:limit] ||= 20
|
222
228
|
@options[:limit].to_i
|
223
229
|
end
|
230
|
+
# Kaminari support
|
231
|
+
alias_method :limit_value, :per_page
|
232
|
+
|
233
|
+
# Kaminari support
|
234
|
+
def per(limit)
|
235
|
+
@options[:limit] = limit
|
236
|
+
self
|
237
|
+
end
|
224
238
|
|
225
239
|
# The total number of pages available if the results are paginated.
|
226
240
|
#
|
@@ -232,8 +246,9 @@ module ThinkingSphinx
|
|
232
246
|
|
233
247
|
@total_pages ||= (@results[:total] / per_page.to_f).ceil
|
234
248
|
end
|
235
|
-
# Compatibility with older versions of will_paginate
|
249
|
+
# Compatibility with kaminari and older versions of will_paginate
|
236
250
|
alias_method :page_count, :total_pages
|
251
|
+
alias_method :num_pages, :total_pages
|
237
252
|
|
238
253
|
# Query time taken
|
239
254
|
#
|
@@ -309,7 +324,7 @@ module ThinkingSphinx
|
|
309
324
|
{
|
310
325
|
:docs => [string.to_s],
|
311
326
|
:words => results[:words].keys.join(' '),
|
312
|
-
:index => options[:index] || "#{model.
|
327
|
+
:index => options[:index] || "#{model.core_index_names.first}"
|
313
328
|
}.merge(options[:excerpt_options] || {})
|
314
329
|
).first
|
315
330
|
end
|
@@ -70,7 +70,7 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
|
|
70
70
|
ThinkingSphinx.deltas_enabled = true
|
71
71
|
ThinkingSphinx.updates_enabled = true
|
72
72
|
ThinkingSphinx.stub!(:sphinx_running? => true)
|
73
|
-
Person.
|
73
|
+
Person.delta_objects.first.stub!(:` => "", :toggled => true)
|
74
74
|
|
75
75
|
@person = Person.new
|
76
76
|
Person.stub!(:search_for_id => false)
|
@@ -234,50 +234,6 @@ describe ThinkingSphinx::ActiveRecord do
|
|
234
234
|
Beta.sphinx_indexes.length.should == 1
|
235
235
|
end
|
236
236
|
end
|
237
|
-
|
238
|
-
describe "index methods" do
|
239
|
-
before(:all) do
|
240
|
-
@person = Person.find(:first)
|
241
|
-
end
|
242
|
-
|
243
|
-
describe "in_both_indexes?" do
|
244
|
-
it "should return true if in core and delta indexes" do
|
245
|
-
@person.should_receive(:in_core_index?).and_return(true)
|
246
|
-
@person.should_receive(:in_delta_index?).and_return(true)
|
247
|
-
@person.in_both_indexes?.should be_true
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should return false if in one index and not the other" do
|
251
|
-
@person.should_receive(:in_core_index?).and_return(true)
|
252
|
-
@person.should_receive(:in_delta_index?).and_return(false)
|
253
|
-
@person.in_both_indexes?.should be_false
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
describe "in_core_index?" do
|
258
|
-
it "should call in_index? with core" do
|
259
|
-
@person.should_receive(:in_index?).with('core')
|
260
|
-
@person.in_core_index?
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "in_delta_index?" do
|
265
|
-
it "should call in_index? with delta" do
|
266
|
-
@person.should_receive(:in_index?).with('delta')
|
267
|
-
@person.in_delta_index?
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe "in_index?" do
|
272
|
-
it "should return true if in the specified index" do
|
273
|
-
@person.should_receive(:sphinx_document_id).and_return(1)
|
274
|
-
@person.should_receive(:sphinx_index_name).and_return('person_core')
|
275
|
-
Person.should_receive(:search_for_id).with(1, 'person_core').and_return(true)
|
276
|
-
|
277
|
-
@person.in_index?('core').should be_true
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
237
|
|
282
238
|
describe '.source_of_sphinx_index' do
|
283
239
|
it "should return self if model defines an index" do
|
@@ -450,6 +406,12 @@ describe ThinkingSphinx::ActiveRecord do
|
|
450
406
|
@person.stub!(:id => 'unique_hash')
|
451
407
|
@person.primary_key_for_sphinx.should == id
|
452
408
|
end
|
409
|
+
|
410
|
+
it "should be inherited by subclasses" do
|
411
|
+
Person.set_sphinx_primary_key :first_name
|
412
|
+
Parent.superclass.custom_primary_key_for_sphinx?
|
413
|
+
Parent.primary_key_for_sphinx.should == Person.primary_key_for_sphinx
|
414
|
+
end
|
453
415
|
end
|
454
416
|
|
455
417
|
describe '.sphinx_index_names' do
|
@@ -39,7 +39,7 @@ describe ThinkingSphinx::AutoVersion do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should output a warning if the detected version is something else" do
|
42
|
-
STDERR.should_receive(:puts)
|
42
|
+
STDERR.should_receive(:puts).twice
|
43
43
|
|
44
44
|
@config.stub!(:version => '0.9.7')
|
45
45
|
ThinkingSphinx::AutoVersion.detect
|
@@ -98,6 +98,14 @@ describe ThinkingSphinx::FacetSearch do
|
|
98
98
|
:classes => [Person], :facets => :state
|
99
99
|
)
|
100
100
|
end
|
101
|
+
|
102
|
+
it "should handle multiple facets" do
|
103
|
+
ThinkingSphinx.should_receive(:search).twice.and_return(search)
|
104
|
+
|
105
|
+
ThinkingSphinx::FacetSearch.new(
|
106
|
+
:classes => [Person], :facets => [:state, :city]
|
107
|
+
)
|
108
|
+
end
|
101
109
|
end
|
102
110
|
|
103
111
|
describe "empty result set for attributes" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 4
|
10
|
+
version: 1.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pat Allan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-03 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|