Sha256: a2bfcb728ff052533f1677665420ec3c06f51a5b1fd0e72d1812a99babacea2c

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require 'fileutils'

module Sunspot
  module Solr
    class Installer
      class ConfigInstaller
        include TaskHelper

        class <<self
          def execute(config_path, options = {})
            new(config_path, options).execute
          end
        end

        def initialize(config_path, options)
          @config_path = config_path
          @verbose = !!options[:verbose]
          @force   = !!options[:force]
        end

        def execute
          sunspot_config_path = File.join(File.dirname(__FILE__), '..', '..',
                                          '..', '..', 'solr', 'solr', 'conf')
          return if File.expand_path(sunspot_config_path) == File.expand_path(@config_path)

          FileUtils.mkdir_p(@config_path)
          Dir.glob(File.join(sunspot_config_path, '*.*')).each do |file|
            file = File.expand_path(file)
            dest = File.join(@config_path, File.basename(file))

            if File.exist?(dest)
              if @force
                say("Removing existing file #{dest}")
              else
                next
              end
            end

            say("Copying #{file} => #{dest}")
            FileUtils.cp(file, dest)
          end

          # Also copy the solr.xml file for multi core support
          file = File.expand_path('../solr.xml', sunspot_config_path)
          dest = File.expand_path(File.join(@config_path, ".."), File.basename(file))
          say("Copying #{file} => #{dest}")
          FileUtils.cp(file, dest)

          # Also copy words.dic file for mmseg4j
          FileUtils.mkdir_p(File.join(@config_path, '../dic'))
          dest = File.expand_path(File.join(@config_path, '../dic/words.dic'))
          unless File.exist?(dest)
            file = File.expand_path(File.join(sunspot_config_path, '../dic/words.dic'))
            say("Copying #{file} => #{dest}")
            FileUtils.cp(file, dest)
          end

        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qiny_sunspot_solr-2.1.0 lib/sunspot/solr/installer/config_installer.rb