riddle 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/riddle/client.rb +34 -22
- metadata +3 -3
data/lib/riddle/client.rb
CHANGED
@@ -575,6 +575,34 @@ module Riddle
|
|
575
575
|
socket
|
576
576
|
end
|
577
577
|
|
578
|
+
def request_header(command, length = 0)
|
579
|
+
length += key_message.length if key
|
580
|
+
core_header = case command
|
581
|
+
when :search
|
582
|
+
# Message length is +4/+8 to account for the following count value for
|
583
|
+
# the number of messages.
|
584
|
+
if Versions[command] >= 0x118
|
585
|
+
[Commands[command], Versions[command], 8 + length].pack("nnN")
|
586
|
+
else
|
587
|
+
[Commands[command], Versions[command], 4 + length].pack("nnN")
|
588
|
+
end
|
589
|
+
when :status
|
590
|
+
[Commands[command], Versions[command], 4, 1].pack("nnNN")
|
591
|
+
else
|
592
|
+
[Commands[command], Versions[command], length].pack("nnN")
|
593
|
+
end
|
594
|
+
|
595
|
+
key ? core_header + key_message : core_header
|
596
|
+
end
|
597
|
+
|
598
|
+
def key_message
|
599
|
+
@key_message ||= begin
|
600
|
+
message = Message.new
|
601
|
+
message.append_string key
|
602
|
+
message.to_s
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
578
606
|
# Send a collection of messages, for a command type (eg, search, excerpts,
|
579
607
|
# update), to the Sphinx daemon.
|
580
608
|
def request(command, messages)
|
@@ -588,36 +616,20 @@ module Riddle
|
|
588
616
|
message = message.force_encoding('ASCII-8BIT')
|
589
617
|
end
|
590
618
|
|
591
|
-
if key
|
592
|
-
prefix = Message.new
|
593
|
-
prefix.append_string key
|
594
|
-
message = prefix.to_s + message
|
595
|
-
end
|
596
|
-
|
597
619
|
connect do |socket|
|
598
620
|
case command
|
599
621
|
when :search
|
600
|
-
# Message length is +4 to account for the following count value for
|
601
|
-
# the number of messages (well, that's what I'm assuming).
|
602
622
|
if Versions[command] >= 0x118
|
603
|
-
socket.send
|
604
|
-
|
605
|
-
8+message.length, messages.length, 0
|
606
|
-
].pack("nnNNN") + message, 0
|
623
|
+
socket.send request_header(command, message.length) +
|
624
|
+
[messages.length, 0].pack('NN') + message, 0
|
607
625
|
else
|
608
|
-
socket.send
|
609
|
-
|
610
|
-
4+message.length, messages.length
|
611
|
-
].pack("nnNN") + message, 0
|
626
|
+
socket.send request_header(command, message.length) +
|
627
|
+
[messages.length].pack('N') + message, 0
|
612
628
|
end
|
613
629
|
when :status
|
614
|
-
socket.send
|
615
|
-
Commands[command], Versions[command], 4, 1
|
616
|
-
].pack("nnNN"), 0
|
630
|
+
socket.send request_header(command, message.length), 0
|
617
631
|
else
|
618
|
-
socket.send
|
619
|
-
Commands[command], Versions[command], message.length
|
620
|
-
].pack("nnN") + message, 0
|
632
|
+
socket.send request_header(command, message.length) + message, 0
|
621
633
|
end
|
622
634
|
|
623
635
|
header = socket.recv(8)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: riddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.3.
|
5
|
+
version: 1.3.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pat Allan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-12 00:00:00 +10:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
hash:
|
139
|
+
hash: -2415930395284714044
|
140
140
|
segments:
|
141
141
|
- 0
|
142
142
|
version: "0"
|