Class: ThinkingSphinx::OracleAdapter

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

Instance Method Summary collapse

Methods inherited from AbstractAdapter

detect

Instance Method Details

#boolean(value) ⇒ Object



42
43
44
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 42

def boolean(value)
  value ? '1' : '0'
end

#cast_to_datetime(clause) ⇒ Object

Works the same way as described here: github.com/freelancing-god/thinking-sphinx/issues#issue/13

With oracle_enhanced you can specify “time_zone” in database.yml



28
29
30
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 28

def cast_to_datetime(clause)
  "((SYSDATE + (#{clause} - timestamp '1970-01-01 00:00:00 +00:00') - SYSDATE) * 86400)"
end

#cast_to_string(clause) ⇒ Object



20
21
22
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 20

def cast_to_string(clause)
  "TO_CHAR(#{clause})"
end

#cast_to_unsigned(clause) ⇒ Object



32
33
34
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 32

def cast_to_unsigned(clause)
  "CAST(#{clause} AS NUMBER(10,0))"
end

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



12
13
14
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 12

def concatenate(clause, separator = ' ')
  clause.split(', ').collect { |field| field }.join(" || '#{separator}' || ")
end

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



36
37
38
39
40
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 36

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

#crc(clause, blank_to_null = false) ⇒ Object



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

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

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



16
17
18
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 16

def group_concatenate(clause, separator = ' ')
  "TO_STRING(CAST(COLLECT(DISTINCT TO_CHAR(#{clause})) AS SYS.ODCIVARCHAR2LIST), '#{separator}')"
end

#select_each(query) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 58

def select_each(query)
  cursor = connection.raw_connection.exec(query)
  col_names = cursor.get_col_names.collect(&:downcase)
  while values = cursor.fetch
    hash_values = Hash[*col_names.zip(values).flatten]
    yield hash_values
  end
ensure
  cursor.close if cursor
end

#setupObject



3
4
5
6
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 3

def setup
  create_group_concat_function
  create_crc32_function
end

#sphinx_identifierObject



8
9
10
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 8

def sphinx_identifier
  "odbc"
end

#time_difference(diff) ⇒ Object



54
55
56
# File 'lib/thinking_sphinx/xml/adapters/oracle_adapter.rb', line 54

def time_difference(diff)
  "SYSDATE - #{diff}/(86400)"
end

#utf8_query_preObject



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

def utf8_query_pre
  nil
end