thinking-sphinx 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +5 -2
  3. data/Appraisals +4 -0
  4. data/Gemfile +1 -1
  5. data/HISTORY +18 -0
  6. data/README.textile +7 -7
  7. data/gemfiles/rails_3_1.gemfile +1 -1
  8. data/gemfiles/rails_3_2.gemfile +1 -1
  9. data/gemfiles/rails_4_0.gemfile +11 -0
  10. data/lib/thinking_sphinx.rb +1 -0
  11. data/lib/thinking_sphinx/active_record/associations.rb +8 -1
  12. data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +4 -0
  13. data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +4 -0
  14. data/lib/thinking_sphinx/active_record/filtered_reflection.rb +32 -14
  15. data/lib/thinking_sphinx/active_record/sql_builder.rb +4 -4
  16. data/lib/thinking_sphinx/active_record/sql_source.rb +3 -1
  17. data/lib/thinking_sphinx/active_record/sql_source/template.rb +5 -1
  18. data/lib/thinking_sphinx/capistrano.rb +6 -7
  19. data/lib/thinking_sphinx/configuration.rb +56 -33
  20. data/lib/thinking_sphinx/core/index.rb +1 -1
  21. data/lib/thinking_sphinx/errors.rb +2 -0
  22. data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +4 -0
  23. data/lib/thinking_sphinx/masks/pagination_mask.rb +4 -0
  24. data/lib/thinking_sphinx/masks/scopes_mask.rb +2 -2
  25. data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +4 -0
  26. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +4 -3
  27. data/lib/thinking_sphinx/middlewares/sphinxql.rb +15 -3
  28. data/lib/thinking_sphinx/railtie.rb +13 -0
  29. data/lib/thinking_sphinx/search.rb +3 -2
  30. data/lib/thinking_sphinx/search/query.rb +4 -0
  31. data/spec/acceptance/specifying_sql_spec.rb +4 -4
  32. data/spec/internal/app/models/tweet.rb +1 -1
  33. data/spec/thinking_sphinx/active_record/associations_spec.rb +49 -4
  34. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +3 -3
  35. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +14 -1
  36. data/spec/thinking_sphinx/configuration_spec.rb +25 -1
  37. data/spec/thinking_sphinx/connection_spec.rb +4 -4
  38. data/spec/thinking_sphinx/errors_spec.rb +7 -0
  39. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +3 -3
  40. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +35 -4
  41. data/spec/thinking_sphinx/search/query_spec.rb +20 -0
  42. data/spec/thinking_sphinx/search_spec.rb +5 -0
  43. data/thinking-sphinx.gemspec +3 -3
  44. metadata +22 -48
  45. data/lib/thinking_sphinx/search/translator.rb +0 -50
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2825535169716d44b3c2a897d70bdd6c44638b17
4
+ data.tar.gz: 30d74a154abf22f00795be4eaae8cb69e16fff19
5
+ SHA512:
6
+ metadata.gz: 4f33cf2627e2944ecee27c689a60770a201a4eb54de9fd97354b3eec27cd07d0d847d79a003b4df8e188f5dc3ecdf2a36ac7003cb8cb63f158f4486f3f75f1cc
7
+ data.tar.gz: a66b7764fcb538650f61931d4a5bddaf9d708098db223606a120f503a1eecbbe533e6b048b942a10fe157b8a11b593b0ff4e27a80e7934378597cfe2f6fd284a
@@ -1,10 +1,12 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.9.2
3
4
  - 1.9.3
5
+ - 2.0.0
4
6
  before_install:
5
7
  - gem update --system
6
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.6_i386_12.04.deb
7
- - sudo dpkg -i fs-sphinx-2.0.6_i386_12.04.deb
8
+ - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.6_x86_64_12.04.deb
9
+ - sudo dpkg -i fs-sphinx-2.0.6_x86_64_12.04.deb
8
10
  before_script:
9
11
  - "mysql -e 'create database thinking_sphinx;' > /dev/null"
10
12
  - "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null"
@@ -14,3 +16,4 @@ env:
14
16
  gemfile:
15
17
  - gemfiles/rails_3_1.gemfile
16
18
  - gemfiles/rails_3_2.gemfile
19
+ - gemfiles/rails_4_0.gemfile
data/Appraisals CHANGED
@@ -5,3 +5,7 @@ end
5
5
  appraise 'rails_3_2' do
6
6
  gem 'rails', '~> 3.2.0'
7
7
  end
8
+
9
+ appraise 'rails_4_0' do
10
+ gem 'rails', '~> 4.0.0.beta1'
11
+ end
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
data/HISTORY CHANGED
@@ -1,3 +1,21 @@
1
+ 2013-03-23: 3.0.2
2
+ * [CHANGE] per_page now accepts an optional paging limit, to match WillPaginate's behaviour. If none is supplied, it just returns the page size.
3
+ * [FEATURE] Ruby 2.0 support.
4
+ * [FEATURE] Rails 4.0.0 beta1 support.
5
+ * [FIX] :utf8? option within index definitions is now supported, and defaults to true if the database configuration's encoding is set to 'utf8'.
6
+ * [FIX] indices_location and configuration_file values in thinking_sphinx.yml will be applied to the configuration.
7
+ * [CHANGE] Strings and regular expressions in ThinkingSphinx::Search::Query are now treated as UTF-8.
8
+ * [FIX] Primary keys that are not 'id' now work correctly.
9
+ * [CHANGE] Setting a custom framework will rebuild the core configuration around its provided settings (path and environment).
10
+ * [CHANGE] Search masks don't rely on respond_to?, and so Object/Kernel methods are passed through to the underlying array instead.
11
+ * [FIX] Search options specified in index definitions and thinking_sphinx.yml are now used in search requests (eg: max_matches, field_weights).
12
+ * [FEATURE] Indexes defined in app/indices in engines are now loaded (Antonio Tapiador del Dujo).
13
+ * [FIX] Custom association conditions are no longer presumed to be an array.
14
+ * [CHANGE] Empty search conditions are now ignored, instead of being appended with no value (Nicholas Klick).
15
+ * [CHANGE] Custom conditions are no longer added to the sql_query_range value, as they may involve associations.
16
+ * [FIX] Capistrano tasks use the correct ts rake task prefix (David Celis).
17
+ * [FEATURE] Query errors are classified as such, instead of getting the base SphinxError.
18
+
1
19
  2013-02-04: 3.0.1
2
20
  * [FEATURE] Provide Capistrano deployment tasks (David Celis).
3
21
  * [FEATURE] Allow specifying of Sphinx version. Is only useful for Flying Sphinx purposes at this point - has no impact on Riddle or Sphinx.
@@ -28,7 +28,7 @@ ThinkingSphinx::Index.define :article, :with => :active_record do
28
28
  has published
29
29
  end</code></pre>
30
30
 
31
- You'll notice the first argument is the model name downcased and as a symbol, and we are specifying the processor - @:active_record@. Everything inside the block is just like previous versions of Thinking Sphinx. Same goes for @config/thinking_sphinx.yml@ (formerly @config/sphinx.yml@).
31
+ You'll notice the first argument is the model name downcased and as a symbol, and we are specifying the processor - @:active_record@. Everything inside the block is just like previous versions of Thinking Sphinx. Same goes for most settings in @config/thinking_sphinx.yml@ (formerly @config/sphinx.yml@) unless noted below.
32
32
 
33
33
  When you're defining indices for namespaced models, use a lowercase string with /'s for namespacing as the model reference:
34
34
 
@@ -37,6 +37,8 @@ ThinkingSphinx::Index.define 'blog/article', :with => :active_record</code></pre
37
37
 
38
38
  Other changes:
39
39
  * SphinxQL is now used instead of the old socket connections (hence the dependency on the @mysql2@ gem).
40
+ * Specifying a different port for Sphinx to use (in @config/thinking_sphinx.yml@) should be done with the mysql41 setting, not the port setting.
41
+ * The searchd_log and searchd_query_log settings are now log and query_log (matching their Sphinx names).
40
42
  * You'll need to include @ThinkingSphinx::Scopes@ into your models if you want to use Sphinx scopes. Default scopes can be set as follows:
41
43
 
42
44
  <pre><code>class Person < ActiveRecord::Base
@@ -193,12 +195,10 @@ h2. Deployment with Capistrano
193
195
 
194
196
  Thinking Sphinx comes with several Capistrano tasks to help ease deployment of your applications. Just require the recipes:
195
197
 
196
- ```ruby
197
- # config/deploy.rb
198
- require 'thinking_sphinx/capistrano'
199
- ```
198
+ <pre><code># config/deploy.rb
199
+ require 'thinking_sphinx/capistrano'</code></pre>
200
200
 
201
- When running `cap deploy:setup` to get your server ready for deployments, Thinking Sphinx will also set up a shared folder for your indexes. Before finalizing a deployment, these indexes will be symlinked into the release path for use. When you deploy your application for the first time using `cap deploy:cold`, your indexes will be built for you and the search daemon will be started. Run `cap -T` to see all of the deployment tasks.
201
+ When running @cap deploy:setup@ to get your server ready for deployments, Thinking Sphinx will also set up a shared folder for your indexes. Before finalizing a deployment, these indexes will be symlinked into the release path for use. When you deploy your application for the first time using @cap deploy:cold@, your indexes will be built for you and the search daemon will be started. Run @cap -T@ to see all of the deployment tasks.
202
202
 
203
203
  h2. Limitations
204
204
 
@@ -226,7 +226,7 @@ h3. Ruby Versions
226
226
 
227
227
  Built on MRI 1.9.3 and tested against MRI 1.9.2 as well. No plans to support MRI 1.8, but would like to support Rubinius and JRuby (the one catch with the latter is the different MySQL interfaces).
228
228
 
229
- There's also the complication that Sphinx 2.0.x releases don't work with JDBC (as JDBC sends several MySQL-specific comamnds through when initializing a connection). So, JRuby support won't appear until there's a stable Sphinx release that can interact with JDBC.
229
+ There's also the complication that Sphinx 2.0.x releases don't work with JDBC (as JDBC sends several MySQL-specific commands through when initializing a connection). So, JRuby support won't appear until there's a stable Sphinx release that can interact with JDBC.
230
230
 
231
231
  h3. Database Versions
232
232
 
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
6
  gem "pg", "~> 0.11.0", :platform=>:ruby
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
6
  gem "pg", "~> 0.11.0", :platform=>:ruby
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
+ gem "pg", "~> 0.11.0", :platform=>:ruby
7
+ gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
+ gem "rails", "~> 4.0.0.beta1"
10
+
11
+ gemspec :path=>"../"
@@ -9,6 +9,7 @@ require 'riddle'
9
9
  require 'middleware'
10
10
  require 'active_record'
11
11
  require 'innertube'
12
+ require 'active_support/core_ext/module/delegation'
12
13
 
13
14
  module ThinkingSphinx
14
15
  def self.count(query = '', options = {})
@@ -79,8 +79,15 @@ class ThinkingSphinx::ActiveRecord::Associations
79
79
  end
80
80
 
81
81
  def rewrite_conditions_for(join)
82
- conditions = Array(join.conditions).flatten
82
+ if join.respond_to?(:scope_chain)
83
+ conditions = Array(join.scope_chain).flatten
84
+ else
85
+ conditions = Array(join.conditions).flatten
86
+ end
87
+
83
88
  conditions.each do |condition|
89
+ next unless condition.is_a?(String)
90
+
84
91
  condition.gsub! /::ts_join_alias::/,
85
92
  model.connection.quote_table_name(join.parent.aliased_table_name)
86
93
  end
@@ -10,4 +10,8 @@ class ThinkingSphinx::ActiveRecord::DatabaseAdapters::AbstractAdapter
10
10
  def quoted_table_name
11
11
  @model.quoted_table_name
12
12
  end
13
+
14
+ def utf8_query_pre
15
+ []
16
+ end
13
17
  end
@@ -20,4 +20,8 @@ class ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter <
20
20
  def group_concatenate(clause, separator = ' ')
21
21
  "GROUP_CONCAT(#{clause} SEPARATOR '#{separator}')"
22
22
  end
23
+
24
+ def utf8_query_pre
25
+ ['SET NAMES utf8']
26
+ end
23
27
  end
@@ -1,8 +1,8 @@
1
1
  class ThinkingSphinx::ActiveRecord::FilteredReflection <
2
2
  ActiveRecord::Reflection::AssociationReflection
3
3
 
4
- class Options
5
- attr_reader :reflection, :class_name, :options
4
+ class Filter
5
+ attr_reader :reflection, :class_name
6
6
 
7
7
  delegate :foreign_type, :active_record, :to => :reflection
8
8
 
@@ -11,23 +11,36 @@ class ThinkingSphinx::ActiveRecord::FilteredReflection <
11
11
  @options = reflection.options.clone
12
12
  end
13
13
 
14
- def filtered
15
- options.delete :polymorphic
16
- options[:class_name] = class_name
17
- options[:foreign_key] ||= "#{reflection.name}_id"
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
18
19
 
19
- case options[:conditions]
20
+ return @options if reflection.respond_to?(:scope)
21
+
22
+ case @options[:conditions]
20
23
  when nil
21
- options[:conditions] = condition
24
+ @options[:conditions] = condition
22
25
  when Array
23
- options[:conditions] << condition
26
+ @options[:conditions] << condition
24
27
  when Hash
25
- options[:conditions].merge!(reflection.foreign_type => options[:class_name])
28
+ @options[:conditions].merge!(reflection.foreign_type => @options[:class_name])
26
29
  else
27
- options[:conditions] << " AND #{condition}"
30
+ @options[:conditions] << " AND #{condition}"
28
31
  end
29
32
 
30
- options
33
+ @options
34
+ end
35
+
36
+ def scope
37
+ lambda { |association|
38
+ reflection = association.reflection
39
+ where(
40
+ association.parent.aliased_table_name.to_sym =>
41
+ {reflection.foreign_type => reflection.class_name}
42
+ )
43
+ }
31
44
  end
32
45
 
33
46
  private
@@ -42,8 +55,13 @@ class ThinkingSphinx::ActiveRecord::FilteredReflection <
42
55
  end
43
56
 
44
57
  def self.clone_with_filter(reflection, name, class_name)
45
- options = Options.new(reflection, class_name).filtered
58
+ filter = Filter.new(reflection, class_name)
46
59
 
47
- new reflection.macro, name, options, reflection.active_record
60
+ if reflection.respond_to?(:scope)
61
+ new reflection.macro, name, filter.scope, filter.options,
62
+ reflection.active_record
63
+ else
64
+ new reflection.macro, name, filter.options, reflection.active_record
65
+ end
48
66
  end
49
67
  end
@@ -43,7 +43,7 @@ class ThinkingSphinx::ActiveRecord::SQLBuilder
43
43
 
44
44
  queries << delta_processor.reset_query if reset_delta
45
45
  queries << "SET SESSION group_concat_max_len = #{max_len}" if max_len
46
- queries << source.adapter.utf8_query_pre if source.options[:utf8?]
46
+ queries += source.adapter.utf8_query_pre if source.options[:utf8?]
47
47
 
48
48
  queries.compact
49
49
  end
@@ -129,10 +129,10 @@ class ThinkingSphinx::ActiveRecord::SQLBuilder
129
129
  ).compact.join(', ')
130
130
  end
131
131
 
132
- def where_clause(without_range = false)
132
+ def where_clause(for_range = false)
133
133
  logic = []
134
134
 
135
- unless without_range || source.disable_range?
135
+ unless for_range || source.disable_range?
136
136
  logic << "#{quoted_primary_key} >= $start"
137
137
  logic << "#{quoted_primary_key} <= $end"
138
138
  end
@@ -143,7 +143,7 @@ class ThinkingSphinx::ActiveRecord::SQLBuilder
143
143
  end
144
144
 
145
145
  logic << delta_processor.clause(source.delta?) if delta_processor
146
- logic += source.conditions
146
+ logic += source.conditions unless for_range
147
147
 
148
148
  logic.compact.join(' AND ')
149
149
  end
@@ -9,7 +9,9 @@ class ThinkingSphinx::ActiveRecord::SQLSource < Riddle::Configuration::SQLSource
9
9
  def initialize(model, options = {})
10
10
  @model = model
11
11
  @database_settings = model.connection.instance_variable_get(:@config).clone
12
- @options = options
12
+ @options = {
13
+ :utf8? => (@database_settings[:encoding] == 'utf8')
14
+ }.merge options
13
15
 
14
16
  @fields = []
15
17
  @attributes = []
@@ -8,7 +8,7 @@ class ThinkingSphinx::ActiveRecord::SQLSource::Template
8
8
  def apply
9
9
  add_field class_column, :sphinx_internal_class_name
10
10
 
11
- add_attribute :id, :sphinx_internal_id, nil
11
+ add_attribute primary_key, :sphinx_internal_id, nil
12
12
  add_attribute class_column, :sphinx_internal_class, :string, :facet => true
13
13
  add_attribute '0', :sphinx_deleted, :integer
14
14
  end
@@ -46,4 +46,8 @@ class ThinkingSphinx::ActiveRecord::SQLSource::Template
46
46
  def model
47
47
  source.model
48
48
  end
49
+
50
+ def primary_key
51
+ source.model.primary_key.to_sym
52
+ end
49
53
  end
@@ -2,29 +2,29 @@ Capistrano::Configuration.instance(:must_exist).load do
2
2
  namespace :thinking_sphinx do
3
3
  desc 'Generate the Sphinx configuration file.'
4
4
  task :configure do
5
- rake 'thinking_sphinx:configure'
5
+ rake 'ts:configure'
6
6
  end
7
7
 
8
8
  desc 'Build Sphinx indexes into the shared path and symlink them into your release.'
9
9
  task :index do
10
- rake 'thinking_sphinx:index'
10
+ rake 'ts:index'
11
11
  end
12
12
  after 'thinking_sphinx:index', 'thinking_sphinx:symlink_indexes'
13
13
 
14
14
  desc 'Start the Sphinx search daemon.'
15
15
  task :start do
16
- rake 'thinking_sphinx:start'
16
+ rake 'ts:start'
17
17
  end
18
18
  before 'thinking_sphinx:start', 'thinking_sphinx:configure'
19
19
 
20
20
  desc 'Stop the Sphinx search daemon.'
21
21
  task :stop do
22
- rake 'thinking_sphinx:stop'
22
+ rake 'ts:stop'
23
23
  end
24
24
 
25
25
  desc 'Restart the Sphinx search daemon.'
26
26
  task :restart do
27
- rake 'thinking_sphinx:stop thinking_sphinx:configure thinking_sphinx:start'
27
+ rake 'ts:stop ts:configure ts:start'
28
28
  end
29
29
 
30
30
  desc <<-DESC
@@ -32,10 +32,9 @@ Stop, reindex, and then start the Sphinx search daemon. This task must be execut
32
32
  if you alter the structure of your indexes.
33
33
  DESC
34
34
  task :rebuild do
35
- rake 'thinking_sphinx:stop thinking_sphinx:reindex'
35
+ rake 'ts:rebuild'
36
36
  end
37
37
  after 'thinking_sphinx:rebuild', 'thinking_sphinx:symlink_indexes'
38
- after 'thinking_sphinx:rebuild', 'thinking_sphinx:start'
39
38
 
40
39
  desc 'Create the shared folder for sphinx indexes.'
41
40
  task :shared_sphinx_folder do
@@ -1,42 +1,14 @@
1
1
  class ThinkingSphinx::Configuration < Riddle::Configuration
2
2
  attr_accessor :configuration_file, :indices_location, :version
3
3
  attr_reader :index_paths
4
- attr_writer :controller, :framework
4
+ attr_writer :controller
5
+
6
+ delegate :environment, :to => :framework
5
7
 
6
8
  def initialize
7
9
  super
8
10
 
9
- @configuration_file = File.join framework.root, 'config',
10
- "#{framework.environment}.sphinx.conf"
11
- @index_paths = [File.join(framework.root, 'app', 'indices')]
12
- @indices_location = File.join framework.root, 'db', 'sphinx',
13
- framework.environment
14
- @version = settings['version'] || '2.0.6'
15
-
16
- searchd.pid_file = File.join framework.root, 'log',
17
- "#{framework.environment}.sphinx.pid"
18
- searchd.log = File.join framework.root, 'log',
19
- "#{framework.environment}.searchd.log"
20
- searchd.query_log = File.join framework.root, 'log',
21
- "#{framework.environment}.searchd.query.log"
22
- searchd.binlog_path = File.join framework.root, 'tmp', 'binlog',
23
- framework.environment
24
-
25
- searchd.address = settings['address']
26
- searchd.address = Defaults::ADDRESS unless searchd.address.present?
27
- searchd.mysql41 = settings['mysql41'] || settings['port'] ||
28
- Defaults::PORT
29
- searchd.workers = 'threads'
30
-
31
- [indexer, searchd].each do |object|
32
- settings.each do |key, value|
33
- next unless object.class.settings.include?(key.to_sym)
34
-
35
- object.send("#{key}=", value)
36
- end
37
- end
38
-
39
- @offsets = {}
11
+ setup
40
12
  end
41
13
 
42
14
  def self.instance
@@ -61,6 +33,22 @@ class ThinkingSphinx::Configuration < Riddle::Configuration
61
33
  @framework ||= ThinkingSphinx::Frameworks.current
62
34
  end
63
35
 
36
+ def framework=(framework)
37
+ @framework = framework
38
+ setup
39
+ framework
40
+ end
41
+
42
+ def engine_index_paths
43
+ return [] unless defined?(Rails)
44
+
45
+ Rails::Engine::Railties.engines.select { |engine|
46
+ engine.paths['app/indices']
47
+ }.collect { |engine|
48
+ engine.paths['app/indices'].existent
49
+ }.flatten
50
+ end
51
+
64
52
  def indices_for_references(*references)
65
53
  preload_indices
66
54
  indices.select { |index| references.include?(index.reference) }
@@ -104,12 +92,47 @@ class ThinkingSphinx::Configuration < Riddle::Configuration
104
92
 
105
93
  def settings_to_hash
106
94
  contents = YAML.load(ERB.new(File.read(settings_file)).result)
107
- contents && contents[framework.environment] || {}
95
+ contents && contents[environment] || {}
108
96
  end
109
97
 
110
98
  def settings_file
111
99
  File.join framework.root, 'config', 'thinking_sphinx.yml'
112
100
  end
101
+
102
+ def setup
103
+ @configuration_file = settings['configuration_file'] ||
104
+ File.join(framework.root, 'config', "#{environment}.sphinx.conf")
105
+ @index_paths = engine_index_paths +
106
+ [File.join(framework.root, 'app', 'indices')]
107
+ @indices_location = settings['indices_location'] ||
108
+ File.join(framework.root, 'db', 'sphinx', environment)
109
+ @version = settings['version'] || '2.0.6'
110
+
111
+ searchd.pid_file = File.join framework.root, 'log',
112
+ "#{environment}.sphinx.pid"
113
+ searchd.log = File.join framework.root, 'log',
114
+ "#{environment}.searchd.log"
115
+ searchd.query_log = File.join framework.root, 'log',
116
+ "#{environment}.searchd.query.log"
117
+ searchd.binlog_path = File.join framework.root, 'tmp', 'binlog',
118
+ environment
119
+
120
+ searchd.address = settings['address']
121
+ searchd.address = Defaults::ADDRESS unless searchd.address.present?
122
+ searchd.mysql41 = settings['mysql41'] || settings['port'] ||
123
+ Defaults::PORT
124
+ searchd.workers = 'threads'
125
+
126
+ [indexer, searchd].each do |object|
127
+ settings.each do |key, value|
128
+ next unless object.class.settings.include?(key.to_sym)
129
+
130
+ object.send("#{key}=", value)
131
+ end
132
+ end
133
+
134
+ @offsets = {}
135
+ end
113
136
  end
114
137
 
115
138
  require 'thinking_sphinx/configuration/consistent_ids'