Sha256: 61573518153d8a238be139b5240e090f4146db7099534f306ade350d320d1663

Contents?: true

Size: 637 Bytes

Versions: 3

Compression:

Stored size: 637 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 (?) ORDER BY fulltext_score ASC", 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

3 entries across 3 versions & 1 rubygems

Version Path
mysql_simple_fulltext-0.0.3 lib/mysql_simple_fulltext.rb
mysql_simple_fulltext-0.0.2 lib/mysql_simple_fulltext.rb
mysql_simple_fulltext-0.0.1 lib/mysql_simple_fulltext.rb