Class: ThinkingSphinx::Configuration

Inherits:
Riddle::Configuration
  • Object
show all
Defined in:
lib/thinking_sphinx/configuration.rb

Defined Under Namespace

Modules: Defaults Classes: ConsistentIds, DistributedIndices, MinimumFields

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



10
11
12
13
14
# File 'lib/thinking_sphinx/configuration.rb', line 10

def initialize
  super

  setup
end

Instance Attribute Details

#configuration_fileObject

Returns the value of attribute configuration_file



4
5
6
# File 'lib/thinking_sphinx/configuration.rb', line 4

def configuration_file
  @configuration_file
end

#controllerObject



28
29
30
31
32
33
34
# 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

#index_pathsObject (readonly)

Returns the value of attribute index_paths



5
6
7
# File 'lib/thinking_sphinx/configuration.rb', line 5

def index_paths
  @index_paths
end

#indices_locationObject

Returns the value of attribute indices_location



4
5
6
# File 'lib/thinking_sphinx/configuration.rb', line 4

def indices_location
  @indices_location
end

#versionObject

Returns the value of attribute version



4
5
6
# File 'lib/thinking_sphinx/configuration.rb', line 4

def version
  @version
end

Class Method Details

.instanceObject



16
17
18
# File 'lib/thinking_sphinx/configuration.rb', line 16

def self.instance
  @instance ||= new
end

.resetObject



20
21
22
# File 'lib/thinking_sphinx/configuration.rb', line 20

def self.reset
  @instance = nil
end

Instance Method Details

#bin_pathObject



24
25
26
# File 'lib/thinking_sphinx/configuration.rb', line 24

def bin_path
  settings['bin_path']
end

#engine_index_pathsObject



46
47
48
49
50
# File 'lib/thinking_sphinx/configuration.rb', line 46

def engine_index_paths
  return [] unless defined?(Rails)

  engine_indice_paths.flatten.compact
end

#engine_indice_pathsObject



52
53
54
55
56
57
# 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

#frameworkObject



36
37
38
# File 'lib/thinking_sphinx/configuration.rb', line 36

def framework
  @framework ||= ThinkingSphinx::Frameworks.current
end

#framework=(framework) ⇒ Object



40
41
42
43
44
# File 'lib/thinking_sphinx/configuration.rb', line 40

def framework=(framework)
  @framework = framework
  setup
  framework
end

#indices_for_references(*references) ⇒ Object



59
60
61
62
# 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) ⇒ Object



64
65
66
# File 'lib/thinking_sphinx/configuration.rb', line 64

def next_offset(reference)
  @offsets[reference] ||= @offsets.keys.count
end

#preload_indicesObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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

  if settings['distributed_indices'].nil? || settings['distributed_indices']
    ThinkingSphinx::Configuration::DistributedIndices.new(indices).reconcile
  end

  @preloaded_indices = true
end

#renderObject



84
85
86
87
88
89
90
91
# File 'lib/thinking_sphinx/configuration.rb', line 84

def render
  preload_indices

  ThinkingSphinx::Configuration::ConsistentIds.new(indices).reconcile
  ThinkingSphinx::Configuration::MinimumFields.new(indices).reconcile

  super
end

#render_to_fileObject



93
94
95
96
97
# File 'lib/thinking_sphinx/configuration.rb', line 93

def render_to_file
  FileUtils.mkdir_p searchd.binlog_path unless searchd.binlog_path.blank?

  open(configuration_file, 'w') { |file| file.write render }
end

#settingsObject



99
100
101
# File 'lib/thinking_sphinx/configuration.rb', line 99

def settings
  @settings ||= File.exists?(settings_file) ? settings_to_hash : {}
end