thinking-sphinx 1.4.9 → 1.4.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.
data/README.textile CHANGED
@@ -202,3 +202,4 @@ Since I first released this library, there's been quite a few people who have su
202
202
  * Aaron Gibralter
203
203
  * Pete Deffendol
204
204
  * Tony Pitale
205
+ * Kenn Ejima
@@ -316,7 +316,7 @@ module ThinkingSphinx
316
316
  private
317
317
 
318
318
  def local_sphinx_indexes
319
- sphinx_indexes.select { |index|
319
+ (sphinx_indexes || []).select { |index|
320
320
  index.model == self
321
321
  }
322
322
  end
@@ -152,12 +152,12 @@ module ThinkingSphinx
152
152
  end
153
153
 
154
154
  def generate
155
- @configuration.indexes.clear
155
+ @configuration.indices.clear
156
156
 
157
157
  ThinkingSphinx.context.indexed_models.each do |model|
158
158
  model = model.constantize
159
159
  model.define_indexes
160
- @configuration.indexes.concat model.to_riddle
160
+ @configuration.indices.concat model.to_riddle
161
161
 
162
162
  enforce_common_attribute_types
163
163
  end
@@ -317,7 +317,7 @@ module ThinkingSphinx
317
317
  end
318
318
 
319
319
  def enforce_common_attribute_types
320
- sql_indexes = configuration.indexes.reject { |index|
320
+ sql_indexes = configuration.indices.reject { |index|
321
321
  index.is_a? Riddle::Configuration::DistributedIndex
322
322
  }
323
323
 
@@ -62,6 +62,9 @@ class ThinkingSphinx::Context
62
62
 
63
63
  begin
64
64
  camelized_model.constantize
65
+ rescue LoadError
66
+ # Make sure that STI subclasses in subfolders are loaded.
67
+ model_name.gsub!(/.*[\/\\]/, '').nil? ? next : retry
65
68
  rescue Exception => err
66
69
  STDERR.puts "Warning: Error loading #{file}:"
67
70
  STDERR.puts err.message
@@ -4,7 +4,7 @@ require 'thinking_sphinx/index/faux_column'
4
4
  module ThinkingSphinx
5
5
  class Index
6
6
  attr_accessor :name, :model, :sources, :delta_object
7
-
7
+
8
8
  # Create a new index instance by passing in the model it is tied to, and
9
9
  # a block to build it with (optional but recommended). For documentation
10
10
  # on the syntax for inside the block, the Builder class is what you want.
@@ -13,9 +13,9 @@ module ThinkingSphinx
13
13
  #
14
14
  # Index.new(User) do
15
15
  # indexes login, email
16
- #
16
+ #
17
17
  # has created_at
18
- #
18
+ #
19
19
  # set_property :delta => true
20
20
  # end
21
21
  #
@@ -26,46 +26,46 @@ module ThinkingSphinx
26
26
  @options = {}
27
27
  @delta_object = nil
28
28
  end
29
-
29
+
30
30
  def fields
31
31
  @sources.collect { |source| source.fields }.flatten
32
32
  end
33
-
33
+
34
34
  def attributes
35
35
  @sources.collect { |source| source.attributes }.flatten
36
36
  end
37
-
37
+
38
38
  def core_name
39
39
  "#{name}_core"
40
40
  end
41
-
41
+
42
42
  def delta_name
43
43
  "#{name}_delta"
44
44
  end
45
-
45
+
46
46
  def all_names
47
47
  names = [core_name]
48
48
  names << delta_name if delta?
49
-
49
+
50
50
  names
51
51
  end
52
-
52
+
53
53
  def self.name_for(model)
54
54
  model.name.underscore.tr(':/\\', '_')
55
55
  end
56
-
56
+
57
57
  def prefix_fields
58
58
  fields.select { |field| field.prefixes }
59
59
  end
60
-
60
+
61
61
  def infix_fields
62
62
  fields.select { |field| field.infixes }
63
63
  end
64
-
64
+
65
65
  def local_options
66
66
  @options
67
67
  end
68
-
68
+
69
69
  def options
70
70
  all_index_options = config.index_options.clone
71
71
  @options.keys.select { |key|
@@ -74,82 +74,82 @@ module ThinkingSphinx
74
74
  }.each { |key| all_index_options[key.to_sym] = @options[key] }
75
75
  all_index_options
76
76
  end
77
-
77
+
78
78
  def delta?
79
79
  !@delta_object.nil?
80
80
  end
81
-
81
+
82
82
  def to_riddle(offset)
83
83
  indexes = [to_riddle_for_core(offset)]
84
84
  indexes << to_riddle_for_delta(offset) if delta?
85
85
  indexes << to_riddle_for_distributed
86
86
  end
87
-
87
+
88
88
  private
89
-
89
+
90
90
  def adapter
91
91
  @adapter ||= @model.sphinx_database_adapter
92
92
  end
93
-
93
+
94
94
  def utf8?
95
95
  options[:charset_type] == "utf-8"
96
96
  end
97
-
97
+
98
98
  def sql_query_pre_for_delta
99
99
  [""]
100
100
  end
101
-
101
+
102
102
  def config
103
103
  @config ||= ThinkingSphinx::Configuration.instance
104
104
  end
105
-
105
+
106
106
  def to_riddle_for_core(offset)
107
107
  index = Riddle::Configuration::Index.new core_name
108
108
  index.path = File.join config.searchd_file_path, index.name
109
-
109
+
110
110
  set_configuration_options_for_indexes index
111
111
  set_field_settings_for_indexes index
112
-
112
+
113
113
  sources.each_with_index do |source, i|
114
114
  index.sources << source.to_riddle_for_core(offset, i)
115
115
  end
116
-
116
+
117
117
  index
118
118
  end
119
-
119
+
120
120
  def to_riddle_for_delta(offset)
121
121
  index = Riddle::Configuration::Index.new delta_name
122
122
  index.parent = core_name
123
123
  index.path = File.join config.searchd_file_path, index.name
124
-
124
+
125
125
  sources.each_with_index do |source, i|
126
126
  index.sources << source.to_riddle_for_delta(offset, i)
127
127
  end
128
-
128
+
129
129
  index
130
130
  end
131
-
131
+
132
132
  def to_riddle_for_distributed
133
133
  index = Riddle::Configuration::DistributedIndex.new name
134
- index.local_indexes << core_name
135
- index.local_indexes.unshift delta_name if delta?
134
+ index.local_indices << core_name
135
+ index.local_indices.unshift delta_name if delta?
136
136
  index
137
137
  end
138
-
138
+
139
139
  def set_configuration_options_for_indexes(index)
140
140
  config.index_options.each do |key, value|
141
141
  method = "#{key}=".to_sym
142
142
  index.send(method, value) if index.respond_to?(method)
143
143
  end
144
-
144
+
145
145
  options.each do |key, value|
146
146
  index.send("#{key}=".to_sym, value) if ThinkingSphinx::Configuration::IndexOptions.include?(key.to_s) && !value.nil?
147
147
  end
148
148
  end
149
-
149
+
150
150
  def set_field_settings_for_indexes(index)
151
151
  field_names = lambda { |field| field.unique_name.to_s }
152
-
152
+
153
153
  index.prefix_field_names += prefix_fields.collect(&field_names)
154
154
  index.infix_field_names += infix_fields.collect(&field_names)
155
155
  end
@@ -1,3 +1,3 @@
1
1
  module ThinkingSphinx
2
- Version = '1.4.9'
2
+ Version = '1.4.10'
3
3
  end
@@ -238,7 +238,7 @@ describe ThinkingSphinx::Configuration do
238
238
  config.reset
239
239
  config.generate
240
240
 
241
- config.configuration.indexes.each do |index|
241
+ config.configuration.indices.each do |index|
242
242
  next if index.is_a? Riddle::Configuration::DistributedIndex
243
243
 
244
244
  index.sources.each do |source|
@@ -41,10 +41,9 @@ describe ThinkingSphinx::Context do
41
41
  }.should_not raise_error
42
42
  end
43
43
 
44
- it "should report load errors but not raise them" do
44
+ it "should retry if the first load fails and contains a directory" do
45
+ model_name_lower.should_receive(:gsub!).twice.and_return(true, nil)
45
46
  class_name.stub(:constantize).and_raise(LoadError)
46
- STDERR.stub!(:puts => '')
47
- STDERR.should_receive(:puts).with('Warning: Error loading a.rb:')
48
47
 
49
48
  lambda {
50
49
  ts_context.prepare
@@ -4,179 +4,179 @@ describe ThinkingSphinx::Index do
4
4
  describe "prefix_fields method" do
5
5
  before :each do
6
6
  @index = ThinkingSphinx::Index.new(Person)
7
-
7
+
8
8
  @field_a = stub('field', :prefixes => true)
9
9
  @field_b = stub('field', :prefixes => false)
10
10
  @field_c = stub('field', :prefixes => true)
11
-
11
+
12
12
  @index.stub!(:fields => [@field_a, @field_b, @field_c])
13
13
  end
14
-
14
+
15
15
  it "should return fields that are flagged as prefixed" do
16
16
  @index.prefix_fields.should include(@field_a)
17
17
  @index.prefix_fields.should include(@field_c)
18
18
  end
19
-
19
+
20
20
  it "should not return fields that aren't flagged as prefixed" do
21
21
  @index.prefix_fields.should_not include(@field_b)
22
22
  end
23
23
  end
24
-
24
+
25
25
  describe "infix_fields method" do
26
26
  before :each do
27
27
  @index = ThinkingSphinx::Index.new(Person)
28
-
28
+
29
29
  @field_a = stub('field', :infixes => true)
30
30
  @field_b = stub('field', :infixes => false)
31
31
  @field_c = stub('field', :infixes => true)
32
-
32
+
33
33
  @index.stub!(:fields => [@field_a, @field_b, @field_c])
34
34
  end
35
-
35
+
36
36
  it "should return fields that are flagged as infixed" do
37
37
  @index.infix_fields.should include(@field_a)
38
38
  @index.infix_fields.should include(@field_c)
39
39
  end
40
-
40
+
41
41
  it "should not return fields that aren't flagged as infixed" do
42
42
  @index.infix_fields.should_not include(@field_b)
43
43
  end
44
44
  end
45
-
45
+
46
46
  describe '.name_for' do
47
47
  it "should return the model's name downcased" do
48
48
  ThinkingSphinx::Index.name_for(Alpha).should == 'alpha'
49
49
  end
50
-
50
+
51
51
  it "should separate words by underscores" do
52
52
  ThinkingSphinx::Index.name_for(ActiveRecord).should == 'active_record'
53
53
  end
54
-
54
+
55
55
  it "should separate namespaces by underscores" do
56
56
  ThinkingSphinx::Index.name_for(ActiveRecord::Base).
57
57
  should == 'active_record_base'
58
58
  end
59
59
  end
60
-
60
+
61
61
  describe '#name' do
62
62
  it "should return the downcased name of the index's model" do
63
63
  ThinkingSphinx::Index.new(Alpha).name.should == 'alpha'
64
64
  end
65
-
65
+
66
66
  it "should return a custom name if one is set" do
67
67
  index = ThinkingSphinx::Index.new(Alpha)
68
68
  index.name = 'custom'
69
69
  index.name.should == 'custom'
70
70
  end
71
71
  end
72
-
72
+
73
73
  describe '#core_name' do
74
74
  it "should take the index's name and append _core" do
75
75
  ThinkingSphinx::Index.new(Alpha).core_name.should == 'alpha_core'
76
76
  end
77
77
  end
78
-
78
+
79
79
  describe '#delta_name' do
80
80
  it "should take the index's name and append _delta" do
81
81
  ThinkingSphinx::Index.new(Alpha).delta_name.should == 'alpha_delta'
82
82
  end
83
83
  end
84
-
84
+
85
85
  describe '#all_names' do
86
86
  it "should return the core index name by default" do
87
87
  ThinkingSphinx::Index.new(Alpha).all_names.should == ['alpha_core']
88
88
  end
89
-
89
+
90
90
  it "should return both core and delta names if deltas are enabled" do
91
91
  index = ThinkingSphinx::Index.new(Alpha)
92
92
  index.delta_object = stub('delta')
93
-
93
+
94
94
  index.all_names.should == ['alpha_core', 'alpha_delta']
95
95
  end
96
-
96
+
97
97
  it "should respect custom names" do
98
98
  index = ThinkingSphinx::Index.new(Alpha)
99
99
  index.name = 'custom'
100
-
100
+
101
101
  index.all_names.should == ['custom_core']
102
102
  end
103
-
103
+
104
104
  it "should respect custom names when deltas are enabled" do
105
105
  index = ThinkingSphinx::Index.new(Alpha)
106
106
  index.name = 'custom'
107
107
  index.delta_object = stub('delta')
108
-
108
+
109
109
  index.all_names.should == ['custom_core', 'custom_delta']
110
110
  end
111
111
  end
112
-
112
+
113
113
  describe '#to_riddle' do
114
114
  it "should return two Riddle indexes if deltas are disabled" do
115
115
  index = ThinkingSphinx::Index.new(Alpha)
116
-
116
+
117
117
  index.to_riddle(0).length.should == 2
118
118
  end
119
-
119
+
120
120
  it "should return three Riddle indexes if deltas are enabled" do
121
121
  index = ThinkingSphinx::Index.new(Beta)
122
122
  index.delta_object = stub('delta')
123
-
123
+
124
124
  index.to_riddle(0).length.should == 3
125
125
  end
126
-
126
+
127
127
  it "should include a distributed index" do
128
128
  index = ThinkingSphinx::Index.new(Alpha)
129
-
129
+
130
130
  index.to_riddle(0).last.
131
131
  should be_a(Riddle::Configuration::DistributedIndex)
132
132
  end
133
-
133
+
134
134
  context 'core index' do
135
135
  it "should use the core name" do
136
136
  @index = ThinkingSphinx::Index.new(Alpha).to_riddle(0).first
137
137
  @index.name.should == 'alpha_core'
138
138
  end
139
-
139
+
140
140
  it "should not try to set disable_range on the index" do
141
141
  ThinkingSphinx::Configuration.instance.
142
142
  index_options[:disable_range] = true
143
-
143
+
144
144
  lambda {
145
145
  @index = ThinkingSphinx::Index.new(Alpha).to_riddle(0).first
146
146
  }.should_not raise_error(NoMethodError)
147
147
  end
148
148
  end
149
-
149
+
150
150
  context 'delta index' do
151
151
  before :each do
152
152
  index = ThinkingSphinx::Index.new(Beta)
153
153
  index.delta_object = stub('delta')
154
154
  @index = index.to_riddle(0)[1]
155
155
  end
156
-
156
+
157
157
  it "should use the delta name" do
158
158
  @index.name.should == 'beta_delta'
159
159
  end
160
160
  end
161
-
161
+
162
162
  context 'distributed index' do
163
163
  it "should use the index's name" do
164
164
  index = ThinkingSphinx::Index.new(Alpha)
165
165
 
166
166
  index.to_riddle(0).last.name.should == 'alpha'
167
167
  end
168
-
168
+
169
169
  it "should add the core index" do
170
170
  index = ThinkingSphinx::Index.new(Alpha)
171
171
 
172
- index.to_riddle(0).last.local_indexes.should include('alpha_core')
172
+ index.to_riddle(0).last.local_indices.should include('alpha_core')
173
173
  end
174
-
174
+
175
175
  it "should add the delta index if there is one" do
176
176
  index = ThinkingSphinx::Index.new(Beta)
177
177
  index.delta_object = stub('delta')
178
178
 
179
- index.to_riddle(0).last.local_indexes.should include('beta_delta')
179
+ index.to_riddle(0).last.local_indices.should include('beta_delta')
180
180
  end
181
181
  end
182
182
  end
@@ -148,7 +148,7 @@ describe ThinkingSphinx::Search do
148
148
  @results = [] # to confirm same object
149
149
  ThinkingSphinx.stub!(:search => @results)
150
150
 
151
- ThinkingSphinx::Search.search.object_id.should == @results.object_id
151
+ ThinkingSphinx.search.object_id.should == @results.object_id
152
152
  end
153
153
  end
154
154
 
@@ -157,7 +157,7 @@ describe ThinkingSphinx::Search do
157
157
  @results = [] # to confirm same object
158
158
  ThinkingSphinx.stub!(:search_for_ids => @results)
159
159
 
160
- ThinkingSphinx::Search.search_for_ids.object_id.
160
+ ThinkingSphinx.search_for_ids.object_id.
161
161
  should == @results.object_id
162
162
  end
163
163
  end
@@ -167,7 +167,7 @@ describe ThinkingSphinx::Search do
167
167
  @results = [] # to confirm same object
168
168
  ThinkingSphinx.stub!(:search_for_id => @results)
169
169
 
170
- ThinkingSphinx::Search.search_for_id.object_id.
170
+ ThinkingSphinx.search_for_id.object_id.
171
171
  should == @results.object_id
172
172
  end
173
173
  end
@@ -177,7 +177,7 @@ describe ThinkingSphinx::Search do
177
177
  @results = [] # to confirm same object
178
178
  ThinkingSphinx.stub!(:count => @results)
179
179
 
180
- ThinkingSphinx::Search.count.object_id.should == @results.object_id
180
+ ThinkingSphinx.count.object_id.should == @results.object_id
181
181
  end
182
182
  end
183
183
 
@@ -186,7 +186,7 @@ describe ThinkingSphinx::Search do
186
186
  @results = [] # to confirm same object
187
187
  ThinkingSphinx.stub!(:facets => @results)
188
188
 
189
- ThinkingSphinx::Search.facets.object_id.should == @results.object_id
189
+ ThinkingSphinx.facets.object_id.should == @results.object_id
190
190
  end
191
191
  end
192
192
 
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 9
10
- version: 1.4.9
9
+ - 10
10
+ version: 1.4.10
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-10-10 00:00:00 +11:00
18
+ date: 2011-11-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,12 +65,12 @@ dependencies:
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- hash: 29
68
+ hash: 3
69
69
  segments:
70
70
  - 1
71
- - 3
72
- - 3
73
- version: 1.3.3
71
+ - 5
72
+ - 0
73
+ version: 1.5.0
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  requirement: *id003