5071c5b861341c0dcfcf6ac86327701f

Recently, I need to extend ThinkingSphinx::Search class to support sort by expresion (via :sort_expr option). Here is my straight forward code. Is there any better way?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel