Module Ultrasphinx
In: lib/ultrasphinx/search/parser.rb
lib/ultrasphinx/search/internals.rb
lib/ultrasphinx/associations.rb
lib/ultrasphinx/search.rb
lib/ultrasphinx/ultrasphinx.rb
lib/ultrasphinx/fields.rb
lib/ultrasphinx/configure.rb
lib/ultrasphinx/spell.rb
lib/ultrasphinx/search.rb
lib/ultrasphinx/spell.rb
lib/ultrasphinx/ultrasphinx.rb

Methods

Classes and Modules

Module Ultrasphinx::Associations
Module Ultrasphinx::DateSelf
Module Ultrasphinx::NumericSelf
Module Ultrasphinx::Spell
Class Ultrasphinx::Configure
Class Ultrasphinx::Fields
Class Ultrasphinx::Search

Constants

SUBDIR = "config/ultrasphinx"   Internal file paths
DIR = "#{RAILS_ROOT}/#{SUBDIR}"
THIS_DIR = File.expand_path(File.dirname(__FILE__))
CONF_PATH = "#{DIR}/#{RAILS_ENV}.conf"
ENV_BASE_PATH = "#{DIR}/#{RAILS_ENV}.base"
GENERIC_BASE_PATH = "#{DIR}/default.base"
BASE_PATH = (File.exist?(ENV_BASE_PATH) ? ENV_BASE_PATH : GENERIC_BASE_PATH)
MAX_INT = 2**32-1   Some miscellaneous constants
MAX_WORDS = 2**16
MAIN_INDEX = "main"
DELTA_INDEX = "delta"
INDEXES = [MAIN_INDEX, DELTA_INDEX]
CONFIG_MAP = { # These must be symbols for key mapping against Rails itself. :username => 'sql_user', :password => 'sql_pass', :host => 'sql_host', :database => 'sql_db', :port => 'sql_port', :socket => 'sql_sock'
CONNECTION_DEFAULTS = { :host => 'localhost', :password => '', :username => 'root'
SQL_FUNCTIONS = { 'mysql' => { 'group_concat' => "CAST(GROUP_CONCAT(DISTINCT ? ? SEPARATOR ' ') AS CHAR)", 'delta' => "DATE_SUB(NOW(), INTERVAL ? SECOND)", 'hash' => "CAST(CRC32(?) AS unsigned)", 'range_cast' => "?"
DEFAULTS = { 'mysql' => %( type = mysql sql_query_pre = SET SESSION group_concat_max_len = 65535 sql_query_pre = SET NAMES utf8 ), 'postgresql' => %( type = pgsql sql_query_pre = )
ADAPTER = ActiveRecord::Base.connection.instance_variable_get("@config")[:adapter] rescue 'mysql'
INDEXER_SETTINGS = options_for('indexer', BASE_PATH)   Introspect on the existing generated conf files.
CLIENT_SETTINGS = options_for('client', BASE_PATH)
DAEMON_SETTINGS = options_for('searchd', BASE_PATH)
SOURCE_SETTINGS = options_for('source', BASE_PATH)
INDEX_SETTINGS = options_for('index', BASE_PATH)
DICTIONARY = CLIENT_SETTINGS['dictionary_name'] || 'ap'
STOPWORDS_PATH = "#{Ultrasphinx::INDEX_SETTINGS['path']}/#{DICTIONARY}-stopwords.txt"
MODEL_CONFIGURATION = {}
SUBDIR = "config/ultrasphinx"   Internal file paths
DIR = "#{RAILS_ROOT}/#{SUBDIR}"
THIS_DIR = File.expand_path(File.dirname(__FILE__))
CONF_PATH = "#{DIR}/#{RAILS_ENV}.conf"
ENV_BASE_PATH = "#{DIR}/#{RAILS_ENV}.base"
GENERIC_BASE_PATH = "#{DIR}/default.base"
BASE_PATH = (File.exist?(ENV_BASE_PATH) ? ENV_BASE_PATH : GENERIC_BASE_PATH)
MAX_INT = 2**32-1   Some miscellaneous constants
MAX_WORDS = 2**16
MAIN_INDEX = "main"
DELTA_INDEX = "delta"
INDEXES = [MAIN_INDEX, DELTA_INDEX]
CONFIG_MAP = { # These must be symbols for key mapping against Rails itself. :username => 'sql_user', :password => 'sql_pass', :host => 'sql_host', :database => 'sql_db', :port => 'sql_port', :socket => 'sql_sock'
CONNECTION_DEFAULTS = { :host => 'localhost', :password => '', :username => 'root'
SQL_FUNCTIONS = { 'mysql' => { 'group_concat' => "CAST(GROUP_CONCAT(DISTINCT ? ? SEPARATOR ' ') AS CHAR)", 'delta' => "DATE_SUB(NOW(), INTERVAL ? SECOND)", 'hash' => "CAST(CRC32(?) AS unsigned)", 'range_cast' => "?"
DEFAULTS = { 'mysql' => %( type = mysql sql_query_pre = SET SESSION group_concat_max_len = 65535 sql_query_pre = SET NAMES utf8 ), 'postgresql' => %( type = pgsql sql_query_pre = )
ADAPTER = ActiveRecord::Base.connection.instance_variable_get("@config")[:adapter] rescue 'mysql'
INDEXER_SETTINGS = options_for('indexer', BASE_PATH)   Introspect on the existing generated conf files.
CLIENT_SETTINGS = options_for('client', BASE_PATH)
DAEMON_SETTINGS = options_for('searchd', BASE_PATH)
SOURCE_SETTINGS = options_for('source', BASE_PATH)
INDEX_SETTINGS = options_for('index', BASE_PATH)
DICTIONARY = CLIENT_SETTINGS['dictionary_name'] || 'ap'
STOPWORDS_PATH = "#{Ultrasphinx::INDEX_SETTINGS['path']}/#{DICTIONARY}-stopwords.txt"
MODEL_CONFIGURATION = {}

Public Class methods

See if a delta index was defined.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 201
201:   def self.delta_index_present?
202:     if File.exist?(CONF_PATH) 
203:       File.open(CONF_PATH).readlines.detect do |line|
204:         line =~ /^index delta/
205:       end
206:     end
207:   end

See if a delta index was defined.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 201
201:   def self.delta_index_present?
202:     if File.exist?(CONF_PATH) 
203:       File.open(CONF_PATH).readlines.detect do |line|
204:         line =~ /^index delta/
205:       end
206:     end
207:   end

[Source]

    # File lib/ultrasphinx/ultrasphinx.rb, line 61
61:   def self.load_stored_procedure(name)
62:     open("#{THIS_DIR}/postgresql/#{name}.sql").read.gsub(/\s+/, ' ')
63:   end

[Source]

    # File lib/ultrasphinx/ultrasphinx.rb, line 61
61:   def self.load_stored_procedure(name)
62:     open("#{THIS_DIR}/postgresql/#{name}.sql").read.gsub(/\s+/, ' ')
63:   end

Debug-mode logger.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 113
113:   def self.log msg
114:     # XXX Method name is stupid.
115:     if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER
116:       RAILS_DEFAULT_LOGGER.debug msg
117:     else
118:       STDERR.puts msg
119:     end
120:   end

Debug-mode logger.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 113
113:   def self.log msg
114:     # XXX Method name is stupid.
115:     if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER
116:       RAILS_DEFAULT_LOGGER.debug msg
117:     else
118:       STDERR.puts msg
119:     end
120:   end

Configuration file parser.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 123
123:   def self.options_for(heading, path)
124:     # Evaluate ERB
125:     template = ERB.new(File.open(path) {|f| f.read})
126:     contents = template.result(binding)
127:     
128:     # Find the correct heading.
129:     section = contents[/^#{heading.gsub('/', '__')}\s*?\{(.*?)\}/m, 1]
130:     
131:     if section
132:       # Strip comments and leading/trailing whitespace
133:       section.gsub!(/^\s*(.*?)\s*(?:#.*)?$/, '\1')
134: 
135:       # Convert to a hash
136:       returning({}) do |options|
137:         lines = section.split(/\n+/)
138:         while line = lines.shift
139:           if line =~ /(.*?)\s*=\s*(.*)/
140:             key, value = $1, [$2]
141:             value << (line = lines.shift) while line =~ /\\$/
142:             options[key] = value.join("\n    ")
143:           end
144:         end
145:       end
146:     else
147:       # XXX Is it safe to raise here?
148:       Ultrasphinx.say "warning; heading #{heading} not found in #{path}; it may be corrupted. "
149:       {}    
150:     end    
151:   end

Configuration file parser.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 123
123:   def self.options_for(heading, path)
124:     # Evaluate ERB
125:     template = ERB.new(File.open(path) {|f| f.read})
126:     contents = template.result(binding)
127:     
128:     # Find the correct heading.
129:     section = contents[/^#{heading.gsub('/', '__')}\s*?\{(.*?)\}/m, 1]
130:     
131:     if section
132:       # Strip comments and leading/trailing whitespace
133:       section.gsub!(/^\s*(.*?)\s*(?:#.*)?$/, '\1')
134: 
135:       # Convert to a hash
136:       returning({}) do |options|
137:         lines = section.split(/\n+/)
138:         while line = lines.shift
139:           if line =~ /(.*?)\s*=\s*(.*)/
140:             key, value = $1, [$2]
141:             value << (line = lines.shift) while line =~ /\\$/
142:             options[key] = value.join("\n    ")
143:           end
144:         end
145:       end
146:     else
147:       # XXX Is it safe to raise here?
148:       Ultrasphinx.say "warning; heading #{heading} not found in #{path}; it may be corrupted. "
149:       {}    
150:     end    
151:   end

Warn-mode logger. Also called from rake tasks.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 97
 97:   def self.say msg
 98:     # XXX Method name is stupid.
 99:     if with_rake
100:       puts msg[0..0].upcase + msg[1..-1]
101:     else
102:       msg = "** ultrasphinx: #{msg}"
103:       if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER
104:         RAILS_DEFAULT_LOGGER.warn msg
105:       else
106:         STDERR.puts msg
107:       end
108:     end        
109:     nil # Explicitly return nil
110:   end

Warn-mode logger. Also called from rake tasks.

[Source]

     # File lib/ultrasphinx/ultrasphinx.rb, line 97
 97:   def self.say msg
 98:     # XXX Method name is stupid.
 99:     if with_rake
100:       puts msg[0..0].upcase + msg[1..-1]
101:     else
102:       msg = "** ultrasphinx: #{msg}"
103:       if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER
104:         RAILS_DEFAULT_LOGGER.warn msg
105:       else
106:         STDERR.puts msg
107:       end
108:     end        
109:     nil # Explicitly return nil
110:   end

[Validate]