vendor/riddle/lib/riddle/client.rb in ultrasphinx-1.6.7 vs vendor/riddle/lib/riddle/client.rb in ultrasphinx-1.7
- old
+ new
@@ -43,15 +43,17 @@
:retry => 2, # SEARCHD_RETRY
:warning => 3 # SEARCHD_WARNING
}
MatchModes = {
- :all => 0, # SPH_MATCH_ALL
- :any => 1, # SPH_MATCH_ANY
- :phrase => 2, # SPH_MATCH_PHRASE
- :boolean => 3, # SPH_MATCH_BOOLEAN
- :extended => 4 # SPH_MATCH_EXTENDED
+ :all => 0, # SPH_MATCH_ALL
+ :any => 1, # SPH_MATCH_ANY
+ :phrase => 2, # SPH_MATCH_PHRASE
+ :boolean => 3, # SPH_MATCH_BOOLEAN
+ :extended => 4, # SPH_MATCH_EXTENDED
+ :fullsacn => 5, # SPH_MATCH_FULLSCAN
+ :extended2 => 6 # SPH_MATCH_EXTENDED2
}
SortModes = {
:relevance => 0, # SPH_SORT_RELEVANCE
:attr_desc => 1, # SPH_SORT_ATTR_DESC
@@ -270,20 +272,24 @@
# * :before_match (defaults to <span class="match">)
# * :after_match (defaults to </span>)
# * :chunk_separator (defaults to ' … ' - which is an HTML ellipsis)
# * :limit (defaults to 256)
# * :around (defaults to 5)
+ # * :exact_phrase (defaults to false)
+ # * :single_passage (defaults to false)
#
# The defaults differ from the official PHP client, as I've opted for
# semantic HTML markup.
def excerpts(options = {})
options[:index] ||= '*'
options[:before_match] ||= '<span class="match">'
options[:after_match] ||= '</span>'
options[:chunk_separator] ||= ' … ' # ellipsis
options[:limit] ||= 256
options[:around] ||= 5
+ options[:exact_phrase] ||= false
+ options[:single_passage] ||= false
response = Response.new request(:excerpt, excerpts_message(options))
options[:docs].collect { response.next }
end
@@ -441,10 +447,16 @@
# Generation of the message to send to Sphinx for an excerpts request.
def excerpts_message(options)
message = Message.new
- message.append [0, 1].pack('N2') # mode = 0, flags = 1
+ 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_string options[:index]
message.append_string options[:words]
# options
message.append_string options[:before_match]
\ No newline at end of file