public
Description: Ambition adapter for Sphinx
Clone URL: git://github.com/technicalpickles/ambitious-sphinx.git
Fri Feb 29 16:19:36 -0800 2008
commit  753416af4550d0bc834f7891526e128d16c116d6
tree    04f695b5f7a0f280f6006af27dc68f599e0de575
parent  c1588c2424dbf9b47f16ef40bde58d34ce0ac6a6
100644 29 lines (26 sloc) 0.668 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Ambition::Adapters::AmbitiousSphinx
  # Helper for the other
  class Base
    # Does the string have an Ultrasphinx field?
    def has_field? str
      str =~ /:/
    end
    
    # Does the string have any Ultrasphinx operators?
    def has_operator? str
      str =~ /(AND|OR|NOT)/
    end
    
    # Should this string be quotified? It needs to happen if the string doesn't
    # have an operator or a field.
    def needs_quoting? str
      not (has_operator?(str) or has_field?(str))
    end
    
    # Quote the string if it needs it.
    def quotify str
      if needs_quoting?(str)
        %Q("#{str}")
      else
        str
      end
    end
  end
end