Browse files

Updating Riddle references to 1.5.2

  • Loading branch information...
1 parent a8a63b8 commit 3bbcc65d681e9b1709302f648fb0598de4918131 @pat pat committed May 14, 2012
View
1 HISTORY
@@ -1,4 +1,5 @@
Edge:
+* Updating Riddle references to 1.5.2.
* Can explicitly specify available types for STI tables instead of automatically discovering them with "SELECT DISTINCT type FROM <table>" (Cedric Maion).
* Don't try to run rake tasks for Capistrano if there's no Rakefile - eg. on fresh deploys (Nathan Smith).
* Populate search results before comparing with #==.
View
2 thinking-sphinx.gemspec
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'activerecord', ['< 3.0.0', '>= 1.15.6']
s.add_runtime_dependency 'after_commit', '>= 1.0.7'
- s.add_runtime_dependency 'riddle', '>= 1.5.0'
+ s.add_runtime_dependency 'riddle', '>= 1.5.2'
s.add_development_dependency 'appraisal', '0.4.0'
s.add_development_dependency 'cucumber', '1.0.2'
View
16 vendor/riddle/lib/riddle/0.9.9/client.rb
@@ -3,33 +3,33 @@
class Riddle::Client
private
-
+
def initialise_connection
socket = initialise_socket
# Send version
socket.send [1].pack('N'), 0
-
+
# Checking version
version = socket.recv(4).unpack('N*').first
if version < 1
socket.close
- raise VersionError, "Can only connect to searchd version 1.0 or better, not version #{version}"
+ raise Riddle::VersionError, "Can only connect to searchd version 1.0 or better, not version #{version}"
end
-
+
socket
end
-
+
def update_message(index, attributes, values_by_doc)
message = Message.new
-
+
message.append_string index
message.append_int attributes.length
attributes.each_with_index do |attribute, index|
message.append_string attribute
message.append_boolean values_by_doc.values.first[index].is_a?(Array)
end
-
+
message.append_int values_by_doc.length
values_by_doc.each do |key,values|
message.append_64bit_int key # document ID
@@ -43,7 +43,7 @@ def update_message(index, attributes, values_by_doc)
end
end
end
-
+
message.to_s
end
end
View
2 vendor/riddle/lib/riddle/auto_version.rb
@@ -10,7 +10,7 @@ def self.configure
require 'riddle/1.10'
when /2.0.[12]/
require 'riddle/2.0.1'
- when /2.0.3/, /2.1.\d/
+ when /2.0.3/, /2.0.4/, /2.1.\d/
require 'riddle/2.1.0'
end
end
View
10 vendor/riddle/lib/riddle/client.rb
@@ -136,7 +136,7 @@ def self.connection
end
# Can instantiate with a specific server and port - otherwise it assumes
- # defaults of localhost and 3312 respectively. All other settings can be
+ # defaults of localhost and 9312 respectively. All other settings can be
# accessed and changed via the attribute accessors.
def initialize(servers = nil, port = nil, key = nil)
Riddle.version_warning
@@ -165,7 +165,7 @@ def reset
@filters = []
@group_by = ''
@group_function = :day
- @group_clause = '@group desc'
+ @group_clause = '@weight DESC'
@group_distinct = ''
@cut_off = 0
@retry_count = 0
@@ -495,15 +495,17 @@ def close
def open_socket
raise "Already Connected" unless @socket.nil?
+ available_servers = servers.dup
+
if @timeout == 0
@socket = initialise_connection
else
begin
Timeout.timeout(@timeout) { @socket = initialise_connection }
rescue Timeout::Error, Riddle::ConnectionError => e
failed_servers ||= []
- failed_servers << servers.shift
- retry if !servers.empty?
+ failed_servers << available_servers.shift
+ retry if !available_servers.empty?
case e
when Timeout::Error
View
27 vendor/riddle/lib/riddle/client/filter.rb
@@ -2,21 +2,21 @@ module Riddle
class Client
class Filter
attr_accessor :attribute, :values, :exclude
-
+
# Attribute name, values (which can be an array or a range), and whether
# the filter should be exclusive.
def initialize(attribute, values, exclude=false)
@attribute, @values, @exclude = attribute, values, exclude
end
-
+
def exclude?
self.exclude
end
-
+
# Returns the message for this filter to send to the Sphinx service
def query_message
message = Message.new
-
+
message.append_string self.attribute.to_s
case self.values
when Range
@@ -28,21 +28,26 @@ def query_message
append_integer_range message, self.values
end
when Array
- message.append_int FilterTypes[:values]
- message.append_int self.values.length
- append_array message, self.values
+ if self.values.first.is_a?(Float) && self.values.length == 1
+ message.append_int FilterTypes[:float_range]
+ message.append_floats self.values.first, self.values.first
+ else
+ message.append_int FilterTypes[:values]
+ message.append_int self.values.length
+ append_array message, self.values
+ end
end
message.append_int self.exclude? ? 1 : 0
-
+
message.to_s
end
-
+
private
-
+
def append_integer_range(message, range)
message.append_ints self.values.first, self.values.last
end
-
+
# Using to_f is a hack from the PHP client - to workaround 32bit signed
# ints on x32 platforms
def append_array(message, array)
View
38 vendor/riddle/lib/riddle/client/response.rb
@@ -10,81 +10,81 @@ def initialize(str)
@str = str
@marker = 0
end
-
+
# Return the next string value in the stream
def next
len = next_int
result = @str[@marker, len]
@marker += len
-
+
Riddle.encode(result)
end
-
+
# Return the next integer value from the stream
def next_int
int = @str[@marker, 4].unpack('N*').first
@marker += 4
-
+
int
end
-
+
def next_64bit_int
high, low = @str[@marker, 8].unpack('N*N*')[0..1]
@marker += 8
-
+
(high << 32) + low
end
-
+
# Return the next float value from the stream
def next_float
float = @str[@marker, 4].unpack('N*').pack('L').unpack('f*').first
@marker += 4
-
+
float
end
-
+
# Returns an array of string items
def next_array
count = next_int
items = []
count.times do
items << self.next
end
-
+
items
end
-
+
# Returns an array of int items
def next_int_array
count = next_int
items = []
count.times do
items << self.next_int
end
-
+
items
end
-
+
def next_float_array
count = next_int
items = []
count.times do
items << self.next_float
end
-
+
items
end
-
+
def next_64bit_int_array
- count = next_int
+ byte_count = next_int
items = []
- count.times do
+ (byte_count / 2).times do
items << self.next_64bit_int
end
-
+
items
end
-
+
# Returns the length of the streamed data
def length
@str.length
View
2 vendor/riddle/lib/riddle/version.rb
@@ -1,3 +1,3 @@
module Riddle
- Version = '1.5.1'
+ Version = '1.5.2'
end

0 comments on commit 3bbcc65

Please sign in to comment.