lib/activesearch/mongoid.rb in activesearch-0.0.13 vs lib/activesearch/mongoid.rb in activesearch-0.0.14

- old
+ new

@@ -1,13 +1,17 @@ require 'activesearch/base' +require 'activesearch/proxy' require 'activesearch/mongoid/model' module ActiveSearch - # TODO: Wrap this so all engines behave consistently - def self.search(text) - text = text.split(/\s+/) - Mongoid::Model.where(:_keywords.in => text + text.map { |word| "#{I18n.locale}:#{word}"}) + def self.search(text, conditions = {}) + Proxy.new(text, conditions) do |text, conditions| + text = text.split(/\s+/) + conditions.keys.each { |k| conditions["_stored.#{k}"] = conditions.delete(k) } + conditions.merge!(:_keywords.in => text + text.map { |word| "#{I18n.locale}:#{word}"}) + Mongoid::Model.where(conditions) + end end module Mongoid def self.included(base) base.class_eval do \ No newline at end of file