Class: ThinkingSphinx::PostgreSQLAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/thinking_sphinx/adapters/postgresql_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



53
54
55
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 53

def boolean(value)
  value ? 'TRUE' : 'FALSE'
end

#cast_to_datetime(clause) ⇒ Object



30
31
32
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 30

def cast_to_datetime(clause)
  "cast(extract(epoch from #{clause}) as int)"
end

#cast_to_string(clause) ⇒ Object



26
27
28
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 26

def cast_to_string(clause)
  clause
end

#cast_to_unsigned(clause) ⇒ Object



34
35
36
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 34

def cast_to_unsigned(clause)
  clause
end

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



12
13
14
15
16
17
18
19
20
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 12

def concatenate(clause, separator = ' ')
  if clause[/^COALESCE/]
    clause.split('), ').join(") || '#{separator}' || ")
  else
    clause.split(', ').collect { |field|
      "CAST(COALESCE(#{field}, '') as varchar)"
    }.join(" || '#{separator}' || ")
  end
end

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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 38

def convert_nulls(clause, default = '')
  default = case default
  when String
    "'#{default}'"
  when NilClass
    'NULL'
  when Fixnum
    "#{default}::bigint"
  else
    default
  end
  
  "COALESCE(#{clause}, #{default})"
end

#crc(clause, blank_to_null = false) ⇒ Object



57
58
59
60
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 57

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

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



22
23
24
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 22

def group_concatenate(clause, separator = ' ')
  "array_to_string(array_accum(COALESCE(#{clause}, '0')), '#{separator}')"
end

#setupObject



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

def setup
  create_array_accum_function
  create_crc32_function
end

#sphinx_identifierObject



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

def sphinx_identifier
  "pgsql"
end

#time_difference(diff) ⇒ Object



66
67
68
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 66

def time_difference(diff)
  "current_timestamp - interval '#{diff} seconds'"
end

#utf8_query_preObject



62
63
64
# File 'lib/thinking_sphinx/adapters/postgresql_adapter.rb', line 62

def utf8_query_pre
  nil
end