Class: ActiveRecord::Extensions::FullTextSearching::MySQLFullTextExtension

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ar-extensions/fulltext/mysql.rb

Overview

This adds FullText searching functionality for the MySQLAdapter.

Constant Summary collapse

RGX =
/^match_(.+)/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register(fulltext_key, options) ⇒ Object

:nodoc:



8
9
10
11
# File 'lib/ar-extensions/fulltext/mysql.rb', line 8

def register( fulltext_key, options ) # :nodoc:
  @fulltext_registry ||= ActiveRecord::Extensions::Registry.new
  @fulltext_registry.register( fulltext_key, options )
end

.registryObject

:nodoc:



13
14
15
# File 'lib/ar-extensions/fulltext/mysql.rb', line 13

def registry # :nodoc:
  @fulltext_registry
end

Instance Method Details

#process(key, val, caller) ⇒ Object

:nodoc:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ar-extensions/fulltext/mysql.rb', line 22

def process( key, val, caller ) # :nodoc:
  match_data = key.to_s.match( RGX )
  return nil unless match_data
  fulltext_identifier = match_data.captures[0].to_sym
  if self.class.registers?( fulltext_identifier )
    fields = self.class.registry.options( fulltext_identifier )[:fields]
    str = "MATCH ( #{fields.join( ',' )} ) AGAINST (#{caller.connection.quote(val)})"
    return ActiveRecord::Extensions::Result.new( str, nil )
  end
  nil
end