Class: ThinkingSphinx::MysqlAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/thinking_sphinx/adapters/mysql_adapter.rb

Instance Method Summary collapse

Methods inherited from AbstractAdapter

detect, #initialize, #quote_with_table

Constructor Details

This class inherits a constructor from ThinkingSphinx::AbstractAdapter

Instance Method Details

#boolean(value) ⇒ Object



37
38
39
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 37

def boolean(value)
  value ? 1 : 0
end

#cast_to_datetime(clause) ⇒ Object



23
24
25
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 23

def cast_to_datetime(clause)
  "UNIX_TIMESTAMP(#{clause})"
end

#cast_to_string(clause) ⇒ Object



19
20
21
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 19

def cast_to_string(clause)
  "CAST(#{clause} AS CHAR)"
end

#cast_to_unsigned(clause) ⇒ Object



27
28
29
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 27

def cast_to_unsigned(clause)
  "CAST(#{clause} AS UNSIGNED)"
end

#concatenate(clause, separator = ' ') ⇒ Object



11
12
13
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 11

def concatenate(clause, separator = ' ')
  "CONCAT_WS('#{separator}', #{clause})"
end

#convert_nulls(clause, default = '') ⇒ Object



31
32
33
34
35
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 31

def convert_nulls(clause, default = '')
  default = "'#{default}'" if default.is_a?(String)
  
  "IFNULL(#{clause}, #{default})"
end

#crc(clause, blank_to_null = false) ⇒ Object



41
42
43
44
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 41

def crc(clause, blank_to_null = false)
  clause = "NULLIF(#{clause},'')" if blank_to_null
  "CRC32(#{clause})"
end

#group_concatenate(clause, separator = ' ') ⇒ Object



15
16
17
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 15

def group_concatenate(clause, separator = ' ')
  "GROUP_CONCAT(DISTINCT IFNULL(#{clause}, '0') SEPARATOR '#{separator}')"
end

#setupObject



3
4
5
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 3

def setup
  # Does MySQL actually need to do anything?
end

#sphinx_identifierObject



7
8
9
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 7

def sphinx_identifier
  "mysql"
end

#time_difference(diff) ⇒ Object



50
51
52
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 50

def time_difference(diff)
  "DATE_SUB(NOW(), INTERVAL #{diff} SECOND)"
end

#utf8_query_preObject



46
47
48
# File 'lib/thinking_sphinx/adapters/mysql_adapter.rb', line 46

def utf8_query_pre
  "SET NAMES utf8"
end