Class: Ambition::Adapters::AmbitiousSphinx::Query
- Defined in:
- lib/ambition/adapters/ambitious_sphinx/query.rb
Overview
Responsible for taking the clauses that Ambition has generated, and ultimately doing a Ultrasphinx::Search based on them
Instance Method Summary collapse
- #kick ⇒ Object
-
#page(number) ⇒ Object
Some magic to add pagination.
-
#size ⇒ Object
Not entirely sure when this is used, so unimplemented so far.
-
#to_hash ⇒ Object
Builds a hash of options for Ultrasphinx::Search based on the clauses Ambition has generated.
-
#to_s ⇒ Object
Prints out the query that would be executed.
Methods inherited from Base
#has_field?, #has_operator?, #needs_quoting?, #quotify
Instance Method Details
#kick ⇒ Object
7 8 9 |
# File 'lib/ambition/adapters/ambitious_sphinx/query.rb', line 7 def kick Ultrasphinx::Search.new(to_hash).results end |
#page(number) ⇒ Object
Some magic to add pagination. This gets called if you were to do:
Meal.select {'bacon'}.page(5)
When page
is invoked, it’s actually being invoked on Ambition::Context
. It has method_missing
? voodoo which will try to pass the method onto the Query
. That’s this class.
18 19 20 21 |
# File 'lib/ambition/adapters/ambitious_sphinx/query.rb', line 18 def page(number) stash[:page] = number context end |
#size ⇒ Object
Not entirely sure when this is used, so unimplemented so far.
24 25 26 |
# File 'lib/ambition/adapters/ambitious_sphinx/query.rb', line 24 def size raise "Not implemented yet." end |
#to_hash ⇒ Object
Builds a hash of options for Ultrasphinx::Search based on the clauses Ambition has generated.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ambition/adapters/ambitious_sphinx/query.rb', line 29 def to_hash hash = {} unless (query = clauses[:select]).blank? query_s = query.join(' ').squeeze(' ').strip hash[:query] = quotify(query_s) end unless (page = stash[:page]).blank? hash[:page] = page end hash end |
#to_s ⇒ Object
Prints out the query that would be executed.
45 46 47 48 |
# File 'lib/ambition/adapters/ambitious_sphinx/query.rb', line 45 def to_s hash = to_hash hash[:query] end |