class ThinkingSphinx::Configuration

Attributes

batch_size[RW]
configuration_file[RW]
controller[W]
guarding_strategy[W]
index_paths[R]
index_set_class[W]
indexing_strategy[W]
indices_location[RW]
version[RW]

Public Class Methods

instance() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 22
def self.instance
  @instance ||= new
end
new() click to toggle source
Calls superclass method
# File lib/thinking_sphinx/configuration.rb, line 16
def initialize
  super

  reset
end
reset() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 26
def self.reset
  @instance = nil
end

Public Instance Methods

bin_path() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 30
def bin_path
  settings['bin_path']
end
controller() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 34
def controller
  @controller ||= begin
    rc = Riddle::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 52
def engine_index_paths
  return [] unless defined?(Rails)

  engine_indice_paths.flatten.compact.sort
end
engine_indice_paths() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 58
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 42
def framework
  @framework ||= ThinkingSphinx::Frameworks.current
end
framework=(framework) click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 46
def framework=(framework)
  @framework = framework
  reset
  framework
end
guarding_strategy() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 65
def guarding_strategy
  @guarding_strategy ||= ThinkingSphinx::Guard::Files
end
index_set_class() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 69
def index_set_class
  @index_set_class ||= ThinkingSphinx::IndexSet
end
indexing_strategy() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 73
def indexing_strategy
  @indexing_strategy ||= ThinkingSphinx::IndexingStrategies::AllAtOnce
end
indices_for_references(*references) click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 77
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 81
def next_offset(reference)
  @offsets[reference] ||= @offsets.keys.count
end
preload_indices() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 85
def preload_indices
  @@mutex.synchronize do
    return if @preloaded_indices

    index_paths.each do |path|
      Dir["#{path}/**/*.rb"].sort.each do |file|
        ActiveSupport::Dependencies.require_or_load file
      end
    end

    normalise
    verify

    @preloaded_indices = true
  end
end
render() click to toggle source
Calls superclass method
# File lib/thinking_sphinx/configuration.rb, line 102
def render
  preload_indices

  super
end
render_to_file() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 108
def render_to_file
  unless settings['skip_directory_creation'] || searchd.binlog_path.blank?
    FileUtils.mkdir_p searchd.binlog_path
  end

  open(configuration_file, 'w') { |file| file.write render }
end
settings() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 116
def settings
  @settings ||= ThinkingSphinx::Settings.call self
end
setup() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 120
def setup
  @configuration_file = settings['configuration_file']
  @index_paths = engine_index_paths +
    [Pathname.new(framework.root).join('app', 'indices').to_s]
  @indices_location = settings['indices_location']
  @version = settings['version'] || '2.2.11'
  @batch_size = settings['batch_size'] || 1000

  if settings['common_sphinx_configuration']
    common.common_sphinx_configuration  = true
    indexer.common_sphinx_configuration = true
  end

  configure_searchd

  apply_sphinx_settings!

  @offsets = {}
end

Private Instance Methods

apply_sphinx_settings!() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 142
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 152
def configure_searchd
  searchd.socket = "#{settings["socket"]}:mysql41" if socket?

  if tcp?
    searchd.address = settings['address'].presence || Defaults::ADDRESS
    searchd.mysql41 = settings['mysql41'] || settings['port'] || Defaults::PORT
  end

  searchd.mysql_version_string = '5.5.21' if RUBY_PLATFORM == 'java'
end
normalise() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 163
def normalise
  if settings['distributed_indices'].nil? || settings['distributed_indices']
    ThinkingSphinx::Configuration::DistributedIndices.new(indices).reconcile
  end

  ThinkingSphinx::Configuration::ConsistentIds.new(indices).reconcile
  ThinkingSphinx::Configuration::MinimumFields.new(indices).reconcile
end
reset() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 172
def reset
  @settings = nil
  setup
end
socket?() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 177
def socket?
  settings["socket"].present?
end
sphinx_sections() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 181
def sphinx_sections
  sections = [indexer, searchd]
  sections.unshift common if settings['common_sphinx_configuration']
  sections
end
tcp?() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 187
def tcp?
  settings["socket"].nil?      ||
  settings["address"].present? ||
  settings["mysql41"].present? ||
  settings["port"].present?
end
verify() click to toggle source
# File lib/thinking_sphinx/configuration.rb, line 194
def verify
  ThinkingSphinx::Configuration::DuplicateNames.new(indices).reconcile
end