vendor/riddle/lib/riddle/client.rb in ultrasphinx-1.7 vs vendor/riddle/lib/riddle/client.rb in ultrasphinx-1.8
- old
+ new
@@ -30,13 +30,13 @@
:excerpt => 1, # SEARCHD_COMMAND_EXCERPT
:update => 2 # SEARCHD_COMMAND_UPDATE
}
Versions = {
- :search => 0x10F, # VER_COMMAND_SEARCH
+ :search => 0x112, # VER_COMMAND_SEARCH
:excerpt => 0x100, # VER_COMMAND_EXCERPT
- :update => 0x100 # VER_COMMAND_UPDATE
+ :update => 0x101 # VER_COMMAND_UPDATE
}
Statuses = {
:ok => 0, # SEARCHD_OK
:error => 1, # SEARCHD_ERROR
@@ -52,10 +52,16 @@
:extended => 4, # SPH_MATCH_EXTENDED
:fullsacn => 5, # SPH_MATCH_FULLSCAN
:extended2 => 6 # SPH_MATCH_EXTENDED2
}
+ RankModes = {
+ :proximity_bm25 => 0, # SPH_RANK_PROXIMITY_BM25
+ :bm25 => 1, # SPH_RANK_BM25
+ :none => 2 # SPH_RANK_NONE
+ }
+
SortModes = {
:relevance => 0, # SPH_SORT_RELEVANCE
:attr_desc => 1, # SPH_SORT_ATTR_DESC
:attr_asc => 2, # SPH_SORT_ATTR_ASC
:time_segments => 3, # SPH_SORT_TIME_SEGMENTS
@@ -87,11 +93,12 @@
}
attr_accessor :server, :port, :offset, :limit, :max_matches,
:match_mode, :sort_mode, :sort_by, :weights, :id_range, :filters,
:group_by, :group_function, :group_clause, :group_distinct, :cut_off,
- :retry_count, :retry_delay, :anchor
+ :retry_count, :retry_delay, :anchor, :index_weights, :rank_mode,
+ :max_query_time, :field_weights
attr_reader :queue
# Can instantiate with a specific server and port - otherwise it assumes
# defaults of localhost and 3312 respectively. All other settings can be
# accessed and changed via the attribute accessors.
@@ -117,10 +124,14 @@
@retry_count = 0
@retry_delay = 0
@anchor = {}
# string keys are index names, integer values are weightings
@index_weights = {}
+ @rank_mode = :proximity_bm25
+ @max_query_time = 0
+ # string keys are field names, integer values are weightings
+ @field_weights = {}
@queue = []
end
# Set the geo-anchor point - with the names of the attributes that contain
@@ -179,11 +190,11 @@
end
matches = response.next_int
is_64_bit = response.next_int
for i in 0...matches
- doc = is_64_bit > 0 ? (response.next_int() << 32) + response.next_int : response.next_int
+ doc = is_64_bit > 0 ? response.next_64bit_int : response.next_int
weight = response.next_int
result[:matches] << {:doc => doc, :weight => weight, :index => i, :attributes => {}}
result[:attribute_names].each do |attr|
case result[:attributes][attr]
@@ -342,11 +353,11 @@
response = ""
status = -1
version = 0
length = 0
message = Array(messages).join("")
-
+
connect do |socket|
case command
when :search
# Message length is +4 to account for the following count value for
# the number of messages (well, that's what I'm assuming).
@@ -395,11 +406,12 @@
# Generation of the message to send to Sphinx for a search.
def query_message(search, index)
message = Message.new
# Mode, Limits, Sort Mode
- message.append_ints @offset, @limit, MatchModes[@match_mode], SortModes[@sort_mode]
+ message.append_ints @offset, @limit, MatchModes[@match_mode],
+ RankModes[@rank_mode], SortModes[@sort_mode]
message.append_string @sort_by
# Query
message.append_string search
@@ -409,11 +421,12 @@
# Index
message.append_string index
# ID Range
- message.append_ints 0, @id_range.first, @id_range.last
+ message.append_int 1
+ message.append_64bit_ints @id_range.first, @id_range.last
# Filters
message.append_int @filters.length
@filters.each { |filter| message.append filter.query_message }
@@ -440,10 +453,20 @@
@index_weights.each do |key,val|
message.append_string key
message.append_int val
end
+ # Max Query Time
+ message.append_int @max_query_time
+
+ # Per Field Weights
+ message.append_int @field_weights.length
+ @field_weights.each do |key,val|
+ message.append_string key
+ message.append_int val
+ end
+
message.to_s
end
# Generation of the message to send to Sphinx for an excerpts request.
def excerpts_message(options)
@@ -478,10 +501,10 @@
message.append_string index
message.append_array attributes
message.append_int values_by_doc.length
values_by_doc.each do |key,values|
- message.append_int key # document ID
+ message.append_64bit_int key # document ID
message.append_ints *values # array of new values (integers)
end
message.to_s
end
\ No newline at end of file