lib/thinking_sphinx.rb in dpickett-thinking-sphinx-1.1.12 vs lib/thinking_sphinx.rb in dpickett-thinking-sphinx-1.1.23
- old
+ new
@@ -16,10 +16,11 @@
require 'thinking_sphinx/facet'
require 'thinking_sphinx/class_facet'
require 'thinking_sphinx/facet_collection'
require 'thinking_sphinx/field'
require 'thinking_sphinx/index'
+require 'thinking_sphinx/source'
require 'thinking_sphinx/rails_additions'
require 'thinking_sphinx/search'
require 'thinking_sphinx/deltas'
require 'thinking_sphinx/adapters/abstract_adapter'
@@ -34,11 +35,11 @@
module ThinkingSphinx
module Version #:nodoc:
Major = 1
Minor = 1
- Tiny = 12
+ Tiny = 23
String = [Major, Minor, Tiny].join('.')
end
# A ConnectionError will get thrown when a connection to Sphinx can't be
@@ -135,11 +136,43 @@
"SELECT @@global.sql_mode, @@session.sql_mode;"
).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? }
)
end
+ @@remote_sphinx = false
+
+ # An indication of whether Sphinx is running on a remote machine instead of
+ # the same machine.
+ #
+ def self.remote_sphinx?
+ @@remote_sphinx
+ end
+
+ # Tells Thinking Sphinx that Sphinx is running on a different machine, and
+ # thus it can't reliably guess whether it is running or not (ie: the
+ # #sphinx_running? method), and so just assumes it is.
+ #
+ # Useful for multi-machine deployments. Set it in your production.rb file.
+ #
+ # ThinkingSphinx.remote_sphinx = true
+ #
+ def self.remote_sphinx=(value)
+ @@remote_sphinx = value
+ end
+
+ # Check if Sphinx is running. If remote_sphinx is set to true (indicating
+ # Sphinx is on a different machine), this will always return true, and you
+ # will have to handle any connection errors yourself.
+ #
def self.sphinx_running?
+ remote_sphinx? || sphinx_running_by_pid?
+ end
+
+ # Check if Sphinx is actually running, provided the pid is on the same
+ # machine as this code.
+ #
+ def self.sphinx_running_by_pid?
!!sphinx_pid && pid_active?(sphinx_pid)
end
def self.sphinx_pid
pid_file = ThinkingSphinx::Configuration.instance.pid_file
@@ -172,10 +205,11 @@
def self.jruby?
defined?(JRUBY_VERSION)
end
def self.mysql?
- ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" || (
+ ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" ||
+ ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlplusAdapter" || (
jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql"
)
end
end