Sha256: 3928c14343398fd3a613b6948f389dc975565d1c8a016541c20da98f017cf967

Contents?: true

Size: 807 Bytes

Versions: 2

Compression:

Stored size: 807 Bytes

Contents

require 'activesearch/base'
require 'activesearch/proxy'
require 'activesearch/mongoid/model'

module ActiveSearch
  
  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
        include Base
      end
    end
    
    protected
    def reindex
      ActiveSearch::Mongoid::Model.reindex(self, self.search_fields, self.search_options)
    end
    
    def deindex
      ActiveSearch::Mongoid::Model.deindex(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activesearch-0.0.15 lib/activesearch/mongoid.rb
activesearch-0.0.14 lib/activesearch/mongoid.rb