I am trying to implement a basic full-text search with MySQL.
I wrote this migration:
def self.up
execute 'ALTER TABLE photos ENGINE = MyISAM'
execute 'CREATE FULLTEXT INDEX fulltext_photos ON photos (place, info)'
end
def self.down
execute 'ALTER TABLE photos ENGINE = InnoDB'
execute 'DROP INDEX fulltext_photos ON photos'
end
And here's my model:
def self.search(*args)
options = args.extract_options!
find_by_sql [ "SELECT * FROM photos WHERE MATCH (place, info) AGAINST (?)", options[:query] ]
end
The problem is that this code always returns an empty array.
For example:
% Photo.find(:first) => Photo id: 1, place: "Baceno", info: "Era immerso in erba alta." ... % Photo.search(:all, :query => 'baceno') => []