freelancing-god-thinking-sphinx 1.2.9 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml
CHANGED
@@ -155,6 +155,14 @@ module ThinkingSphinx
|
|
155
155
|
self.name.underscore.tr(':/\\', '_')
|
156
156
|
end
|
157
157
|
|
158
|
+
def sphinx_index_names
|
159
|
+
klass = source_of_sphinx_index
|
160
|
+
names = ["#{klass.sphinx_name}_core"]
|
161
|
+
names << "#{klass.sphinx_name}_delta" if sphinx_delta?
|
162
|
+
|
163
|
+
names
|
164
|
+
end
|
165
|
+
|
158
166
|
private
|
159
167
|
|
160
168
|
def sphinx_delta?
|
@@ -177,6 +177,13 @@ module ThinkingSphinx
|
|
177
177
|
(current_page - 1) * per_page
|
178
178
|
end
|
179
179
|
|
180
|
+
def indexes
|
181
|
+
return options[:index] if options[:index]
|
182
|
+
return '*' if classes.empty?
|
183
|
+
|
184
|
+
classes.collect { |klass| klass.sphinx_index_names }.flatten.join(',')
|
185
|
+
end
|
186
|
+
|
180
187
|
def each_with_groupby_and_count(&block)
|
181
188
|
populate
|
182
189
|
results[:matches].each_with_index do |match, index|
|
@@ -194,8 +201,8 @@ module ThinkingSphinx
|
|
194
201
|
end
|
195
202
|
|
196
203
|
def excerpt_for(string, model = nil)
|
197
|
-
if model.nil? &&
|
198
|
-
model ||=
|
204
|
+
if model.nil? && one_class
|
205
|
+
model ||= one_class
|
199
206
|
end
|
200
207
|
|
201
208
|
populate
|
@@ -224,7 +231,7 @@ module ThinkingSphinx
|
|
224
231
|
retry_on_stale_index do
|
225
232
|
begin
|
226
233
|
log "Querying Sphinx: #{query}"
|
227
|
-
@results = client.query query,
|
234
|
+
@results = client.query query, indexes, comment
|
228
235
|
rescue Errno::ECONNREFUSED => err
|
229
236
|
raise ThinkingSphinx::ConnectionError,
|
230
237
|
'Connection to Sphinx Daemon (searchd) failed.'
|
@@ -266,8 +273,8 @@ module ThinkingSphinx
|
|
266
273
|
def client
|
267
274
|
client = config.client
|
268
275
|
|
269
|
-
index_options =
|
270
|
-
|
276
|
+
index_options = one_class ?
|
277
|
+
one_class.sphinx_indexes.first.local_options : {}
|
271
278
|
|
272
279
|
[
|
273
280
|
:max_matches, :group_by, :group_function, :group_clause,
|
@@ -325,6 +332,10 @@ module ThinkingSphinx
|
|
325
332
|
@classes ||= options[:classes] || []
|
326
333
|
end
|
327
334
|
|
335
|
+
def one_class
|
336
|
+
@one_class ||= classes.length != 1 ? nil : classes.first
|
337
|
+
end
|
338
|
+
|
328
339
|
def query
|
329
340
|
@query ||= begin
|
330
341
|
q = @args.join(' ') << conditions_as_query
|
@@ -363,10 +374,6 @@ module ThinkingSphinx
|
|
363
374
|
end
|
364
375
|
end
|
365
376
|
|
366
|
-
def index
|
367
|
-
options[:index] || '*'
|
368
|
-
end
|
369
|
-
|
370
377
|
def comment
|
371
378
|
options[:comment] || ''
|
372
379
|
end
|
@@ -408,9 +415,9 @@ module ThinkingSphinx
|
|
408
415
|
end
|
409
416
|
|
410
417
|
def field_names
|
411
|
-
return []
|
418
|
+
return [] unless one_class
|
412
419
|
|
413
|
-
|
420
|
+
one_class.sphinx_indexes.collect { |index|
|
414
421
|
index.fields.collect { |field| field.unique_name }
|
415
422
|
}.flatten
|
416
423
|
end
|
@@ -548,15 +555,15 @@ MSG
|
|
548
555
|
end
|
549
556
|
|
550
557
|
def index_option(key)
|
551
|
-
return nil
|
558
|
+
return nil unless one_class
|
552
559
|
|
553
|
-
|
560
|
+
one_class.sphinx_indexes.collect { |index|
|
554
561
|
index.local_options[key]
|
555
562
|
}.compact.first
|
556
563
|
end
|
557
564
|
|
558
565
|
def attribute(*keys)
|
559
|
-
return nil
|
566
|
+
return nil unless one_class
|
560
567
|
|
561
568
|
keys.detect { |key|
|
562
569
|
attributes.include?(key)
|
@@ -564,9 +571,9 @@ MSG
|
|
564
571
|
end
|
565
572
|
|
566
573
|
def attributes
|
567
|
-
return []
|
574
|
+
return [] unless one_class
|
568
575
|
|
569
|
-
attributes =
|
576
|
+
attributes = one_class.sphinx_indexes.collect { |index|
|
570
577
|
index.attributes.collect { |attrib| attrib.unique_name }
|
571
578
|
}.flatten
|
572
579
|
end
|
@@ -618,7 +625,7 @@ MSG
|
|
618
625
|
# the number of #find's in multi-model searches.
|
619
626
|
#
|
620
627
|
def instances_from_matches
|
621
|
-
return single_class_results if
|
628
|
+
return single_class_results if one_class
|
622
629
|
|
623
630
|
groups = results[:matches].group_by { |match|
|
624
631
|
match[:attributes]["class_crc"]
|
@@ -639,7 +646,7 @@ MSG
|
|
639
646
|
end
|
640
647
|
|
641
648
|
def single_class_results
|
642
|
-
instances_from_class
|
649
|
+
instances_from_class one_class, results[:matches]
|
643
650
|
end
|
644
651
|
|
645
652
|
def class_from_crc(crc)
|
@@ -655,12 +662,11 @@ MSG
|
|
655
662
|
end
|
656
663
|
|
657
664
|
def is_scope?(method)
|
658
|
-
|
659
|
-
classes.first.sphinx_scopes.include?(method)
|
665
|
+
one_class && one_class.sphinx_scopes.include?(method)
|
660
666
|
end
|
661
667
|
|
662
668
|
def add_scope(method, *args, &block)
|
663
|
-
merge_search
|
669
|
+
merge_search one_class.send(method, *args, &block)
|
664
670
|
end
|
665
671
|
|
666
672
|
def merge_search(search)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe
|
3
|
+
describe ThinkingSphinx::ActiveRecord do
|
4
|
+
describe '.define_index' do
|
5
5
|
before :each do
|
6
6
|
module ::TestModule
|
7
7
|
class TestModel < ActiveRecord::Base; end
|
@@ -154,7 +154,7 @@ describe "ThinkingSphinx::ActiveRecord" do
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
describe
|
157
|
+
describe '.source_of_sphinx_index' do
|
158
158
|
it "should return self if model defines an index" do
|
159
159
|
Person.source_of_sphinx_index.should == Person
|
160
160
|
end
|
@@ -164,13 +164,13 @@ describe "ThinkingSphinx::ActiveRecord" do
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
describe
|
167
|
+
describe '.to_crc32' do
|
168
168
|
it "should return an integer" do
|
169
169
|
Person.to_crc32.should be_a_kind_of(Integer)
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
describe
|
173
|
+
describe '.to_crc32s' do
|
174
174
|
it "should return an array" do
|
175
175
|
Person.to_crc32s.should be_a_kind_of(Array)
|
176
176
|
end
|
@@ -351,4 +351,18 @@ describe "ThinkingSphinx::ActiveRecord" do
|
|
351
351
|
@person.primary_key_for_sphinx.should == id
|
352
352
|
end
|
353
353
|
end
|
354
|
+
|
355
|
+
describe '.sphinx_index_names' do
|
356
|
+
it "should return the core index" do
|
357
|
+
Alpha.sphinx_index_names.should == ['alpha_core']
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should return the delta index if enabled" do
|
361
|
+
Beta.sphinx_index_names.should == ['beta_core', 'beta_delta']
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should return the superclass with an index definition" do
|
365
|
+
Parent.sphinx_index_names.should == ['person_core', 'person_delta']
|
366
|
+
end
|
367
|
+
end
|
354
368
|
end
|
@@ -193,6 +193,14 @@ describe ThinkingSphinx::Search do
|
|
193
193
|
search[3].id.should == 1
|
194
194
|
end
|
195
195
|
|
196
|
+
it "should use the requested classes to generate the index argument" do
|
197
|
+
@client.should_receive(:query) do |query, index, comment|
|
198
|
+
index.should == 'alpha_core,beta_core,beta_delta'
|
199
|
+
end
|
200
|
+
|
201
|
+
ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).first
|
202
|
+
end
|
203
|
+
|
196
204
|
describe 'query' do
|
197
205
|
it "should concatenate arguments with spaces" do
|
198
206
|
@client.should_receive(:query) do |query, index, comment|
|
@@ -838,6 +846,27 @@ describe ThinkingSphinx::Search do
|
|
838
846
|
end
|
839
847
|
end
|
840
848
|
|
849
|
+
describe '#indexes' do
|
850
|
+
it "should default to '*'" do
|
851
|
+
ThinkingSphinx::Search.new.indexes.should == '*'
|
852
|
+
end
|
853
|
+
|
854
|
+
it "should use given class to determine index name" do
|
855
|
+
ThinkingSphinx::Search.new(:classes => [Alpha]).indexes.
|
856
|
+
should == 'alpha_core'
|
857
|
+
end
|
858
|
+
|
859
|
+
it "should add both core and delta indexes for given classes" do
|
860
|
+
ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).indexes.
|
861
|
+
should == 'alpha_core,beta_core,beta_delta'
|
862
|
+
end
|
863
|
+
|
864
|
+
it "should respect the :index option" do
|
865
|
+
ThinkingSphinx::Search.new(:classes => [Alpha], :index => '*').indexes.
|
866
|
+
should == '*'
|
867
|
+
end
|
868
|
+
end
|
869
|
+
|
841
870
|
describe '.each_with_groupby_and_count' do
|
842
871
|
before :each do
|
843
872
|
@alpha = Alpha.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freelancing-god-thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|