Sha256: 4a83a25825aa5914a5fbb0ae93e2971a10728bc5c6c9bfc0811e8a26fb39b80f

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

class SphinxController
  def initialize
    config.searchd.mysql41 = 9307
  end

  def setup
    FileUtils.mkdir_p config.indices_location
    config.controller.bin_path = ENV['SPHINX_BIN'] || ''
    config.render_to_file && index

    ThinkingSphinx::Configuration.reset

    if Rails::VERSION::MAJOR < 7
      ActiveSupport::Dependencies.loaded.each do |path|
        $LOADED_FEATURES.delete "#{path}.rb"
      end

      ActiveSupport::Dependencies.clear
    end

    config.searchd.mysql41 = 9307
    config.settings['quiet_deltas']      = true
    config.settings['attribute_updates'] = true
    config.controller.bin_path           = ENV['SPHINX_BIN'] || ''
  end

  def start
    config.controller.start
  rescue Riddle::CommandFailedError => error
    puts <<-TXT

The Sphinx start command failed:
  Command: #{error.command_result.command}
  Status:  #{error.command_result.status}
  Output:  #{error.command_result.output}
    TXT
    raise error
  end

  def stop
    while config.controller.running? do
      config.controller.stop
      sleep(0.1)
    end
  end

  def index(*indices)
    ThinkingSphinx::Commander.call :index_sql, config, :indices => indices
  end

  def merge
    ThinkingSphinx::Commander.call(:merge_and_update, config, {})
  end

  private

  def config
    ThinkingSphinx::Configuration.instance
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 spec/acceptance/support/sphinx_controller.rb
thinking-sphinx-5.5.1 spec/acceptance/support/sphinx_controller.rb
thinking-sphinx-5.5.0 spec/acceptance/support/sphinx_controller.rb
thinking-sphinx-5.4.0 spec/acceptance/support/sphinx_controller.rb