public
Description: Ambition adapter for Sphinx
Clone URL: git://github.com/technicalpickles/ambitious-sphinx.git
100644 23 lines (20 sloc) 0.386 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Ambition::Adapters::AmbitiousSphinx
  class Base
    def has_field? str
      str =~ /:/
    end
    
    def has_operator? str
      str =~ /(AND|OR|NOT)/
    end
    
    def needs_quoting? str
      not (has_operator?(str) or has_field?(str))
    end
    
    def quotify str
      if needs_quoting?(str)
        %Q("#{str}")
      else
        str
      end
    end
  end
end