Class: RtSphinx::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/rt_sphinx/query.rb

Instance Method Summary collapse

Constructor Details

#initializeQuery

Returns a new instance of Query.



6
7
8
# File 'lib/rt_sphinx/query.rb', line 6

def initialize
  @connection = RtSphinx::Connection.instance
end

Instance Method Details

#insert(index, *values) ⇒ Object



15
16
17
18
19
20
# File 'lib/rt_sphinx/query.rb', line 15

def insert(index, *values)
  item_id = rand(10_000)*rand(9_888)
  values_str = values.map{|v| "'#{v}'"}.join(', ')
  insert_sql = "INSERT INTO #{index} (id, timestamp, message, logjson) VALUES (#{item_id}, #{values_str})"
  @connection.execute_sql(insert_sql, 'insert')
end

#select(index, clause) ⇒ Object



10
11
12
13
# File 'lib/rt_sphinx/query.rb', line 10

def select(index, clause)
  select_sql = "SELECT * FROM #{index} WHERE #{clause}"
  @connection.execute_sql(select_sql, 'select')
end