Class: MongoidSphinx::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mongoid_sphinx/configuration.rb

Constant Summary collapse

SourceOptions =
%w( mysql_connect_flags mysql_ssl_cert mysql_ssl_key
mysql_ssl_ca sql_range_step sql_query_pre sql_query_post
sql_query_killlist sql_ranged_throttle sql_query_post_index unpack_zlib
unpack_mysqlcompress unpack_mysqlcompress_maxsize )
IndexOptions =
%w( blend_chars charset_table charset_type charset_dictpath
docinfo enable_star exceptions expand_keywords hitless_words
html_index_attrs html_remove_elements html_strip index_exact_words
ignore_chars inplace_docinfo_gap inplace_enable inplace_hit_gap
inplace_reloc_factor inplace_write_factor min_infix_len min_prefix_len
min_stemming_len min_word_len mlock morphology ngram_chars ngram_len
ondisk_dict overshort_step phrase_boundary phrase_boundary_step preopen
stopwords stopwords_step wordforms )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mongoid_sphinx/configuration.rb', line 27

def initialize
  init_root_env
  @configuration = Riddle::Configuration.new
  @configuration.searchd.pid_file   = "#{@root}/log/searchd.#{@env}.pid"
  @configuration.searchd.log        = "#{@root}/log/searchd.log"
  @configuration.searchd.query_log  = "#{@root}/log/searchd.query.log"
  
  @controller = Riddle::Controller.new @configuration, "#{@root}/config/#{@env}.sphinx.conf"
  
  self.address              = "127.0.0.1"
  self.port                 = 9312
  self.searchd_file_path    = "#{@root}/db/sphinx/#{@env}"
  self.allow_star           = false
  self.model_directories    = ["#{@root}/app/models/"] + Dir.glob("#{@root}/vendor/plugins/*/app/models/")
  self.indexed_models       = []
  
  self.source_options  = {
    :type => "xmlpipe2"
  }
  self.index_options   = {
    :charset_type => "utf-8",
    :morphology => "stem_en"
  }
  
  parse_config
  
  self
end

Instance Attribute Details

#allow_starObject

Returns the value of attribute allow_star.



22
23
24
# File 'lib/mongoid_sphinx/configuration.rb', line 22

def allow_star
  @allow_star
end

#configurationObject

Returns the value of attribute configuration.



25
26
27
# File 'lib/mongoid_sphinx/configuration.rb', line 25

def configuration
  @configuration
end

#controllerObject

Returns the value of attribute controller.



25
26
27
# File 'lib/mongoid_sphinx/configuration.rb', line 25

def controller
  @controller
end

#index_optionsObject

Returns the value of attribute index_options.



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

def index_options
  @index_options
end

#indexed_modelsObject

Returns the value of attribute indexed_models.



23
24
25
# File 'lib/mongoid_sphinx/configuration.rb', line 23

def indexed_models
  @indexed_models
end

#model_directoriesObject

Returns the value of attribute model_directories.



23
24
25
# File 'lib/mongoid_sphinx/configuration.rb', line 23

def model_directories
  @model_directories
end

#searchd_file_pathObject

Returns the value of attribute searchd_file_path.



23
24
25
# File 'lib/mongoid_sphinx/configuration.rb', line 23

def searchd_file_path
  @searchd_file_path
end

#source_optionsObject

Returns the value of attribute source_options.



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

def source_options
  @source_options
end

Instance Method Details

#addressObject



76
77
78
# File 'lib/mongoid_sphinx/configuration.rb', line 76

def address
  @address
end

#address=(address) ⇒ Object



80
81
82
83
# File 'lib/mongoid_sphinx/configuration.rb', line 80

def address=(address)
  @address = address
  @configuration.searchd.address = address
end

#bin_pathObject



135
136
137
# File 'lib/mongoid_sphinx/configuration.rb', line 135

def bin_path
  @controller.bin_path
end

#bin_path=(path) ⇒ Object



139
140
141
# File 'lib/mongoid_sphinx/configuration.rb', line 139

def bin_path=(path)
  @controller.bin_path = path
end

#build(file_path = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mongoid_sphinx/configuration.rb', line 61

def build(file_path=nil)
  file_path ||= "#{self.config_file}"
  
  @configuration.indexes.clear
  
  MongoidSphinx.context.indexed_models.each do |model|
    model = model.constantize
    @configuration.indexes.concat model.to_riddle
  end
  
  open(file_path, "w") do |file|
    file.write @configuration.render
  end
end

#clientObject



56
57
58
59
# File 'lib/mongoid_sphinx/configuration.rb', line 56

def client
  @configuration ||= parse_config
  Riddle::Client.new address, port
end

#config_fileObject



127
128
129
# File 'lib/mongoid_sphinx/configuration.rb', line 127

def config_file
  @controller.path
end

#config_file=(file) ⇒ Object



131
132
133
# File 'lib/mongoid_sphinx/configuration.rb', line 131

def config_file=(file)
  @controller.path = file
end

#indexer_binary_nameObject



151
152
153
# File 'lib/mongoid_sphinx/configuration.rb', line 151

def indexer_binary_name
  @controller.indexer_binary_name
end

#indexer_binary_name=(name) ⇒ Object



155
156
157
# File 'lib/mongoid_sphinx/configuration.rb', line 155

def indexer_binary_name=(name)
  @controller.indexer_binary_name = name
end

#mem_limitObject



94
95
96
# File 'lib/mongoid_sphinx/configuration.rb', line 94

def mem_limit
  @mem_limit
end

#mem_limit=(mem_limit) ⇒ Object



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

def mem_limit=(mem_limit)
  @mem_limit = mem_limit
  @configuration.indexer.mem_limit = mem_limit
end

#pid_fileObject



103
104
105
# File 'lib/mongoid_sphinx/configuration.rb', line 103

def pid_file
  @configuration.searchd.pid_file
end

#pid_file=(pid_file) ⇒ Object



107
108
109
# File 'lib/mongoid_sphinx/configuration.rb', line 107

def pid_file=(pid_file)
  @configuration.searchd.pid_file = pid_file
end

#portObject



85
86
87
# File 'lib/mongoid_sphinx/configuration.rb', line 85

def port
  @port
end

#port=(port) ⇒ Object



89
90
91
92
# File 'lib/mongoid_sphinx/configuration.rb', line 89

def port=(port)
  @port = port
  @configuration.searchd.port = port
end

#query_log_fileObject



119
120
121
# File 'lib/mongoid_sphinx/configuration.rb', line 119

def query_log_file
  @configuration.searchd.query_log
end

#query_log_file=(file) ⇒ Object



123
124
125
# File 'lib/mongoid_sphinx/configuration.rb', line 123

def query_log_file=(file)
  @configuration.searchd.query_log = file
end

#searchd_binary_nameObject



143
144
145
# File 'lib/mongoid_sphinx/configuration.rb', line 143

def searchd_binary_name
  @controller.searchd_binary_name
end

#searchd_binary_name=(name) ⇒ Object



147
148
149
# File 'lib/mongoid_sphinx/configuration.rb', line 147

def searchd_binary_name=(name)
  @controller.searchd_binary_name = name
end

#searchd_log_fileObject



111
112
113
# File 'lib/mongoid_sphinx/configuration.rb', line 111

def searchd_log_file
  @configuration.searchd.log
end

#searchd_log_file=(file) ⇒ Object



115
116
117
# File 'lib/mongoid_sphinx/configuration.rb', line 115

def searchd_log_file=(file)
  @configuration.searchd.log = file
end