Skip to content

Commit

Permalink
Updating vendored Riddle.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jul 27, 2010
1 parent 30818b7 commit 1c9d3e2
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 49 deletions.
2 changes: 2 additions & 0 deletions vendor/riddle/lib/riddle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def self.version_warning
require 'riddle/0.9.8'
# or
require 'riddle/0.9.9'
# or
require 'riddle/1.10'
}
end
Expand Down
5 changes: 5 additions & 0 deletions vendor/riddle/lib/riddle/1.10.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'riddle/0.9.9'

Riddle.loaded_version = '1.10'

require 'riddle/1.10/client'
28 changes: 28 additions & 0 deletions vendor/riddle/lib/riddle/1.10/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Riddle::Client::Versions[:search] = 0x117
Riddle::Client::Versions[:excerpt] = 0x102

class Riddle::Client
private

# Generation of the message to send to Sphinx for an excerpts request.
def excerpts_message(options)
message = Message.new

message.append [0, excerpt_flags(options)].pack('N2') # 0 = mode
message.append_string options[:index]
message.append_string options[:words]

# options
message.append_string options[:before_match]
message.append_string options[:after_match]
message.append_string options[:chunk_separator]
message.append_ints options[:limit], options[:around]
message.append_ints options[:limit_passages], options[:limit_words]
message.append_ints options[:start_passage_id]
message.append_string options[:html_strip_mode]

message.append_array options[:docs]

message.to_s
end
end
2 changes: 2 additions & 0 deletions vendor/riddle/lib/riddle/auto_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def self.configure
case version
when '0.9.8', '0.9.9'
require "riddle/#{version}"
when '1.10-beta'
require 'riddle/1.10'
end
end
end
94 changes: 62 additions & 32 deletions vendor/riddle/lib/riddle/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@ class ResponseError < StandardError; end
#
class Client
Commands = {
:search => 0, # SEARCHD_COMMAND_SEARCH
:excerpt => 1, # SEARCHD_COMMAND_EXCERPT
:update => 2, # SEARCHD_COMMAND_UPDATE
:keywords => 3, # SEARCHD_COMMAND_KEYWORDS
:persist => 4, # SEARCHD_COMMAND_PERSIST
:status => 5, # SEARCHD_COMMAND_STATUS
:query => 6 # SEARCHD_COMMAND_QUERY
:search => 0, # SEARCHD_COMMAND_SEARCH
:excerpt => 1, # SEARCHD_COMMAND_EXCERPT
:update => 2, # SEARCHD_COMMAND_UPDATE
:keywords => 3, # SEARCHD_COMMAND_KEYWORDS
:persist => 4, # SEARCHD_COMMAND_PERSIST
:status => 5, # SEARCHD_COMMAND_STATUS
:query => 6, # SEARCHD_COMMAND_QUERY
:flushattrs => 7 # SEARCHD_COMMAND_FLUSHATTRS
}

Versions = {
:search => 0x113, # VER_COMMAND_SEARCH
:excerpt => 0x100, # VER_COMMAND_EXCERPT
:update => 0x101, # VER_COMMAND_UPDATE
:keywords => 0x100, # VER_COMMAND_KEYWORDS
:status => 0x100, # VER_COMMAND_STATUS
:query => 0x100 # VER_COMMAND_QUERY
:search => 0x113, # VER_COMMAND_SEARCH
:excerpt => 0x100, # VER_COMMAND_EXCERPT
:update => 0x101, # VER_COMMAND_UPDATE
:keywords => 0x100, # VER_COMMAND_KEYWORDS
:status => 0x100, # VER_COMMAND_STATUS
:query => 0x100, # VER_COMMAND_QUERY
:flushattrs => 0x100 # VER_COMMAND_FLUSHATTRS
}

Statuses = {
Expand All @@ -72,7 +74,9 @@ class Client
:wordcount => 3, # SPH_RANK_WORDCOUNT
:proximity => 4, # SPH_RANK_PROXIMITY
:match_any => 5, # SPH_RANK_MATCHANY
:fieldmask => 6 # SPH_RANK_FIELDMASK
:fieldmask => 6, # SPH_RANK_FIELDMASK
:sph04 => 7, # SPH_RANK_SPH04
:total => 8 # SPH_RANK_TOTAL
}

SortModes = {
Expand All @@ -91,6 +95,7 @@ class Client
:bool => 4, # SPH_ATTR_BOOL
:float => 5, # SPH_ATTR_FLOAT
:bigint => 6, # SPH_ATTR_BIGINT
:string => 7, # SPH_ATTR_STRING
:multi => 0x40000000 # SPH_ATTR_MULTI
}

Expand Down Expand Up @@ -175,9 +180,9 @@ def reset
# the latitude and longitude (in radians), and the reference position.
# Note that for geocoding to work properly, you must also set
# match_mode to :extended. To sort results by distance, you will
# need to set sort_mode to '@geodist asc' for example. Sphinx
# expects latitude and longitude to be returned from you SQL source
# in radians.
# need to set sort_by to '@geodist asc', and sort_mode to extended (as an
# example). Sphinx expects latitude and longitude to be returned from you
# SQL source in radians.
#
# Example:
# client.set_anchor('lat', -0.6591741, 'long', 2.530770)
Expand Down Expand Up @@ -356,14 +361,22 @@ def query(search, index = '*', comments = '')
# 3. Pass the documents' text to +excerpts+ for marking up of matched terms.
#
def excerpts(options = {})
options[:index] ||= '*'
options[:before_match] ||= '<span class="match">'
options[:after_match] ||= '</span>'
options[:chunk_separator] ||= ' &#8230; ' # ellipsis
options[:limit] ||= 256
options[:around] ||= 5
options[:exact_phrase] ||= false
options[:single_passage] ||= false
options[:index] ||= '*'
options[:before_match] ||= '<span class="match">'
options[:after_match] ||= '</span>'
options[:chunk_separator] ||= ' &#8230; ' # ellipsis
options[:limit] ||= 256
options[:limit_passages] ||= 0
options[:limit_words] ||= 0
options[:around] ||= 5
options[:exact_phrase] ||= false
options[:single_passage] ||= false
options[:query_mode] ||= false
options[:force_all_words] ||= false
options[:start_passage_id] ||= 1
options[:load_files] ||= false
options[:html_strip_mode] ||= 'index'
options[:allow_empty] ||= false

response = Response.new request(:excerpt, excerpts_message(options))

Expand Down Expand Up @@ -425,6 +438,14 @@ def status
end
end

def flush_attributes
response = Response.new request(
:flushattrs, Message.new
)

response.next_int
end

def add_override(attribute, type, values)
@overrides[attribute] = {:type => type, :values => values}
end
Expand Down Expand Up @@ -678,13 +699,7 @@ def query_message(search, index, comments = '')
def excerpts_message(options)
message = Message.new

flags = 1
flags |= 2 if options[:exact_phrase]
flags |= 4 if options[:single_passage]
flags |= 8 if options[:use_boundaries]
flags |= 16 if options[:weight_order]

message.append [0, flags].pack('N2') # 0 = mode
message.append [0, excerpt_flags(options)].pack('N2') # 0 = mode
message.append_string options[:index]
message.append_string options[:words]

Expand Down Expand Up @@ -735,9 +750,24 @@ def attribute_from_type(type, response)
is_multi ? response.next_float_array : response.next_float
when AttributeTypes[:bigint]
is_multi ? response.next_64bit_int_arry : response.next_64bit_int
when AttributeTypes[:string]
is_multi ? response.next_array : response.next
else
is_multi ? response.next_int_array : response.next_int
end
end

def excerpt_flags(options)
flags = 1
flags |= 2 if options[:exact_phrase]
flags |= 4 if options[:single_passage]
flags |= 8 if options[:use_boundaries]
flags |= 16 if options[:weight_order]
flags |= 32 if options[:query_mode]
flags |= 64 if options[:force_all_words]
flags |= 128 if options[:load_files]
flags |= 256 if options[:allow_empty]
flags
end
end
end
16 changes: 15 additions & 1 deletion vendor/riddle/lib/riddle/configuration/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def settings_body
conf = " #{setting} = "
else
conf = setting_to_array(setting).collect { |set|
" #{setting} = #{set}"
" #{setting} = #{rendered_setting set}"
}
end
conf.length == 0 ? nil : conf
Expand All @@ -38,6 +38,20 @@ def setting_to_array(setting)
[value]
end
end

def rendered_setting(setting)
return setting unless setting.is_a?(String)

index = 8100
output = setting.clone

while index < output.length
output.insert(index, "\\\n")
index += 8100
end

output
end
end
end
end
13 changes: 0 additions & 13 deletions vendor/riddle/lib/riddle/configuration/sql_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ def initialize(name, type)
@unpack_mysqlcompress = []
end

def sql_query=(query)
unless query.nil?
max_length = 8178 # max is: 8192 - "sql_query = ".length - "\\\n".length
i = max_length
while i < query.length
i = query.rindex(" ", i)
query.insert(i, "\\" + "\n")
i = i + max_length
end
end
@sql_query = query
end

def valid?
super && (!( @sql_host.nil? || @sql_user.nil? || @sql_db.nil? ||
@sql_query.nil? ) || !@parent.nil?)
Expand Down
6 changes: 3 additions & 3 deletions vendor/riddle/lib/riddle/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(configuration, path)
end

def sphinx_version
`#{indexer} 2>&1`[/^Sphinx (\d\.\d\.\d)/, 1]
`#{indexer} 2>&1`[/^Sphinx (\d+\.\d+(\.\d+|\-beta))/, 1]
rescue
nil
end
Expand All @@ -21,15 +21,15 @@ def index(*indexes)
options = indexes.last.is_a?(Hash) ? indexes.pop : {}
indexes << '--all' if indexes.empty?

cmd = "#{indexer} --config '#{@path}' #{indexes.join(' ')}"
cmd = "#{indexer} --config \"#{@path}\" #{indexes.join(' ')}"
cmd << " --rotate" if running?
options[:verbose] ? system(cmd) : `#{cmd}`
end

def start
return if running?

cmd = "#{searchd} --pidfile --config '#{@path}'"
cmd = "#{searchd} --pidfile --config \"#{@path}\""

if RUBY_PLATFORM =~ /mswin/
system("start /B #{cmd} 1> NUL 2>&1")
Expand Down

0 comments on commit 1c9d3e2

Please sign in to comment.