<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/ultrasphinx/autoload.rb</filename>
    </added>
    <added>
      <filename>lib/ultrasphinx/core_extensions.rb</filename>
    </added>
    <added>
      <filename>lib/ultrasphinx/fields.rb</filename>
    </added>
    <added>
      <filename>lib/ultrasphinx/is_indexed.rb</filename>
    </added>
    <added>
      <filename>lib/ultrasphinx/search.rb</filename>
    </added>
    <added>
      <filename>lib/ultrasphinx/spell.rb</filename>
    </added>
    <added>
      <filename>lib/ultrasphinx/ultrasphinx.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,2 @@
 
-require 'fields'
 require 'ultrasphinx'
-require 'autoload'
-require 'is_indexed'
-require 'search'</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,194 +1,8 @@
 
-require 'yaml'
-
-module Ultrasphinx
-
-  class Exception &lt; ::Exception
-  end
-  class ConfigurationError &lt; Exception
-  end  
-  class DaemonError &lt; Exception
-  end
-
-  CONF_PATH = &quot;#{RAILS_ROOT}/config/environments/sphinx.#{RAILS_ENV}.conf&quot;
-  ENV_BASE_PATH = &quot;#{RAILS_ROOT}/config/environments/sphinx.#{RAILS_ENV}.base&quot; 
-  GENERIC_BASE_PATH = &quot;#{RAILS_ROOT}/config/sphinx.base&quot;
-  BASE_PATH = (File.exist?(ENV_BASE_PATH) ? ENV_BASE_PATH : GENERIC_BASE_PATH)
-  
-  raise ConfigurationError, &quot;Please create a #{BASE_PATH} configuration file.&quot; unless File.exist? BASE_PATH
-  
-  def self.options_for(heading)
-    section = open(BASE_PATH).read[/^#{heading}.*?\{(.*?)\}/m, 1]
-    raise &quot;missing heading #{heading} in #{BASE_PATH}&quot; if section.nil?
-    lines = section.split(&quot;\n&quot;).reject { |l| l.strip.empty? }
-    options = lines.map do |c|
-      c =~ /\s*(.*?)\s*=\s*([^\#]*)/
-      $1 ? [$1, $2.strip] : []
-    end
-    Hash[*options.flatten] 
-  end
-  
-  SOURCE_DEFAULTS = %(
-    strip_html = 0
-    index_html_attrs =
-    sql_query_pre = SET SESSION group_concat_max_len = 65535
-    sql_query_pre = SET NAMES utf8
-    sql_query_post =
-    sql_range_step = 20000
-  )
-
-  MAX_INT = 2**32-1
-  COLUMN_TYPES = {:string =&gt; 'text', :text =&gt; 'text', :integer =&gt; 'numeric', :date =&gt; 'date', :datetime =&gt; 'date' }
-  CONFIG_MAP = {:username =&gt; 'sql_user',
-    :password =&gt; 'sql_pass',
-    :host =&gt; 'sql_host',
-    :database =&gt; 'sql_db',
-    :adapter =&gt; 'type',
-    :port =&gt; 'sql_port',
-    :socket =&gt; 'sql_sock'}
-  OPTIONAL_SPHINX_KEYS = ['morphology', 'stopwords', 'min_word_len', 'charset_type', 'charset_table', 'docinfo']
-  PLUGIN_SETTINGS = options_for('ultrasphinx')
-  DAEMON_SETTINGS = options_for('searchd')
-
-  MAX_WORDS = 2**16 # maximum number of stopwords built  
-  STOPWORDS_PATH = &quot;#{Ultrasphinx::PLUGIN_SETTINGS['path']}/stopwords.txt}&quot;
-
-  #logger.debug &quot;Ultrasphinx options are: #{PLUGIN_SETTINGS.inspect}&quot;
-
-  MODELS_HASH = {}
-
-  class &lt;&lt; self    
-    def load_constants
-      Dir[&quot;#{RAILS_ROOT}/app/models/**/*.rb&quot;].each do |filename|
-        next if filename =~ /\/(\.svn|CVS|\.bzr)\//
-        begin
-          open(filename) {|file| load filename if file.grep(/is_indexed/).any?}
-        rescue Object =&gt; e
-          puts &quot;Ultrasphinx: warning; autoload error on #{filename}&quot;
-        end
-      end 
-      Fields.instance.configure(MODELS_HASH)
-    end
-         
-    def configure       
-      load_constants
-            
-      puts &quot;Rebuilding Ultrasphinx configurations for #{ENV['RAILS_ENV']} environment&quot; 
-      puts &quot;Available models are #{MODELS_HASH.keys.to_sentence}&quot;
-      File.open(CONF_PATH, &quot;w&quot;) do |conf|
-        conf.puts &quot;\n# Auto-generated at #{Time.now}.\n# Hand modifications will be overwritten.\n&quot;
-        
-        conf.puts &quot;\n# #{BASE_PATH}&quot;
-        conf.puts open(BASE_PATH).read.sub(/^ultrasphinx.*?\{.*?\}/m, '') + &quot;\n&quot;
-        
-        index_list = {&quot;complete&quot; =&gt; []}
-        
-        conf.puts &quot;\n# Source configuration\n\n&quot;
-
-        puts &quot;Generating SQL&quot;
-        MODELS_HASH.each_with_index do |model_options, class_id|
-          model, options = model_options
-          klass, source = model.constantize, model.tableize
-
-#          puts &quot;SQL for #{model}&quot;
-          
-          index_list[source] = [source]
-          index_list[&quot;complete&quot;] &lt;&lt; source
-  
-          conf.puts &quot;source #{source}\n{&quot;
-          conf.puts SOURCE_DEFAULTS        
-          klass.connection.instance_variable_get(&quot;@config&quot;).each do |key, value|
-            conf.puts &quot;#{CONFIG_MAP[key]} = #{value}&quot; if CONFIG_MAP[key]          
-          end
-          
-          table, pkey = klass.table_name, klass.primary_key
-          condition_strings, join_strings = Array(options[:conditions]).map{|condition| &quot;(#{condition})&quot;}, []
-          column_strings = [&quot;(#{table}.#{pkey} * #{MODELS_HASH.size} + #{class_id}) AS id&quot;, 
-                                       &quot;#{class_id} AS class_id&quot;, &quot;'#{klass.name}' AS class&quot;]   
-          remaining_columns = Fields.instance.keys - [&quot;class&quot;, &quot;class_id&quot;]
-          
-          conf.puts &quot;\nsql_query_range = SELECT MIN(#{pkey}), MAX(#{pkey}) FROM #{table}&quot;
-          
-          options[:fields].to_a.each do |f|
-            column, as = f.is_a?(Hash) ? [f[:field], f[:as]] : [f, f]
-            column_strings &lt;&lt; Fields.instance.cast(&quot;#{table}.#{column}&quot;, as)
-            remaining_columns.delete(as)
-          end
-          
-          options[:includes].to_a.each do |join|
-            join_klass = join[:model].constantize
-            association = klass.reflect_on_association(join[:model].underscore.to_sym)
-            join_strings &lt;&lt; &quot;LEFT OUTER JOIN #{join_klass.table_name} ON &quot; + 
-              if (macro = association.macro) == :belongs_to 
-                &quot;#{join_klass.table_name}.#{join_klass.primary_key} = #{table}.#{association.primary_key_name}&quot; 
-              elsif macro == :has_one
-                &quot;#{table}.#{klass.primary_key} = #{join_klass.table_name}.#{association.instance_variable_get('@foreign_key_name')}&quot; 
-              else
-                raise ConfigurationError, &quot;Unidentified association macro #{macro.inspect}&quot;
-              end
-            column_strings &lt;&lt; &quot;#{join_klass.table_name}.#{join[:field]} AS #{join[:as] or join[:field]}&quot;
-            remaining_columns.delete(join[:as] || join[:field])
-          end
-          
-          options[:concats].to_a.select{|concat| concat[:model] and concat[:field]}.each do |group|
-            # only has_many's right now
-            join_klass = group[:model].constantize
-            association = klass.reflect_on_association(group[:association_name] ? group[:association_name].to_sym :  group[:model].underscore.pluralize.to_sym)
-            join_strings &lt;&lt; &quot;LEFT OUTER JOIN #{join_klass.table_name} ON #{table}.#{klass.primary_key} = #{join_klass.table_name}.#{association.primary_key_name}&quot; + (&quot; AND (#{group[:conditions]})&quot; if group[:conditions]).to_s # XXX make sure foreign key is right for polymorphic relationships
-            column_strings &lt;&lt; Fields.instance.cast(&quot;GROUP_CONCAT(#{join_klass.table_name}.#{group[:field]} SEPARATOR ' ')&quot;, group[:as])
-            remaining_columns.delete(group[:as])
-          end
-          
-          options[:concats].to_a.select{|concat| concat[:fields]}.each do |concat|
-            column_strings &lt;&lt; Fields.instance.cast(&quot;CONCAT_WS(' ', #{concat[:fields].map{|field| &quot;#{table}.#{field}&quot;}.join(', ')})&quot;, concat[:as])
-            remaining_columns.delete(concat[:as])
-          end
-            
-#          puts &quot;#{model} has #{remaining_columns.inspect} remaining&quot;
-          remaining_columns.each do |field|
-            column_strings &lt;&lt; Fields.instance.null(field)
-          end
-          
-          query_strings = [&quot;SELECT&quot;, column_strings.sort_by do |string| 
-            # sphinx wants them always in the same order, but &quot;id&quot; must be first
-            (field = string[/.*AS (.*)/, 1]) == &quot;id&quot; ? &quot;*&quot; : field
-          end.join(&quot;, &quot;)] 
-          query_strings &lt;&lt; &quot;FROM #{table}&quot;                      
-          query_strings += join_strings.uniq
-          query_strings &lt;&lt; &quot;WHERE #{table}.#{pkey} &gt;= $start AND #{table}.#{pkey} &lt;= $end&quot;
-          query_strings += condition_strings.uniq.map{|s| &quot;AND #{s}&quot;}
-          query_strings &lt;&lt; &quot;GROUP BY id&quot;
-          
-          conf.puts &quot;sql_query = #{query_strings.join(&quot; &quot;)}&quot;
-          
-          groups = []
-          # group and date sorting params... this really only would have to be run once
-          Fields.instance.each do |field, type|
-            case type
-              when 'numeric'
-                groups &lt;&lt; &quot;sql_group_column = #{field}&quot;
-              when 'date'
-                groups &lt;&lt; &quot;sql_date_column = #{field}&quot;
-            end
-          end
-          conf.puts &quot;\n&quot; + groups.sort_by{|s| s[/= (.*)/, 1]}.join(&quot;\n&quot;)
-          conf.puts &quot;\nsql_query_info = SELECT * FROM #{table} WHERE #{table}.#{pkey} = (($id - #{class_id}) / #{MODELS_HASH.size})&quot;           
-          conf.puts &quot;}\n\n&quot;                
-        end
-        
-        conf.puts &quot;\n# Index configuration\n\n&quot;
-        index_list.to_a.sort_by {|x| x.first == &quot;complete&quot; ? 1 : 0}.each do |name, source_list|
-          conf.puts &quot;index #{name}\n{&quot;
-          source_list.each {|source| conf.puts &quot;source = #{source}&quot;}
-          OPTIONAL_SPHINX_KEYS.each do |key|
-            conf.puts &quot;#{key} = #{PLUGIN_SETTINGS[key]}&quot; if PLUGIN_SETTINGS[key]
-          end
-          conf.puts &quot;path = #{PLUGIN_SETTINGS[&quot;path&quot;]}/sphinx_index_#{name}&quot;
-          conf.puts &quot;}\n\n&quot;        
-        end
-      end
-            
-    end
-        
-  end
-end
+require 'ultrasphinx/core_extensions'
+require 'ultrasphinx/ultrasphinx'
+require 'ultrasphinx/autoload'
+require 'ultrasphinx/fields'
+require 'ultrasphinx/is_indexed'
+require 'ultrasphinx/search'
+require 'ultrasphinx/spell'</diff>
      <filename>lib/ultrasphinx.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,7 @@ namespace :ultrasphinx do
     cmd &lt;&lt; &quot; --rotate&quot; if daemon_running?
     cmd &lt;&lt; &quot; complete&quot;
     puts cmd
-    exec cmd
+    system cmd
   end
   
   namespace :daemon do
@@ -23,13 +23,19 @@ namespace :ultrasphinx do
       raise Ultrasphinx::DaemonError, &quot;Already running&quot; if daemon_running?
       # remove lockfiles
       Dir[Ultrasphinx::PLUGIN_SETTINGS[&quot;path&quot;] + &quot;*spl&quot;].each {|file| File.delete(file)}
-      exec &quot;searchd --config #{Ultrasphinx::CONF_PATH}&quot;
+      system &quot;searchd --config #{Ultrasphinx::CONF_PATH}&quot;
+      if daemon_running?
+        puts &quot;Started successfully&quot;
+      else
+        puts &quot;Failed to start&quot;
+      end
     end
     
     desc &quot;Stop the search daemon&quot;
     task :stop =&gt; [:environment] do
       raise Ultrasphinx::DaemonError, &quot;Doesn't seem to be running&quot; unless daemon_running?
       system &quot;kill #{daemon_pid}&quot;
+      puts &quot;Stopped&quot;
     end
 
     desc &quot;Restart the search daemon&quot;
@@ -55,9 +61,9 @@ namespace :ultrasphinx do
     desc &quot;Check if the search daemon is running&quot;
     task :status =&gt; :environment do
       if daemon_running?
-        puts &quot;Running.&quot;
+        puts &quot;Daemon is running&quot;
       else
-        puts &quot;Stopped.&quot;
+        puts &quot;Daemon is stopped&quot;
       end
     end      
   end</diff>
      <filename>tasks/ultrasphinx.rake</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/autoload.rb</filename>
    </removed>
    <removed>
      <filename>lib/fields.rb</filename>
    </removed>
    <removed>
      <filename>lib/is_indexed.rb</filename>
    </removed>
    <removed>
      <filename>lib/search.rb</filename>
    </removed>
    <removed>
      <filename>lib/spell.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>36e5cba49002d35361908e3bf93ceff8affe631f</id>
    </parent>
  </parents>
  <author>
    <name>Evan Weaver</name>
    <email>evan@cloudbur.st</email>
  </author>
  <url>http://github.com/jamesgolick/ultrasphinx/commit/09b10a820160623a426d7221274391ea3f938dd1</url>
  <id>09b10a820160623a426d7221274391ea3f938dd1</id>
  <committed-date>2007-07-19T19:32:17-07:00</committed-date>
  <authored-date>2007-07-19T19:32:17-07:00</authored-date>
  <message>namespace</message>
  <tree>9e375b648cbd6d088d9931de6881cd61988cd060</tree>
  <committer>
    <name>Evan Weaver</name>
    <email>evan@cloudbur.st</email>
  </committer>
</commit>
