Class: Sphinx::Request
- Inherits:
-
Object
- Object
- Sphinx::Request
- Defined in:
- lib/sphinx/sphinx/request.rb
Overview
Pack ints, floats, strings, and arrays to internal representation needed by Sphinx search engine.
Instance Method Summary collapse
-
#initialize ⇒ Request
constructor
Initialize new request.
-
#put_float(*floats) ⇒ Object
Put float(s) to request.
-
#put_int(*ints) ⇒ Object
Put int(s) to request.
-
#put_int64(*ints) ⇒ Object
Put 64-bit int(s) to request.
-
#put_int64_array(arr) ⇒ Object
Put array of 64-bit ints to request (first length, then the array itself).
-
#put_int_array(arr) ⇒ Object
Put array of ints to request (first length, then the array itself).
-
#put_string(*strings) ⇒ Object
Put string(s) to request (first length, then the string itself).
-
#to_s ⇒ Object
Returns the entire message.
Constructor Details
#initialize ⇒ Request
Initialize new request.
6 7 8 |
# File 'lib/sphinx/sphinx/request.rb', line 6 def initialize @request = '' end |
Instance Method Details
#put_float(*floats) ⇒ Object
Put float(s) to request.
26 27 28 29 30 31 32 |
# File 'lib/sphinx/sphinx/request.rb', line 26 def put_float(*floats) floats.each do |f| t1 = [f].pack('f') # machine order t2 = t1.unpack('L*').first # int in machine order @request << [t2].pack('N') end end |
#put_int(*ints) ⇒ Object
Put int(s) to request.
11 12 13 |
# File 'lib/sphinx/sphinx/request.rb', line 11 def put_int(*ints) ints.each { |i| @request << [i].pack('N') } end |
#put_int64(*ints) ⇒ Object
Put 64-bit int(s) to request.
16 17 18 |
# File 'lib/sphinx/sphinx/request.rb', line 16 def put_int64(*ints) ints.each { |i| @request << [i].pack('q').reverse }#[i >> 32, i & ((1 << 32) - 1)].pack('NN') } end |
#put_int64_array(arr) ⇒ Object
Put array of 64-bit ints to request (first length, then the array itself)
40 41 42 43 |
# File 'lib/sphinx/sphinx/request.rb', line 40 def put_int64_array(arr) put_int arr.length put_int64(*arr) end |
#put_int_array(arr) ⇒ Object
Put array of ints to request (first length, then the array itself)
35 36 37 |
# File 'lib/sphinx/sphinx/request.rb', line 35 def put_int_array(arr) put_int arr.length, *arr end |
#put_string(*strings) ⇒ Object
Put string(s) to request (first length, then the string itself).
21 22 23 |
# File 'lib/sphinx/sphinx/request.rb', line 21 def put_string(*strings) strings.each { |s| @request << [s.length].pack('N') + s } end |
#to_s ⇒ Object
Returns the entire message
46 47 48 |
# File 'lib/sphinx/sphinx/request.rb', line 46 def to_s @request end |