Sha256: 8124d2aa6b2e43cacc21079f3d65a21e10c5c405d46a6db55ae626a527e71ec3

Contents?: true

Size: 537 Bytes

Versions: 1

Compression:

Stored size: 537 Bytes

Contents

module ActiveSearch
  module Mongoid
    def self.included(base)
      base.extend ClassMethods
    end
    
    module ClassMethods
      def search_on(*fields)
        field :_keywords, type: Array
        index :_keywords
        
        before_save do
          self._keywords = []
          
          fields.each do |f|
            self._keywords = self._keywords | self[f].downcase.split if self[f]
          end
        end
      end
      
      def fts(query)
        all_in(_keywords: query.split)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activesearch-0.0.1 lib/activesearch/mongoid.rb