Guest User

Untitled

a guest
Jun 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. ## Configuraçao para o Masochism
  2. module ThinkingSphinx
  3. class Source
  4. include ThinkingSphinx::Source::InternalProperties
  5. include ThinkingSphinx::Source::SQL
  6.  
  7. ActiveReload::ConnectionProxy::setup! if Rails.env.production?
  8.  
  9. def set_source_sql(source, offset, delta = false)
  10. source.sql_query = to_sql(:offset => offset, :delta => delta).gsub(/\n/, ' ')
  11. source.sql_query_range = to_sql_query_range(:delta => delta)
  12. source.sql_query_info = to_sql_query_info(offset)
  13.  
  14. source.sql_query_pre += send(!delta ? :sql_query_pre_for_core : :sql_query_pre_for_delta)
  15.  
  16. if @index.local_options[:group_concat_max_len]
  17. source.sql_query_pre << "SET SESSION group_concat_max_len = #{@index.local_options[:group_concat_max_len]}"
  18. end
  19.  
  20. # A BASE DE DADOS ESTA USANDO LATIN1, E POR ISSO O SPHINX NAO CONSEGUIA INDEXAR COM UTF8
  21. # POR ISSO COMENTAMOS ESSA LINHA
  22. # source.sql_query_pre += [adapter.utf8_query_pre].compact if utf8?
  23. end
  24. end
  25. end
  26.  
  27.  
  28. ## Configuraçao para o Masochism
  29. # if Rails.env.production?
  30. ThinkingSphinx::Source.class_eval do
  31. # we have to overwrite this method because it tries to access
  32. # @model.connection.instance_variable_get(:@config)
  33. def set_source_database_settings(source)
  34.  
  35. ActiveReload::ConnectionProxy::setup! if Rails.env.production?
  36.  
  37. current_db_conf = @model.configurations[Rails.env]['master_database'] || @model.configurations[Rails.env]['database']
  38. config = current_db_conf.symbolize_keys
  39.  
  40. source.sql_host = config[:host] || "localhost"
  41. source.sql_user = config[:username] || config[:user] || ""
  42. source.sql_pass = (config[:password].to_s || "").gsub('#', '\#')
  43. source.sql_db = config[:database]
  44. source.sql_port = config[:port]
  45. source.sql_sock = config[:socket]
  46. end
  47. end
Add Comment
Please, Sign In to add comment