class ThinkingSphinx::Configuration
Attributes
configuration_file[RW]
controller[W]
index_paths[R]
indices_location[RW]
version[RW]
Public Class Methods
instance()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 16 def self.instance @instance ||= new end
new()
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/configuration.rb, line 10 def initialize super setup end
reset()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 20 def self.reset @instance = nil end
Public Instance Methods
bin_path()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 24 def bin_path settings['bin_path'] end
controller()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 28 def controller @controller ||= begin rc = ThinkingSphinx::Controller.new self, configuration_file rc.bin_path = bin_path.gsub(/([^\/])$/, '\1/') if bin_path.present? rc end end
engine_index_paths()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 46 def engine_index_paths return [] unless defined?(Rails) engine_indice_paths.flatten.compact end
engine_indice_paths()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 52 def engine_indice_paths Rails::Engine.subclasses.collect(&:instance).collect do |engine| engine.paths.add 'app/indices' unless engine.paths['app/indices'] engine.paths['app/indices'].existent end end
framework()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 36 def framework @framework ||= ThinkingSphinx::Frameworks.current end
framework=(framework)
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 40 def framework=(framework) @framework = framework setup framework end
indices_for_references(*references)
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 59 def indices_for_references(*references) preload_indices indices.select { |index| references.include?(index.reference) } end
next_offset(reference)
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 64 def next_offset(reference) @offsets[reference] ||= @offsets.keys.count end
preload_indices()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 68 def preload_indices return if @preloaded_indices index_paths.each do |path| Dir["#{path}/**/*.rb"].sort.each do |file| ActiveSupport::Dependencies.require_or_load file end end ThinkingSphinx::Configuration::DistributedIndices.new(indices).reconcile @preloaded_indices = true end
render()
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/configuration.rb, line 82 def render preload_indices ThinkingSphinx::Configuration::ConsistentIds.new(indices).reconcile ThinkingSphinx::Configuration::MinimumFields.new(indices).reconcile super end
render_to_file()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 91 def render_to_file FileUtils.mkdir_p searchd.binlog_path open(configuration_file, 'w') { |file| file.write render } end
settings()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 97 def settings @settings ||= File.exists?(settings_file) ? settings_to_hash : {} end
Private Instance Methods
apply_sphinx_settings!()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 159 def apply_sphinx_settings! [indexer, searchd].each do |object| settings.each do |key, value| next unless object.class.settings.include?(key.to_sym) object.send("#{key}=", value) end end end
configure_searchd()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 103 def configure_searchd configure_searchd_log_files searchd.binlog_path = tmp_path.join('binlog', environment).to_s searchd.address = settings['address'].presence || Defaults::ADDRESS searchd.mysql41 = settings['mysql41'] || settings['port'] || Defaults::PORT searchd.workers = 'threads' searchd.mysql_version_string = '5.5.21' if RUBY_PLATFORM == 'java' end
configure_searchd_log_files()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 113 def configure_searchd_log_files searchd.pid_file = log_root.join("#{environment}.sphinx.pid").to_s searchd.log = log_root.join("#{environment}.searchd.log").to_s searchd.query_log = log_root.join("#{environment}.searchd.query.log").to_s end
framework_root()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 123 def framework_root Pathname.new(framework.root) end
log_root()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 119 def log_root framework_root.join('log').realpath end
settings_file()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 132 def settings_file framework_root.join 'config', 'thinking_sphinx.yml' end
settings_to_hash()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 127 def settings_to_hash contents = YAML.load(ERB.new(File.read(settings_file)).result) contents && contents[environment] || {} end
setup()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 136 def setup @settings = nil @configuration_file = settings['configuration_file'] || framework_root.join( 'config', "#{environment}.sphinx.conf" ).to_s @index_paths = engine_index_paths + [framework_root.join('app', 'indices').to_s] @indices_location = settings['indices_location'] || framework_root.join( 'db', 'sphinx', environment ).to_s @version = settings['version'] || '2.0.6' configure_searchd apply_sphinx_settings! @offsets = {} end
tmp_path()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 154 def tmp_path path = framework_root.join('tmp') File.exists?(path) ? path.realpath : path end