class ThinkingSphinx::Configuration
Attributes
configuration_file[RW]
controller[W]
index_paths[R]
index_set_class[W]
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
index_set_class()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 59 def index_set_class @index_set_class ||= ThinkingSphinx::IndexSet end
indices_for_references(*references)
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 63 def indices_for_references(*references) index_set_class.new(:references => references).to_a end
next_offset(reference)
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 67 def next_offset(reference) @offsets[reference] ||= @offsets.keys.count end
preload_indices()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 71 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 if settings['distributed_indices'].nil? || settings['distributed_indices'] ThinkingSphinx::Configuration::DistributedIndices.new(indices).reconcile end @preloaded_indices = true end
render()
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/configuration.rb, line 87 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 96 def render_to_file FileUtils.mkdir_p searchd.binlog_path unless searchd.binlog_path.blank? open(configuration_file, 'w') { |file| file.write render } end
settings()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 102 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 179 def apply_sphinx_settings! sphinx_sections.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 108 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 118 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 128 def framework_root Pathname.new(framework.root) end
log_root()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 124 def log_root real_path 'log' end
real_path(*arguments)
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 132 def real_path(*arguments) path = framework_root.join(*arguments) path.exist? ? path.realpath : path end
settings_file()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 142 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 137 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 146 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.1.4' if settings['common_sphinx_configuration'] common.common_sphinx_configuration = true indexer.common_sphinx_configuration = true end configure_searchd apply_sphinx_settings! @offsets = {} end
sphinx_sections()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 173 def sphinx_sections sections = [indexer, searchd] sections.unshift common if settings['common_sphinx_configuration'] sections end
tmp_path()
click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 169 def tmp_path real_path 'tmp' end