Sha256: 09022eee7bd2649836b2cc5eb6ba8a56d72883a8d0236f9399116f56c879ad74

Contents?: true

Size: 609 Bytes

Versions: 1

Compression:

Stored size: 609 Bytes

Contents

module MysqlSimpleFulltext
  def search_with_simple_fulltext fields
    @config = Config.new fields

    extend InstanceMethods
  end

  module InstanceMethods
    def fulltext_search query
      find_by_sql [ "SELECT *, MATCH (" + @config.fields.join(',') + ") AGAINST (?) AS fulltext_score FROM #{table_name} WHERE MATCH (" + @config.fields.join(',') + ") AGAINST (?)", query, query ]
    end

    def fulltext_config
      @config
    end
  end

  class Config
    attr_accessor :fields

    def initialize(fields)
      self.fields= fields
    end
  end
end

ActiveRecord::Base.extend MysqlSimpleFulltext

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mysql_simple_fulltext-0.0.1 lib/mysql_simple_fulltext.rb~