Here is my code that extend ThinkingSphinx::Search class to support SPH_SORT_EXPR mode via :sort_expr option.
Feel free to tweak the code at RefactorMyCode.com
module ThinkingSphinx
class Search
class << self
alias_method :original_set_sort_options!, :set_sort_options!
def set_sort_options!(client, options)
expr = options[:sort_expr]
if expr.nil?
original_set_sort_options!(client, options)
else
client.sort_mode = :expr
client.sort_by = expr
end
end
end # class << self
end # Search
end # ThinkingSphinx
Usage: Model.search("search string", :sort_expr => "sort expression")
Find out more about my Thinking Sphinx's bug fixes and extenstions here:
http://github.com/tiendung/thinking-sphinx/wikis
No comments:
Post a Comment