lib/thinking_sphinx/configuration.rb in ebeigarts-thinking-sphinx-1.1.22 vs lib/thinking_sphinx/configuration.rb in ebeigarts-thinking-sphinx-1.2.10

- old
+ new

@@ -157,11 +157,13 @@ # Make sure all models are loaded - without reloading any that # ActiveRecord::Base is already aware of (otherwise we start to hit some # messy dependencies issues). # def load_models - return if defined?(Rails) && Rails.configuration.cache_classes + return if defined?(Rails) && + Rails.configuration.cache_classes && + Rails::VERSION::STRING.to_f > 2.1 self.model_directories.each do |base| Dir["#{base}**/*.rb"].each do |file| model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1') @@ -228,9 +230,27 @@ case ::ActiveRecord::Base.sphinx_database_adapter when SQLite3Adapter, OracleAdapter @type = "xml" else @type = "sql" + end + end + + def client + client = Riddle::Client.new address, port + client.max_matches = configuration.searchd.max_matches || 1000 + client + end + + def models_by_crc + @models_by_crc ||= begin + ThinkingSphinx.indexed_models.inject({}) do |hash, model| + hash[model.constantize.to_crc32] = model + Object.subclasses_of(model.constantize).each { |subclass| + hash[subclass.to_crc32] = subclass.name + } + hash + end end end private