thinking-sphinx 3.1.2 → 3.1.3
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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Appraisals +7 -3
- data/HISTORY +12 -0
- data/README.textile +5 -3
- data/gemfiles/rails_3_2.gemfile +1 -1
- data/gemfiles/rails_4_0.gemfile +1 -1
- data/gemfiles/rails_4_1.gemfile +1 -1
- data/gemfiles/rails_4_2.gemfile +11 -0
- data/lib/thinking_sphinx.rb +1 -1
- data/lib/thinking_sphinx/active_record.rb +1 -1
- data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +3 -1
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +1 -1
- data/lib/thinking_sphinx/active_record/filter_reflection.rb +75 -0
- data/lib/thinking_sphinx/active_record/polymorpher.rb +4 -4
- data/lib/thinking_sphinx/active_record/property_query.rb +1 -1
- data/lib/thinking_sphinx/active_record/simple_many_query.rb +1 -1
- data/lib/thinking_sphinx/active_record/sql_builder.rb +0 -4
- data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +0 -1
- data/lib/thinking_sphinx/configuration.rb +6 -3
- data/lib/thinking_sphinx/core/index.rb +1 -1
- data/lib/thinking_sphinx/excerpter.rb +4 -1
- data/lib/thinking_sphinx/facet_search.rb +8 -2
- data/lib/thinking_sphinx/index_set.rb +33 -11
- data/lib/thinking_sphinx/middlewares/inquirer.rb +1 -1
- data/lib/thinking_sphinx/middlewares/sphinxql.rb +3 -1
- data/lib/thinking_sphinx/railtie.rb +4 -2
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +2 -4
- data/lib/thinking_sphinx/real_time/index.rb +2 -0
- data/lib/thinking_sphinx/real_time/index/template.rb +1 -1
- data/spec/acceptance/big_integers_spec.rb +27 -6
- data/spec/acceptance/facets_spec.rb +1 -2
- data/spec/acceptance/real_time_updates_spec.rb +8 -0
- data/spec/acceptance/remove_deleted_records_spec.rb +4 -2
- data/spec/acceptance/searching_across_schemas_spec.rb +38 -0
- data/spec/acceptance/searching_with_sti_spec.rb +19 -7
- data/spec/internal/app/indices/bird_index.rb +4 -0
- data/spec/internal/app/indices/product_index.rb +21 -0
- data/spec/internal/db/schema.rb +9 -9
- data/spec/spec_helper.rb +2 -1
- data/spec/support/multi_schema.rb +46 -0
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +5 -3
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +172 -0
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +18 -11
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +0 -105
- data/spec/thinking_sphinx/configuration_spec.rb +0 -13
- data/spec/thinking_sphinx/facet_search_spec.rb +1 -2
- data/spec/thinking_sphinx/index_set_spec.rb +31 -13
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +19 -0
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +6 -4
- data/thinking-sphinx.gemspec +1 -1
- metadata +13 -6
- data/lib/thinking_sphinx/active_record/filtered_reflection.rb +0 -75
- data/spec/thinking_sphinx/active_record/filtered_reflection_spec.rb +0 -141
@@ -47,5 +47,24 @@ describe ThinkingSphinx::Middlewares::Inquirer do
|
|
47
47
|
|
48
48
|
context[:results].should == [:raw]
|
49
49
|
end
|
50
|
+
|
51
|
+
context "with mysql2 result" do
|
52
|
+
class FakeResult
|
53
|
+
include Enumerable
|
54
|
+
def each; [{"fake" => "value"}].each { |m| yield m }; end
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:batch_inquirer) { double('batcher', :append_query => true,
|
58
|
+
:results => [
|
59
|
+
FakeResult.new, [{'Variable_name' => 'meta', 'Value' => 'value'}]
|
60
|
+
])
|
61
|
+
}
|
62
|
+
|
63
|
+
it "converts the results into an array" do
|
64
|
+
middleware.call [context]
|
65
|
+
|
66
|
+
context[:results].should be_a Array
|
67
|
+
end
|
68
|
+
end
|
50
69
|
end
|
51
70
|
end
|
@@ -28,12 +28,13 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
28
28
|
let(:sphinx_sql) { double('sphinx_sql', :from => true, :offset => true,
|
29
29
|
:limit => true, :where => true, :matching => true, :values => true) }
|
30
30
|
let(:query) { double('query') }
|
31
|
-
let(:configuration) { double('configuration', :settings => {}
|
31
|
+
let(:configuration) { double('configuration', :settings => {},
|
32
|
+
index_set_class: set_class) }
|
33
|
+
let(:set_class) { double(:new => index_set) }
|
32
34
|
|
33
35
|
before :each do
|
34
36
|
stub_const 'Riddle::Query::Select', double(:new => sphinx_sql)
|
35
37
|
stub_const 'ThinkingSphinx::Search::Query', double(:new => query)
|
36
|
-
stub_const 'ThinkingSphinx::IndexSet', double(:new => index_set)
|
37
38
|
|
38
39
|
context.stub :search => search, :configuration => configuration
|
39
40
|
end
|
@@ -58,8 +59,9 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
58
59
|
search.options[:indices] = ['user_core']
|
59
60
|
index_set.first.stub :reference => :user
|
60
61
|
|
61
|
-
|
62
|
-
with([klass], ['user_core']).
|
62
|
+
set_class.should_receive(:new).
|
63
|
+
with(:classes => [klass], :indices => ['user_core']).
|
64
|
+
and_return(index_set)
|
63
65
|
|
64
66
|
middleware.call [context]
|
65
67
|
end
|
data/thinking-sphinx.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- gemfiles/rails_3_2.gemfile
|
171
171
|
- gemfiles/rails_4_0.gemfile
|
172
172
|
- gemfiles/rails_4_1.gemfile
|
173
|
+
- gemfiles/rails_4_2.gemfile
|
173
174
|
- lib/thinking-sphinx.rb
|
174
175
|
- lib/thinking/sphinx.rb
|
175
176
|
- lib/thinking_sphinx.rb
|
@@ -193,7 +194,7 @@ files:
|
|
193
194
|
- lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb
|
194
195
|
- lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb
|
195
196
|
- lib/thinking_sphinx/active_record/field.rb
|
196
|
-
- lib/thinking_sphinx/active_record/
|
197
|
+
- lib/thinking_sphinx/active_record/filter_reflection.rb
|
197
198
|
- lib/thinking_sphinx/active_record/index.rb
|
198
199
|
- lib/thinking_sphinx/active_record/interpreter.rb
|
199
200
|
- lib/thinking_sphinx/active_record/join_association.rb
|
@@ -314,6 +315,7 @@ files:
|
|
314
315
|
- spec/acceptance/search_counts_spec.rb
|
315
316
|
- spec/acceptance/search_for_just_ids_spec.rb
|
316
317
|
- spec/acceptance/searching_across_models_spec.rb
|
318
|
+
- spec/acceptance/searching_across_schemas_spec.rb
|
317
319
|
- spec/acceptance/searching_on_fields_spec.rb
|
318
320
|
- spec/acceptance/searching_with_filters_spec.rb
|
319
321
|
- spec/acceptance/searching_with_sti_spec.rb
|
@@ -331,6 +333,7 @@ files:
|
|
331
333
|
- spec/internal/app/indices/admin_person_index.rb
|
332
334
|
- spec/internal/app/indices/animal_index.rb
|
333
335
|
- spec/internal/app/indices/article_index.rb
|
336
|
+
- spec/internal/app/indices/bird_index.rb
|
334
337
|
- spec/internal/app/indices/book_index.rb
|
335
338
|
- spec/internal/app/indices/car_index.rb
|
336
339
|
- spec/internal/app/indices/city_index.rb
|
@@ -363,6 +366,7 @@ files:
|
|
363
366
|
- spec/internal/db/schema.rb
|
364
367
|
- spec/internal/tmp/.gitkeep
|
365
368
|
- spec/spec_helper.rb
|
369
|
+
- spec/support/multi_schema.rb
|
366
370
|
- spec/support/sphinx_yaml_helpers.rb
|
367
371
|
- spec/thinking_sphinx/active_record/association_spec.rb
|
368
372
|
- spec/thinking_sphinx/active_record/attribute/type_spec.rb
|
@@ -376,7 +380,7 @@ files:
|
|
376
380
|
- spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb
|
377
381
|
- spec/thinking_sphinx/active_record/database_adapters_spec.rb
|
378
382
|
- spec/thinking_sphinx/active_record/field_spec.rb
|
379
|
-
- spec/thinking_sphinx/active_record/
|
383
|
+
- spec/thinking_sphinx/active_record/filter_reflection_spec.rb
|
380
384
|
- spec/thinking_sphinx/active_record/index_spec.rb
|
381
385
|
- spec/thinking_sphinx/active_record/interpreter_spec.rb
|
382
386
|
- spec/thinking_sphinx/active_record/polymorpher_spec.rb
|
@@ -439,7 +443,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
439
443
|
version: '0'
|
440
444
|
requirements: []
|
441
445
|
rubyforge_project: thinking-sphinx
|
442
|
-
rubygems_version: 2.
|
446
|
+
rubygems_version: 2.2.2
|
443
447
|
signing_key:
|
444
448
|
specification_version: 4
|
445
449
|
summary: A smart wrapper over Sphinx for ActiveRecord
|
@@ -461,6 +465,7 @@ test_files:
|
|
461
465
|
- spec/acceptance/search_counts_spec.rb
|
462
466
|
- spec/acceptance/search_for_just_ids_spec.rb
|
463
467
|
- spec/acceptance/searching_across_models_spec.rb
|
468
|
+
- spec/acceptance/searching_across_schemas_spec.rb
|
464
469
|
- spec/acceptance/searching_on_fields_spec.rb
|
465
470
|
- spec/acceptance/searching_with_filters_spec.rb
|
466
471
|
- spec/acceptance/searching_with_sti_spec.rb
|
@@ -478,6 +483,7 @@ test_files:
|
|
478
483
|
- spec/internal/app/indices/admin_person_index.rb
|
479
484
|
- spec/internal/app/indices/animal_index.rb
|
480
485
|
- spec/internal/app/indices/article_index.rb
|
486
|
+
- spec/internal/app/indices/bird_index.rb
|
481
487
|
- spec/internal/app/indices/book_index.rb
|
482
488
|
- spec/internal/app/indices/car_index.rb
|
483
489
|
- spec/internal/app/indices/city_index.rb
|
@@ -510,6 +516,7 @@ test_files:
|
|
510
516
|
- spec/internal/db/schema.rb
|
511
517
|
- spec/internal/tmp/.gitkeep
|
512
518
|
- spec/spec_helper.rb
|
519
|
+
- spec/support/multi_schema.rb
|
513
520
|
- spec/support/sphinx_yaml_helpers.rb
|
514
521
|
- spec/thinking_sphinx/active_record/association_spec.rb
|
515
522
|
- spec/thinking_sphinx/active_record/attribute/type_spec.rb
|
@@ -523,7 +530,7 @@ test_files:
|
|
523
530
|
- spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb
|
524
531
|
- spec/thinking_sphinx/active_record/database_adapters_spec.rb
|
525
532
|
- spec/thinking_sphinx/active_record/field_spec.rb
|
526
|
-
- spec/thinking_sphinx/active_record/
|
533
|
+
- spec/thinking_sphinx/active_record/filter_reflection_spec.rb
|
527
534
|
- spec/thinking_sphinx/active_record/index_spec.rb
|
528
535
|
- spec/thinking_sphinx/active_record/interpreter_spec.rb
|
529
536
|
- spec/thinking_sphinx/active_record/polymorpher_spec.rb
|
@@ -1,75 +0,0 @@
|
|
1
|
-
class ThinkingSphinx::ActiveRecord::FilteredReflection <
|
2
|
-
ActiveRecord::Reflection::AssociationReflection
|
3
|
-
|
4
|
-
class Filter
|
5
|
-
attr_reader :reflection, :class_name
|
6
|
-
|
7
|
-
delegate :foreign_type, :active_record, :to => :reflection
|
8
|
-
|
9
|
-
def initialize(reflection, class_name)
|
10
|
-
@reflection, @class_name = reflection, class_name
|
11
|
-
@options = reflection.options.clone
|
12
|
-
end
|
13
|
-
|
14
|
-
def options
|
15
|
-
@options.delete :polymorphic
|
16
|
-
@options[:class_name] = class_name
|
17
|
-
@options[:foreign_key] ||= "#{reflection.name}_id"
|
18
|
-
@options[:foreign_type] = reflection.foreign_type
|
19
|
-
|
20
|
-
if reflection.respond_to?(:scope)
|
21
|
-
@options[:sphinx_internal_filtered] = true
|
22
|
-
return @options
|
23
|
-
end
|
24
|
-
|
25
|
-
case @options[:conditions]
|
26
|
-
when nil
|
27
|
-
@options[:conditions] = condition
|
28
|
-
when Array
|
29
|
-
@options[:conditions] << condition
|
30
|
-
when Hash
|
31
|
-
@options[:conditions].merge!(reflection.foreign_type => @options[:class_name])
|
32
|
-
else
|
33
|
-
@options[:conditions] << " AND #{condition}"
|
34
|
-
end
|
35
|
-
|
36
|
-
@options
|
37
|
-
end
|
38
|
-
|
39
|
-
def scope
|
40
|
-
if ::Joiner::Joins.instance_methods.include?(:join_association_class)
|
41
|
-
return nil
|
42
|
-
end
|
43
|
-
|
44
|
-
lambda { |association|
|
45
|
-
reflection = association.reflection
|
46
|
-
klass = reflection.class_name.constantize
|
47
|
-
where(
|
48
|
-
association.parent.aliased_table_name.to_sym =>
|
49
|
-
{reflection.foreign_type => klass.base_class.name}
|
50
|
-
)
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def condition
|
57
|
-
"::ts_join_alias::.#{quoted_foreign_type} = '#{class_name}'"
|
58
|
-
end
|
59
|
-
|
60
|
-
def quoted_foreign_type
|
61
|
-
active_record.connection.quote_column_name foreign_type
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.clone_with_filter(reflection, name, class_name)
|
66
|
-
filter = Filter.new(reflection, class_name)
|
67
|
-
|
68
|
-
if reflection.respond_to?(:scope)
|
69
|
-
new reflection.macro, name, filter.scope, filter.options,
|
70
|
-
reflection.active_record
|
71
|
-
else
|
72
|
-
new reflection.macro, name, filter.options, reflection.active_record
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ThinkingSphinx::ActiveRecord::FilteredReflection do
|
4
|
-
describe '.clone_with_filter' do
|
5
|
-
let(:reflection) { double('Reflection', :macro => :has_some,
|
6
|
-
:options => options, :active_record => double, :name => 'baz',
|
7
|
-
:foreign_type => :foo_type) }
|
8
|
-
let(:options) { {:polymorphic => true} }
|
9
|
-
let(:filtered_reflection) { double }
|
10
|
-
|
11
|
-
before :each do
|
12
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.stub(
|
13
|
-
:new => filtered_reflection
|
14
|
-
)
|
15
|
-
|
16
|
-
reflection.active_record.stub_chain(:connection, :quote_column_name).
|
17
|
-
and_return('"foo_type"')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "uses the existing reflection's macro" do
|
21
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new).
|
22
|
-
with(:has_some, anything, anything, anything)
|
23
|
-
|
24
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
25
|
-
reflection, 'foo_bar', 'Bar'
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "uses the supplied name" do
|
30
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new).
|
31
|
-
with(anything, 'foo_bar', anything, anything)
|
32
|
-
|
33
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
34
|
-
reflection, 'foo_bar', 'Bar'
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "uses the existing reflection's parent" do
|
39
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new).
|
40
|
-
with(anything, anything, anything, reflection.active_record)
|
41
|
-
|
42
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
43
|
-
reflection, 'foo_bar', 'Bar'
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "removes the polymorphic setting from the options" do
|
48
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
49
|
-
options[:polymorphic].should be_nil
|
50
|
-
end
|
51
|
-
|
52
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
53
|
-
reflection, 'foo_bar', 'Bar'
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "adds the class name option" do
|
58
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
59
|
-
options[:class_name].should == 'Bar'
|
60
|
-
end
|
61
|
-
|
62
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
63
|
-
reflection, 'foo_bar', 'Bar'
|
64
|
-
)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "sets the foreign key if necessary" do
|
68
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
69
|
-
options[:foreign_key].should == 'baz_id'
|
70
|
-
end
|
71
|
-
|
72
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
73
|
-
reflection, 'foo_bar', 'Bar'
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "respects supplied foreign keys" do
|
78
|
-
options[:foreign_key] = 'qux_id'
|
79
|
-
|
80
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
81
|
-
options[:foreign_key].should == 'qux_id'
|
82
|
-
end
|
83
|
-
|
84
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
85
|
-
reflection, 'foo_bar', 'Bar'
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "sets conditions if there are none" do
|
90
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
91
|
-
options[:conditions].should == "::ts_join_alias::.\"foo_type\" = 'Bar'"
|
92
|
-
end
|
93
|
-
|
94
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
95
|
-
reflection, 'foo_bar', 'Bar'
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "appends to the conditions array" do
|
100
|
-
options[:conditions] = ['existing']
|
101
|
-
|
102
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
103
|
-
options[:conditions].should == ['existing', "::ts_join_alias::.\"foo_type\" = 'Bar'"]
|
104
|
-
end
|
105
|
-
|
106
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
107
|
-
reflection, 'foo_bar', 'Bar'
|
108
|
-
)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "extends the conditions hash" do
|
112
|
-
options[:conditions] = {:x => :y}
|
113
|
-
|
114
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
115
|
-
options[:conditions].should == {:x => :y, :foo_type => 'Bar'}
|
116
|
-
end
|
117
|
-
|
118
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
119
|
-
reflection, 'foo_bar', 'Bar'
|
120
|
-
)
|
121
|
-
end
|
122
|
-
|
123
|
-
it "appends to the conditions string" do
|
124
|
-
options[:conditions] = 'existing'
|
125
|
-
|
126
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.should_receive(:new) do |macro, name, options, parent|
|
127
|
-
options[:conditions].should == "existing AND ::ts_join_alias::.\"foo_type\" = 'Bar'"
|
128
|
-
end
|
129
|
-
|
130
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
131
|
-
reflection, 'foo_bar', 'Bar'
|
132
|
-
)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "returns the new reflection" do
|
136
|
-
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
|
137
|
-
reflection, 'foo_bar', 'Bar'
|
138
|
-
).should == filtered_reflection
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|