lib/ultrasphinx/ultrasphinx.rb in ultrasphinx-1.5.1 vs lib/ultrasphinx/ultrasphinx.rb in ultrasphinx-1.5.2

- old
+ new

@@ -8,11 +8,11 @@ class DaemonError < Exception #:nodoc: end class UsageError < Exception #:nodoc: end - # internal file paths + # Internal file paths SUBDIR = "config/ultrasphinx" DIR = "#{RAILS_ROOT}/#{SUBDIR}" @@ -24,20 +24,26 @@ BASE_PATH = (File.exist?(ENV_BASE_PATH) ? ENV_BASE_PATH : GENERIC_BASE_PATH) raise ConfigurationError, "Please create a '#{SUBDIR}/#{RAILS_ENV}.base' or '#{SUBDIR}/default.base' file in order to use Ultrasphinx in your #{RAILS_ENV} environment." unless File.exist? BASE_PATH # XXX lame - # some miscellaneous constants + # Some miscellaneous constants MAX_INT = 2**32-1 MAX_WORDS = 2**16 # maximum number of stopwords built EMPTY_SEARCHABLE = "__empty_searchable__" UNIFIED_INDEX_NAME = "complete" + SPHINX_VERSION = if `which indexer` =~ /\/indexer\n/m + `indexer`.split("\n").first[7..-1] + else + "unknown" + end + CONFIG_MAP = { # These must be symbols for key mapping against Rails itself :username => 'sql_user', :password => 'sql_pass', :host => 'sql_host', @@ -71,17 +77,23 @@ } } ADAPTER = ActiveRecord::Base.connection.instance_variable_get("@config")[:adapter] + mattr_accessor :with_rake + # Logger. def self.say msg - msg = "** ultrasphinx: #{msg}" - if defined? RAILS_DEFAULT_LOGGER - RAILS_DEFAULT_LOGGER.warn msg + if with_rake + puts msg[0..0].upcase + msg[1..-1] else - STDERR.puts msg + msg = "** ultrasphinx: #{msg}" + if defined? RAILS_DEFAULT_LOGGER + RAILS_DEFAULT_LOGGER.warn msg + else + STDERR.puts msg + end end end # Configuration file parser. def self.options_for(heading, path) @@ -98,11 +110,10 @@ Hash[*options.flatten] end end - # introspect on the existing generated conf files - + # Introspect on the existing generated conf files INDEXER_SETTINGS = options_for('indexer', BASE_PATH) CLIENT_SETTINGS = options_for('client', BASE_PATH) DAEMON_SETTINGS = options_for('searchd', BASE_PATH) SOURCE_SETTINGS = options_for('source', BASE_PATH) INDEX_SETTINGS = options_for('index', BASE_PATH)