<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,9 +2,9 @@ require 'thinking_sphinx'
 require 'action_controller/dispatcher'
 
 if Rails::VERSION::STRING.to_f &lt; 2.1
-  ThinkingSphinx::Configuration.new.load_models
+  ThinkingSphinx::Configuration.instance.load_models
 end
 
 ActionController::Dispatcher.to_prepare :thinking_sphinx do
-  ThinkingSphinx::Configuration.new.load_models
+  ThinkingSphinx::Configuration.instance.load_models
 end
\ No newline at end of file</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -127,7 +127,7 @@ module ThinkingSphinx
     def toggle_deleted
       return unless ThinkingSphinx.updates_enabled?
       
-      config = ThinkingSphinx::Configuration.new
+      config = ThinkingSphinx::Configuration.instance
       client = Riddle::Client.new config.address, config.port
       
       client.update(</diff>
      <filename>lib/thinking_sphinx/active_record.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,10 +44,10 @@ module ThinkingSphinx
             def index_delta(instance = nil)
               return true unless ThinkingSphinx.updates_enabled? &amp;&amp;
                 ThinkingSphinx.deltas_enabled?
-
-              config = ThinkingSphinx::Configuration.new
+              
+              config = ThinkingSphinx::Configuration.instance
               client = Riddle::Client.new config.address, config.port
-
+              
               client.update(
                 &quot;#{self.sphinx_indexes.first.name}_core&quot;,
                 ['sphinx_deleted'],</diff>
      <filename>lib/thinking_sphinx/active_record/delta.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require 'erb'
+require 'singleton'
 
 module ThinkingSphinx
   # This class both keeps track of the configuration settings for Sphinx and
@@ -41,11 +42,28 @@ module ThinkingSphinx
   # don't set allow_star to true.
   # 
   class Configuration
+    include Singleton
+    
+    SourceOptions = %w( mysql_connect_flags sql_range_step sql_query_pre
+      sql_query_post sql_ranged_throttle sql_query_post_index )
+    
+    IndexOptions  = %w( charset_table charset_type docinfo enable_star
+      exceptions html_index_attrs html_remove_elements html_strip ignore_chars
+      min_infix_len min_prefix_len min_word_len mlock morphology ngram_chars
+      ngram_len phrase_boundary phrase_boundary_step preopen stopwords
+      wordforms )
+    
+    IndexerOptions = %w( max_iops max_iosize mem_limit )
+    
+    SearchdOptions = %w( read_timeout max_children max_matches seamless_rotate
+      preopen_indexes unlink_old )
+    
     attr_accessor :config_file, :searchd_log_file, :query_log_file,
-      :pid_file, :searchd_file_path, :address, :port, :enable_star,
-      :allow_star, :min_prefix_len, :min_infix_len, :mem_limit, :max_matches,
-      :morphology, :charset_type, :charset_table, :ignore_chars, :html_strip,
-      :html_remove_elements, :database_yml_file, :app_root, :bin_path
+      :pid_file, :searchd_file_path, :address, :port, :allow_star,
+      :database_yml_file, :app_root, :bin_path
+    
+    attr_accessor :source_options, :index_options, :indexer_options,
+      :searchd_options
     
     attr_reader :environment
     
@@ -53,6 +71,10 @@ module ThinkingSphinx
     # and parse it according to the current environment.
     # 
     def initialize(app_root = Dir.pwd)
+      self.reset
+    end
+    
+    def reset
       self.app_root          = RAILS_ROOT if defined?(RAILS_ROOT)
       self.app_root          = Merb.root  if defined?(Merb)
       self.app_root        ||= app_root
@@ -66,22 +88,27 @@ module ThinkingSphinx
       self.address              = &quot;127.0.0.1&quot;
       self.port                 = 3312
       self.allow_star           = false
-      self.enable_star          = false
-      self.min_prefix_len       = nil
-      self.min_infix_len        = nil
-      self.mem_limit            = &quot;64M&quot;
-      self.max_matches          = 1000
-      self.morphology           = &quot;stem_en&quot;
-      self.charset_type         = &quot;utf-8&quot;
-      self.charset_table        = nil
-      self.ignore_chars         = nil
-      self.html_strip           = false
-      self.html_remove_elements = &quot;&quot;
+      # self.enable_star          = false
+      # self.min_prefix_len       = nil
+      # self.min_infix_len        = nil
+      # self.mem_limit            = &quot;64M&quot;
+      # self.max_matches          = 1000
+      # self.morphology           = &quot;stem_en&quot;
+      # self.charset_type         = &quot;utf-8&quot;
+      # self.charset_table        = nil
+      # self.ignore_chars         = nil
+      # self.html_strip           = false
+      # self.html_remove_elements = &quot;&quot;
       self.bin_path             = &quot;&quot;
       
+      self.source_options  = {}
+      self.index_options   = {}
+      self.indexer_options = {}
+      self.searchd_options = {}
+      
       parse_config
       
-      self.bin_path += '/' unless self.bin_path.blank?
+      self
     end
     
     def self.environment
@@ -110,7 +137,7 @@ module ThinkingSphinx
         file.write &lt;&lt;-CONFIG
 indexer
 {
-  mem_limit = #{self.mem_limit}
+#{hash_to_config(self.indexer_options)}
 }
 
 searchd
@@ -119,10 +146,8 @@ searchd
   port = #{self.port}
   log = #{self.searchd_log_file}
   query_log = #{self.query_log_file}
-  read_timeout = 5
-  max_children = 30
   pid_file = #{self.pid_file}
-  max_matches = #{self.max_matches}
+#{hash_to_config(self.searchd_options)}
 }
         CONFIG
         
@@ -134,7 +159,7 @@ searchd
           infixed_fields  = []
           
           model.sphinx_indexes.select { |index| index.model == model }.each_with_index do |index, i|
-            file.write index.to_config(model, i, database_conf, charset_type, model_index)
+            file.write index.to_config(model, i, database_conf, model_index)
             
             index.adapter_object.setup
             
@@ -181,6 +206,31 @@ searchd
       end
     end
     
+    def hash_to_config(hash)
+      hash.collect { |key, value|
+        translated_value = case value
+        when TrueClass
+          &quot;1&quot;
+        when FalseClass
+          &quot;0&quot;
+        when NilClass, &quot;&quot;
+          next
+        else
+          value
+        end
+        &quot;  #{key} = #{translated_value}&quot;
+      }.join(&quot;\n&quot;)
+    end
+    
+    def self.options_merge(base, extra)
+      base = base.clone
+      extra.each do |key, value|
+        next if value.nil? || value == &quot;&quot;
+        base[key] = value
+      end
+      base
+    end
+    
     private
     
     # Parse the config/sphinx.yml file - if it exists - then use the attribute
@@ -194,7 +244,14 @@ searchd
       
       conf.each do |key,value|
         self.send(&quot;#{key}=&quot;, value) if self.methods.include?(&quot;#{key}=&quot;)
+        
+        self.source_options[key.to_sym] = value  if SourceOptions.include?(key.to_s)
+        self.index_options[key.to_sym] = value   if IndexOptions.include?(key.to_s)
+        self.indexer_options[key.to_sym] = value if IndexerOptions.include?(key.to_s)
+        self.searchd_options[key.to_sym] = value if SearchdOptions.include?(key.to_s)
       end unless conf.nil?
+      
+      self.bin_path += '/' unless self.bin_path.blank?
     end
     
     def core_index_for_model(model, sources)
@@ -204,31 +261,18 @@ index #{ThinkingSphinx::Index.name(model)}_core
 {
 #{sources}
 path = #{self.searchd_file_path}/#{ThinkingSphinx::Index.name(model)}_core
-charset_type = #{self.charset_type}
 INDEX
       
-      morphology  = model.sphinx_indexes.inject(self.morphology) { |morph, index|
-        index.options[:morphology] || morph
-      }
-      output += &quot;  morphology     = #{morphology}\n&quot;         unless morphology.blank?
-      output += &quot;  charset_table  = #{self.charset_table}\n&quot; unless self.charset_table.nil?
-      output += &quot;  ignore_chars   = #{self.ignore_chars}\n&quot;  unless self.ignore_chars.nil?
+      unless combined_index_options(model).empty?
+        output += hash_to_config(combined_index_options(model))
+      end
       
       if self.allow_star
         # Ye Olde way of turning on enable_star
         output += &quot;  enable_star    = 1\n&quot;
-        output += &quot;  min_prefix_len = #{self.min_prefix_len}\n&quot;
-      else
-        # New, better way of turning on enable_star - thanks to James Healy
-        output += &quot;  enable_star    = 1\n&quot; if self.enable_star
-        output += &quot;  min_prefix_len = #{self.min_prefix_len}\n&quot; unless self.min_prefix_len.nil?
-        output += &quot;  min_infix_len  = #{self.min_infix_len}\n&quot; unless self.min_infix_len.nil?
+        output += &quot;  min_prefix_len = #{self.combined_index_options[:min_prefix_len]}\n&quot;
       end
       
-
-      output += &quot;  html_strip     = 1\n&quot; if self.html_strip
-      output += &quot;  html_remove_elements = #{self.html_remove_elements}\n&quot; unless self.html_remove_elements.blank?
-
       unless model.sphinx_indexes.collect(&amp;:prefix_fields).flatten.empty?
         output += &quot;  prefix_fields = #{model.sphinx_indexes.collect(&amp;:prefix_fields).flatten.map(&amp;:unique_name).join(', ')}\n&quot;
       else
@@ -265,41 +309,14 @@ index #{ThinkingSphinx::Index.name(model)}
 {
   type = distributed
   #{ sources.join(&quot;\n  &quot;) }
-  charset_type = #{self.charset_type}
 }
       INDEX
     end
     
-    def create_array_accum
-      ::ActiveRecord::Base.connection.execute &quot;begin&quot;
-      ::ActiveRecord::Base.connection.execute &quot;savepoint ts&quot;
-      begin
-        # see http://www.postgresql.org/docs/8.2/interactive/sql-createaggregate.html
-        if ::ActiveRecord::Base.connection.raw_connection.server_version &gt; 80200
-          ::ActiveRecord::Base.connection.execute &lt;&lt;-SQL
-            CREATE AGGREGATE array_accum (anyelement)
-            (
-                sfunc = array_append,
-                stype = anyarray,
-                initcond = '{}'
-            );
-          SQL
-        else
-          ::ActiveRecord::Base.connection.execute &lt;&lt;-SQL
-            CREATE AGGREGATE array_accum
-            (
-                basetype = anyelement,
-                sfunc = array_append,
-                stype = anyarray,
-                initcond = '{}'
-            );
-          SQL
-        end
-      rescue
-        ::ActiveRecord::Base.connection.execute &quot;rollback to savepoint ts&quot;
+    def combined_index_options(model)
+      model.sphinx_indexes.inject(self.index_options) do |options, index|
+        self.class.options_merge(options, index.local_index_options)
       end
-      ::ActiveRecord::Base.connection.execute &quot;release savepoint ts&quot;
-      ::ActiveRecord::Base.connection.execute &quot;commit&quot;
     end
   end
 end</diff>
      <filename>lib/thinking_sphinx/configuration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -48,11 +48,11 @@ module ThinkingSphinx
     end
     
     def empty?(part = :core)
-      config = ThinkingSphinx::Configuration.new
+      config = ThinkingSphinx::Configuration.instance
       File.size?(&quot;#{config.searchd_file_path}/#{self.name}_#{part}.spa&quot;).nil?
     end
     
-    def to_config(model, index, database_conf, charset_type, offset)
+    def to_config(model, index, database_conf, offset)
       # Set up associations and joins
       add_internal_attributes
       link!
@@ -82,13 +82,14 @@ sql_db   = #{database_conf[:database]}
 #{&quot;sql_port = #{database_conf[:port]}&quot; unless database_conf[:port].blank? }
 #{&quot;sql_sock = #{database_conf[:socket]}&quot; unless database_conf[:socket].blank? }
 
-sql_query_pre    = #{charset_type == &quot;utf-8&quot; &amp;&amp; adapter == :mysql ? &quot;SET NAMES utf8&quot; : &quot;&quot;}
+sql_query_pre    = #{utf8? &amp;&amp; adapter == :mysql ? &quot;SET NAMES utf8&quot; : &quot;&quot;}
 #{&quot;sql_query_pre    = SET SESSION group_concat_max_len = #{@options[:group_concat_max_len]}&quot; if @options[:group_concat_max_len]}
 sql_query_pre    = #{to_sql_query_pre}
 sql_query        = #{to_sql(:offset =&gt; offset).gsub(/\n/, ' ')}
 sql_query_range  = #{to_sql_query_range}
 sql_query_info   = #{to_sql_query_info(offset)}
 #{attr_sources}
+#{ThinkingSphinx::Configuration.instance.hash_to_config(self.source_options)}
 }
       SOURCE
       
@@ -98,7 +99,7 @@ sql_query_info   = #{to_sql_query_info(offset)}
 source #{self.class.name(model)}_#{index}_delta : #{self.class.name(model)}_#{index}_core
 {
 sql_query_pre    = 
-sql_query_pre    = #{charset_type == &quot;utf-8&quot; &amp;&amp; adapter == :mysql ? &quot;SET NAMES utf8&quot; : &quot;&quot;}
+sql_query_pre    = #{utf8? &amp;&amp; adapter == :mysql ? &quot;SET NAMES utf8&quot; : &quot;&quot;}
 #{&quot;sql_query_pre    = SET SESSION group_concat_max_len = #{@options[:group_concat_max_len]}&quot; if @options[:group_concat_max_len]}
 sql_query        = #{to_sql(:delta =&gt; true, :offset =&gt; offset).gsub(/\n/, ' ')}
 sql_query_range  = #{to_sql_query_range :delta =&gt; true}
@@ -257,8 +258,37 @@ GROUP BY #{ (
       @fields.select { |field| field.infixes }
     end
     
+    def local_index_options
+      @options.keys.inject({}) do |local_options, key|
+        if ThinkingSphinx::Configuration::IndexOptions.include?(key.to_s)
+          local_options[key.to_sym] = @options[key]
+          local_options
+        end
+      end
+    end
+    
+    def index_options
+      all_index_options = ThinkingSphinx::Configuration.instance.index_options.clone
+      @options.keys.select { |key|
+        ThinkingSphinx::Configuration::IndexOptions.include?(key.to_s)
+      }.each { |key| all_index_options[key.to_sym] = @options[key] }
+      all_index_options
+    end
+    
+    def source_options
+      all_source_options = ThinkingSphinx::Configuration.instance.source_options.clone
+      @options.keys.select { |key|
+        ThinkingSphinx::Configuration::SourceOptions.include?(key.to_s)
+      }.each { |key| all_source_options[key.to_sym] = @options[key] }
+      all_source_options
+    end
+    
     private
     
+    def utf8?
+      self.index_options[:charset_type] == &quot;utf-8&quot;
+    end
+    
     def quote_column(column)
       @model.connection.quote_column_name(column)
     end</diff>
      <filename>lib/thinking_sphinx/index.rb</filename>
    </modified>
    <modified>
      <diff>@@ -270,7 +270,7 @@ module ThinkingSphinx
       # options hash.
       # 
       def client_from_options(options = {})
-        config = ThinkingSphinx::Configuration.new
+        config = ThinkingSphinx::Configuration.instance
         client = Riddle::Client.new config.address, config.port
         klass  = options[:class]
         index_options = klass ? klass.sphinx_indexes.last.options : {}</diff>
      <filename>lib/thinking_sphinx/search.rb</filename>
    </modified>
    <modified>
      <diff>@@ -32,6 +32,20 @@ Spec::Runner.configure do |config|
     
     ThinkingSphinx.updates_enabled = true
     ThinkingSphinx.deltas_enabled = true
+    
+    ThinkingSphinx::Configuration.instance.reset
+    ThinkingSphinx::Configuration.instance.database_yml_file = &quot;spec/fixtures/sphinx/database.yml&quot;
+    
+    # Ensure after_commit plugin is loaded correctly
+    Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each { |klass|
+      unless klass.ancestors.include?(AfterCommit::ConnectionAdapters)
+        klass.send(:include, AfterCommit::ConnectionAdapters)
+      end
+    }
+  end
+  
+  config.before :each do
+    #
   end
   
   config.after :each do</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -49,7 +49,7 @@ class SphinxHelper
   end
   
   def setup_sphinx
-    @configuration = ThinkingSphinx::Configuration.new
+    @configuration = ThinkingSphinx::Configuration.instance.reset
     File.open(&quot;spec/fixtures/sphinx/database.yml&quot;, &quot;w&quot;) do |file|
       YAML.dump({@configuration.environment =&gt; {
         :adapter  =&gt; 'mysql',</diff>
      <filename>spec/sphinx_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,5 @@
 require 'spec/spec_helper'
 
-# Ensure after_commit plugin is loaded correctly
-Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each { |klass|
-  klass.send(:include, AfterCommit::ConnectionAdapters)
-}
-
 describe &quot;ThinkingSphinx::ActiveRecord::Delta&quot; do
   it &quot;should call the toggle_delta method after a save&quot; do
     @beta = Beta.new
@@ -78,7 +73,7 @@ describe &quot;ThinkingSphinx::ActiveRecord::Delta&quot; do
       @person.send(:index_delta)
       
       Person.should have_received(:system).with(
-        &quot;#{ThinkingSphinx::Configuration.new.bin_path}indexer --config #{ThinkingSphinx::Configuration.new.config_file} --rotate person_delta&quot;
+        &quot;#{ThinkingSphinx::Configuration.instance.bin_path}indexer --config #{ThinkingSphinx::Configuration.instance.config_file} --rotate person_delta&quot;
       )
     end
     </diff>
      <filename>spec/unit/thinking_sphinx/active_record/delta_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -121,14 +121,14 @@ describe &quot;ThinkingSphinx::ActiveRecord&quot; do
   
   describe &quot;toggle_deleted method&quot; do
     before :each do
-      @configuration = ThinkingSphinx::Configuration.stub_instance(
+      @configuration = ThinkingSphinx::Configuration.instance
+      @configuration.stub_methods(
         :address  =&gt; &quot;an address&quot;,
         :port     =&gt; 123
       )
       @client = Riddle::Client.stub_instance(:update =&gt; true)
       @person = Person.find(:first)
       
-      ThinkingSphinx::Configuration.stub_method(:new =&gt; @configuration)
       Riddle::Client.stub_method(:new =&gt; @client)
       Person.sphinx_indexes.each { |index| index.stub_method(:delta? =&gt; false) }
       @person.stub_method(:in_core_index? =&gt; true)
@@ -271,7 +271,7 @@ describe &quot;ThinkingSphinx::ActiveRecord&quot; do
   end
   
   it &quot;should remove destroyed new instances from the delta index if they're in it&quot; do
-    beta = Beta.create(:name =&gt; &quot;eleven&quot;)
+    beta = Beta.create!(:name =&gt; &quot;eleven&quot;)
     sleep(1) # wait for Sphinx to catch up
     
     Beta.search(&quot;eleven&quot;).should_not be_empty</diff>
      <filename>spec/unit/thinking_sphinx/active_record_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -33,14 +33,14 @@ describe ThinkingSphinx::Configuration do
   describe &quot;environment instance method&quot; do
     it &quot;should return the class method&quot; do
       ThinkingSphinx::Configuration.stub_method(:environment =&gt; &quot;spec&quot;)
-      ThinkingSphinx::Configuration.new.environment.should == &quot;spec&quot;
+      ThinkingSphinx::Configuration.instance.environment.should == &quot;spec&quot;
       ThinkingSphinx::Configuration.should have_received(:environment)
     end    
   end
   
   describe &quot;build method&quot; do
     before :each do
-      @config = ThinkingSphinx::Configuration.new
+      @config = ThinkingSphinx::Configuration.instance
       
       @config.stub_methods(
         :load_models                  =&gt; &quot;&quot;,
@@ -102,13 +102,6 @@ describe ThinkingSphinx::Configuration do
       YAML.should have_received(:load)
     end
     
-    it &quot;should set the mem limit based on the configuration&quot; do
-      @config.build
-      
-      file = open(@config.config_file) { |f| f.read }
-      file.should match(/mem_limit\s+= #{@config.mem_limit}/)
-    end
-    
     it &quot;should use the configuration port&quot; do
       @config.build
       
@@ -131,24 +124,17 @@ describe ThinkingSphinx::Configuration do
       file.should match(/pid_file\s+= #{@config.pid_file}/)
     end
     
-    it &quot;should set max matches from configuration&quot; do
-      @config.build
-      
-      file = open(@config.config_file) { |f| f.read }
-      file.should match(/max_matches\s+= #{@config.max_matches}/)
-    end
-    
     it &quot;should request configuration for each index for each model&quot; do
       @config.build
       
       @person_index_a.should have_received(:to_config).with(
-        Person, 0, {:option =&gt; &quot;value&quot;}, @config.charset_type, 0
+        Person, 0, {:option =&gt; &quot;value&quot;}, 0
       )
       @person_index_b.should have_received(:to_config).with(
-        Person, 1, {:option =&gt; &quot;value&quot;}, @config.charset_type, 0
+        Person, 1, {:option =&gt; &quot;value&quot;}, 0
       )
       @friendship_index_a.should have_received(:to_config).with(
-        Friendship, 0, {:option =&gt; &quot;value&quot;}, @config.charset_type, 1
+        Friendship, 0, {:option =&gt; &quot;value&quot;}, 1
       )
     end
     
@@ -202,7 +188,6 @@ describe ThinkingSphinx::Configuration do
           &quot;searchd_file_path&quot; =&gt; &quot;searchd/file/path&quot;,
           &quot;address&quot;           =&gt; &quot;127.0.0.1&quot;,
           &quot;port&quot;              =&gt; 3333,
-          &quot;allow_star&quot;        =&gt; true,
           &quot;min_prefix_len&quot;    =&gt; 2,
           &quot;min_infix_len&quot;     =&gt; 3,
           &quot;mem_limit&quot;         =&gt; &quot;128M&quot;,
@@ -220,9 +205,12 @@ describe ThinkingSphinx::Configuration do
     end
     
     it &quot;should use the accessors to set the configuration values&quot; do
-      config = ThinkingSphinx::Configuration.new
-      @settings[&quot;development&quot;].each do |key, value|
-        config.send(key).should == value
+      config = ThinkingSphinx::Configuration.instance
+      config.send(:parse_config)
+      
+      %w(config_file searchd_log_file query_log_file pid_file searchd_file_path
+        address port).each do |key|
+        config.send(key).should == @settings[&quot;development&quot;][key]
       end
     end
     
@@ -233,7 +221,7 @@ describe ThinkingSphinx::Configuration do
   
   describe &quot;core_index_for_model method&quot; do
     before :each do
-      @config = ThinkingSphinx::Configuration.new
+      @config = ThinkingSphinx::Configuration.instance
       @model  = Person
     end
     
@@ -251,88 +239,59 @@ describe ThinkingSphinx::Configuration do
     end
     
     it &quot;should include the charset type setting&quot; do
-      @config.charset_type = &quot;specchars&quot;
+      @config.index_options[:charset_type] = &quot;specchars&quot;
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should match(
         /charset_type = specchars/
       )
     end
     
     it &quot;should include the morphology setting if it isn't blank&quot; do
-      @config.morphology = &quot;morph&quot;
+      @config.index_options[:morphology] = &quot;morph&quot;
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should match(
         /morphology\s+= morph/
       )
     end
     
     it &quot;should not include the morphology setting if it is blank&quot; do
-      @config.morphology = nil
+      @config.index_options[:morphology] = nil
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should_not match(
         /morphology\s+=/
       )
       
-      @config.morphology = &quot;&quot;
+      @config.index_options[:morphology] = &quot;&quot;
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should_not match(
         /morphology\s+=/
       )
     end
     
     it &quot;should include the charset_table value if it isn't nil&quot; do
-      @config.charset_table = &quot;table_chars&quot;
+      @config.index_options[:charset_table] = &quot;table_chars&quot;
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should match(
         /charset_table\s+= table_chars/
       )
     end
     
     it &quot;should not set the charset_table value if it is nil&quot; do
-      @config.charset_table = nil
+      @config.index_options[:charset_table] = nil
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should_not match(
         /charset_table\s+=/
       )      
     end
     
     it &quot;should set the ignore_chars value if it isn't nil&quot; do
-      @config.ignore_chars = &quot;ignorable&quot;
+      @config.index_options[:ignore_chars] = &quot;ignorable&quot;
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should match(
         /ignore_chars\s+= ignorable/
       )
     end
     
     it &quot;should not set the ignore_chars value if it is nil&quot; do
-      @config.ignore_chars = nil
+      @config.index_options[:ignore_chars] = nil
       @config.send(:core_index_for_model, @model, &quot;my sources&quot;).should_not match(
         /ignore_chars\s+=/
       )
     end
     
-    it &quot;should include the star-related settings when allow_star is true&quot; do
-      @config.allow_star      = true
-      @config.min_prefix_len  = 1
-      text =  @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
-      
-      text.should match(/enable_star\s+= 1/)
-      text.should match(/min_prefix_len\s+= 1/)
-      # text.should match(/min_infix_len\s+= 1/)
-    end
-    
-    it &quot;should use the configuration's infix and prefix length values if set&quot; do
-      @config.allow_star     = true
-      @config.min_prefix_len = 3
-      @config.min_infix_len  = 2
-      text =  @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
-      
-      text.should match(/min_prefix_len\s+= 3/)
-      # text.should match(/min_infix_len\s+= 2/)
-    end
-    
-    it &quot;should not include the star-related settings when allow_star is false&quot; do
-      @config.allow_star = false
-      text =  @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
-      
-      text.should_not match(/enable_star\s+=/)
-      text.should_not match(/min_prefix_len\s+=/)
-      text.should_not match(/min_infix_len\s+=/)
-    end
-    
     it &quot;should set prefix_fields if any fields are flagged explicitly&quot; do
       @model.sphinx_indexes.first.stub_methods(
         :prefix_fields =&gt; [
@@ -384,23 +343,25 @@ describe ThinkingSphinx::Configuration do
     end
 
     it &quot;should include html_strip if value is set&quot; do
-      @config.html_strip = 1
+      @config.index_options[:html_strip] = 1
       text = @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
       text.should match(/html_strip\s+= 1/)
     end
 
     it &quot;shouldn't include html_strip if value is not set&quot; do
+      @config.index_options.delete :html_strip
       text = @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
       text.should_not match(/html_strip/)
     end
 
     it &quot;should include html_remove_elements if values are set&quot; do
-      @config.html_remove_elements = 'script'
+      @config.index_options[:html_remove_elements] = 'script'
       text = @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
       text.should match(/html_remove_elements\s+= script/)
     end
 
     it &quot;shouldn't include html_remove_elements if no values are set&quot; do
+      @config.index_options.delete :html_remove_elements
       text = @config.send(:core_index_for_model, @model, &quot;my sources&quot;)
       text.should_not match(/html_remove_elements/)
     end
@@ -408,7 +369,7 @@ describe ThinkingSphinx::Configuration do
   
   describe &quot;delta_index_for_model method&quot; do
     before :each do
-      @config = ThinkingSphinx::Configuration.new
+      @config = ThinkingSphinx::Configuration.instance
       @model  = Person
     end
     
@@ -434,7 +395,7 @@ describe ThinkingSphinx::Configuration do
   
   describe &quot;distributed_index_for_model method&quot; do
     before :each do
-      @config = ThinkingSphinx::Configuration.new
+      @config = ThinkingSphinx::Configuration.instance
       @model  = Person
     end
     
@@ -478,7 +439,7 @@ describe ThinkingSphinx::Configuration do
     
   describe &quot;initialisation&quot; do
     it &quot;should have a default bin_path of nothing&quot; do
-      ThinkingSphinx::Configuration.new.bin_path.should == &quot;&quot;
+      ThinkingSphinx::Configuration.instance.bin_path.should == &quot;&quot;
     end
     
     it &quot;should append a / to bin_path if one is supplied&quot; do
@@ -492,7 +453,60 @@ describe ThinkingSphinx::Configuration do
         f.write  YAML.dump(@settings)
       end
       
-      ThinkingSphinx::Configuration.new.bin_path.should match(/\/$/)
+      ThinkingSphinx::Configuration.instance.send(:parse_config)
+      ThinkingSphinx::Configuration.instance.bin_path.should match(/\/$/)
+    end
+  end
+  
+  it &quot;should insert set searchd options into the configuration file&quot; do
+    config = ThinkingSphinx::Configuration.instance
+    ThinkingSphinx::Configuration::SearchdOptions.each do |option|
+      config.searchd_options[option.to_sym] = &quot;something&quot;
+      config.build
+      
+      file = open(config.config_file) { |f| f.read }
+      file.should match(/#{option}\s+= something/)
+      
+      config.searchd_options[option.to_sym] = nil
+    end
+  end
+  
+  it &quot;should insert set indexer options into the configuration file&quot; do
+    config = ThinkingSphinx::Configuration.instance
+    ThinkingSphinx::Configuration::IndexerOptions.each do |option|
+      config.indexer_options[option.to_sym] = &quot;something&quot;
+      config.build
+      
+      file = open(config.config_file) { |f| f.read }
+      file.should match(/#{option}\s+= something/)
+      
+      config.indexer_options[option.to_sym] = nil
+    end
+  end
+  
+  it &quot;should insert set index options into the configuration file&quot; do
+    config = ThinkingSphinx::Configuration.instance
+    ThinkingSphinx::Configuration::IndexOptions.each do |option|
+      config.index_options[option.to_sym] = &quot;something&quot;
+      config.build
+      
+      file = open(config.config_file) { |f| f.read }
+      file.should match(/#{option}\s+= something/)
+      
+      config.index_options[option.to_sym] = nil
+    end
+  end
+  
+  it &quot;should insert set source options into the configuration file&quot; do
+    config = ThinkingSphinx::Configuration.instance
+    ThinkingSphinx::Configuration::SourceOptions.each do |option|
+      config.source_options[option.to_sym] = &quot;something&quot;
+      config.build
+      
+      file = open(config.config_file) { |f| f.read }
+      file.should match(/#{option}\s+= something/)
+      
+      config.source_options[option.to_sym] = nil
     end
   end
 end
\ No newline at end of file</diff>
      <filename>spec/unit/thinking_sphinx/configuration_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,7 +28,7 @@ describe ThinkingSphinx::Index do
     end
     
     it &quot;should call link!&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0)
+      @index.to_config(Person, 0, @database, 0)
       
       @index.should have_received(:link!)
     end
@@ -36,17 +36,17 @@ describe ThinkingSphinx::Index do
     it &quot;should raise an exception if the adapter isn't mysql or postgres&quot; do
       @index.stub_method(:adapter =&gt; :sqlite)
       
-      lambda { @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0) }.should raise_error
+      lambda { @index.to_config(Person, 0, @database, 0) }.should raise_error
     end
     
     it &quot;should set the core source name to {model}_{index}_core&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_core/
       )
     end
     
     it &quot;should include the database config supplied&quot; do
-      conf = @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0)
+      conf = @index.to_config(Person, 0, @database, 0)
       conf.should match(/type\s+= mysql/)
       conf.should match(/sql_host\s+= localhost/)
       conf.should match(/sql_user\s+= username/)
@@ -57,96 +57,99 @@ describe ThinkingSphinx::Index do
     it &quot;should use 'user' if 'username' doesn't exist in database configuration&quot; do
       conf = @index.to_config(Person, 0,
         @database.except(:username).merge(:user =&gt; &quot;username&quot;),
-        &quot;utf-8&quot;, 0
+        0
       )
       conf.should match(/sql_user\s+= username/)
     end
     
     it &quot;should include the database socket if set&quot; do
-      conf = @index.to_config(Person, 0, @database.merge(:socket =&gt; &quot;dbsocket&quot;), &quot;utf-8&quot;, 0)
+      conf = @index.to_config(Person, 0, @database.merge(:socket =&gt; &quot;dbsocket&quot;), 0)
       conf.should match(/sql_sock\s+= dbsocket/)
     end
     
     it &quot;should not include the database socket if not set&quot; do
-      conf = @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0)
+      conf = @index.to_config(Person, 0, @database, 0)
       conf.should_not match(/sql_sock/)
     end
     
     it &quot;should include the database port if set&quot; do
-      conf = @index.to_config(Person, 0, @database.merge(:port =&gt; &quot;dbport&quot;), &quot;utf-8&quot;, 0)
+      conf = @index.to_config(Person, 0, @database.merge(:port =&gt; &quot;dbport&quot;), 0)
       conf.should match(/sql_port\s+= dbport/)
     end
     
     it &quot;should not include the database socket if not set&quot; do
-      conf = @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0)
+      conf = @index.to_config(Person, 0, @database, 0)
       conf.should_not match(/sql_port/)
     end
     
     it &quot;should have a pre query 'SET NAMES utf8' if using mysql and utf8 charset&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.options[:charset_type] = &quot;utf-8&quot;
+      @index.to_config(Person, 0, @database, 0).should match(
         /sql_query_pre\s+= SET NAMES utf8/
       )
       
       @index.stub_method(:delta? =&gt; true)
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta.+sql_query_pre\s+= SET NAMES utf8/m
       )
       
+      @index.options[:charset_type] = &quot;non-utf-8&quot;
       @index.stub_method(:delta? =&gt; false)
-      @index.to_config(Person, 0, @database, &quot;non-utf-8&quot;, 0).should_not match(
+      @index.to_config(Person, 0, @database, 0).should_not match(
         /SET NAMES utf8/
       )
       
+      @index.options[:charset_type] = &quot;utf-8&quot;
       @index.stub_method(:adapter =&gt; :postgres)
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should_not match(
+      @index.to_config(Person, 0, @database, 0).should_not match(
         /SET NAMES utf8/
       )
     end
     
     it &quot;should use the pre query from the index&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /sql_query_pre\s+= sql_query_pre/
       )
     end
     
     it &quot;should not set group_concat_max_len if not specified&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should_not match(
+      @index.to_config(Person, 0, @database, 0).should_not match(
         /group_concat_max_len/
       )
     end
 
     it &quot;should set group_concat_max_len if specified&quot; do
       @index.options.merge! :group_concat_max_len =&gt; 2056
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/
       )
       
       @index.stub_method(:delta? =&gt; true)
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta.+sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/m
       )
     end
     
     it &quot;should use the main query from the index&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /sql_query\s+= SQL/
       )
     end
     
     it &quot;should use the range query from the index&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /sql_query_range\s+= sql_query_range/
       )
     end
 
     it &quot;should use the info query from the index&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /sql_query_info\s+= sql_query_info/
       )
     end
     
     it &quot;should include the attribute sources&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /attr a\n\s+attr b/
       )
     end
@@ -154,13 +157,13 @@ describe ThinkingSphinx::Index do
     it &quot;should add a delta index with name {model}_{index}_delta if requested&quot; do
       @index.stub_method(:delta? =&gt; true)
       
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta/
       )
     end
     
     it &quot;should not add a delta index unless requested&quot; do
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should_not match(
+      @index.to_config(Person, 0, @database, 0).should_not match(
         /source person_0_delta/
       )
     end
@@ -168,7 +171,7 @@ describe ThinkingSphinx::Index do
     it &quot;should have the delta index inherit from the core index&quot; do
       @index.stub_method(:delta? =&gt; true)
       
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta : person_0_core/
       )
     end
@@ -176,7 +179,7 @@ describe ThinkingSphinx::Index do
     it &quot;should redefine the main query for the delta index&quot; do
       @index.stub_method(:delta? =&gt; true)
       
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta.+sql_query\s+= SQL/m
       )
     end
@@ -184,7 +187,7 @@ describe ThinkingSphinx::Index do
     it &quot;should redefine the range query for the delta index&quot; do
       @index.stub_method(:delta? =&gt; true)
       
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta.+sql_query_range\s+= sql_query_range/m
       )
     end
@@ -192,7 +195,7 @@ describe ThinkingSphinx::Index do
     it &quot;should redefine the pre query for the delta index&quot; do
       @index.stub_method(:delta? =&gt; true)
       
-      @index.to_config(Person, 0, @database, &quot;utf-8&quot;, 0).should match(
+      @index.to_config(Person, 0, @database, 0).should match(
         /source person_0_delta.+sql_query_pre\s+=\s*\n/m
       )
     end
@@ -268,7 +271,7 @@ describe ThinkingSphinx::Index do
   describe &quot;empty? method&quot; do
     before :each do
       @index = ThinkingSphinx::Index.new(Contact)
-      config = ThinkingSphinx::Configuration.new
+      config = ThinkingSphinx::Configuration.instance
       
       `mkdir -p #{config.searchd_file_path}`
       @file_path = &quot;#{config.searchd_file_path}/#{@index.name}_core.spa&quot;</diff>
      <filename>spec/unit/thinking_sphinx/index_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,7 @@ namespace :thinking_sphinx do
   
   desc &quot;Start a Sphinx searchd daemon using Thinking Sphinx's settings&quot;
   task :start =&gt; :app_env do
-    config = ThinkingSphinx::Configuration.new
+    config = ThinkingSphinx::Configuration.instance
     
     FileUtils.mkdir_p config.searchd_file_path
     raise RuntimeError, &quot;searchd is already running.&quot; if sphinx_running?
@@ -47,14 +47,14 @@ namespace :thinking_sphinx do
   
   desc &quot;Generate the Sphinx configuration file using Thinking Sphinx's settings&quot;
   task :configure =&gt; :app_env do
-    config = ThinkingSphinx::Configuration.new
+    config = ThinkingSphinx::Configuration.instance
     puts &quot;Generating Configuration to #{config.config_file}&quot;
     config.build
   end
   
   desc &quot;Index data for Sphinx using Thinking Sphinx's settings&quot;
   task :index =&gt; :app_env do
-    config = ThinkingSphinx::Configuration.new
+    config = ThinkingSphinx::Configuration.instance
     unless ENV[&quot;INDEX_ONLY&quot;] == &quot;true&quot;
       puts &quot;Generating Configuration to #{config.config_file}&quot;
       config.build
@@ -86,7 +86,7 @@ namespace :ts do
 end
 
 def sphinx_pid
-  config = ThinkingSphinx::Configuration.new
+  config = ThinkingSphinx::Configuration.instance
   
   if File.exists?(config.pid_file)
     `cat #{config.pid_file}`[/\d+/]</diff>
      <filename>tasks/thinking_sphinx_tasks.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>832bc78a5668b603abe340a8ede50c8e25a13cb1</id>
    </parent>
  </parents>
  <author>
    <name>Pat Allan</name>
    <email>pat@freelancing-gods.com</email>
  </author>
  <url>http://github.com/jaikoo/thinking-sphinx/commit/ec5b0e5cc71ee46bd79c5eb597086a3c1ce8040b</url>
  <id>ec5b0e5cc71ee46bd79c5eb597086a3c1ce8040b</id>
  <committed-date>2008-10-18T06:10:16-07:00</committed-date>
  <authored-date>2008-10-18T06:10:16-07:00</authored-date>
  <message>Restructuring Configuration to be a singleton and providing support for all Sphinx config options</message>
  <tree>014b43c80263f5c2ba1f7268f96f268080884424</tree>
  <committer>
    <name>Pat Allan</name>
    <email>pat@freelancing-gods.com</email>
  </committer>
</commit>
