Skip to content

Commit

Permalink
ruby 1.9 compatibility for scalars used in :with and :without options
Browse files Browse the repository at this point in the history
  • Loading branch information
khaled committed Apr 1, 2011
1 parent c3915cc commit 8233d90
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/mongoid_sphinx/mongoid/sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,25 @@ def search(query, options = {})

if options.key?(:with)
options[:with].each do |key, value|
client.filters << Riddle::Client::Filter.new(key.to_s, value.is_a?(Range) ? value : value.to_a, false)
client.filters << build_sphinx_filter(key, value, false)
end
end

if options.key?(:without)
options[:without].each do |key, value|
client.filters << Riddle::Client::Filter.new(key.to_s, value.is_a?(Range) ? value : value.to_a, true)
client.filters << build_sphinx_filter(key, value, true)
end
end

result = client.query("#{query} @classname #{self.to_s}")
MongoidSphinx::Search.new(client, self, result)
end

def build_sphinx_filter(key, value, exclude)
values = (value.is_a?(Range) || value.is_a?(Array)) ? value : [value]
Riddle::Client::Filter.new(key.to_s, values, exclude)
end

end

end
Expand Down

0 comments on commit 8233d90

Please sign in to comment.