public
Description: Ambition adapter for Sphinx
Clone URL: git://github.com/technicalpickles/ambitious-sphinx.git
100644 41 lines (34 sloc) 1.073 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
30
31
32
33
34
35
36
37
38
39
40
41
module Ambition #:nodoc:
  module Adapters #:nodoc:
    module AmbitiousSphinx
      # Responsible for taking the clauses that Ambition has generated, and ultimately doing a
      # Ultrasphinx::Search based on them
      class Query < Base
        def kick
          Ultrasphinx::Search.new(to_hash).results
        end
 
        # Not entirely sure what this is for, so unimplemented so far.
        def size
          raise "Not implemented yet."
        end
 
        # Builds a hash of options for Ultrasphinx::Search based on the clauses Ambition has generated.
        def to_hash
          hash = {}
 
          unless (query = clauses[:select]).blank?
            query_s = query.join(' ').squeeze(' ').strip
            hash[:query] = quotify(query_s)
          end
          
          unless (page = clauses[:page]).blank?
            hash[:page] = page.first
          end
 
          hash
        end
 
        # Prints out the query that would be executed.
        def to_s
          hash = to_hash
          hash[:query]
        end
      end
    end
  end
end