Skip to content

Commit

Permalink
Merge branch 'v1'
Browse files Browse the repository at this point in the history
Conflicts:
	thinking-sphinx.gemspec
  • Loading branch information
pat committed May 14, 2012
2 parents d5c9a61 + 3bbcc65 commit f5709b8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 45 deletions.
1 change: 1 addition & 0 deletions 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).
* STI fix when generating WHERE clauses for sql_query.
* Don't try to run rake tasks for Capistrano if there's no Rakefile - eg. on fresh deploys (Nathan Smith).
Expand Down
2 changes: 1 addition & 1 deletion thinking-sphinx.gemspec
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']

s.add_runtime_dependency 'activerecord', '>= 3.0.3'
s.add_runtime_dependency 'riddle', '>= 1.5.0'
s.add_runtime_dependency 'riddle', '>= 1.5.2'
s.add_runtime_dependency 'builder', '>= 2.1.2'

s.add_development_dependency 'actionpack', '>= 3.0.3'
Expand Down
16 changes: 8 additions & 8 deletions vendor/riddle/lib/riddle/0.9.9/client.rb
Expand Up @@ -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
Expand All @@ -43,7 +43,7 @@ def update_message(index, attributes, values_by_doc)
end
end
end

message.to_s
end
end
2 changes: 1 addition & 1 deletion vendor/riddle/lib/riddle/auto_version.rb
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions vendor/riddle/lib/riddle/client.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions vendor/riddle/lib/riddle/client/filter.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions vendor/riddle/lib/riddle/client/response.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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 f5709b8

Please sign in to comment.