我在 MySQL 后端使用 ruby on rails。我有一个名为 notes 的表,这是我用来创建它的迁移:
def self.up
create_table(:notes, :options => 'ENGINE=MyISAM') do |t|
t.string :title
t.text :body
t.timestamps
end
execute "alter table notes ADD FULLTEXT(title, body)"
end
我想对标题和正文字段进行全文搜索。问题是全文搜索总是返回空的。例如,如果我将这一行添加到数据库中:Title: test, Body: test
。然后我运行此查询 SELECT * FROM notes WHERE MATCH(title, body) AGAINST('test')
。它返回一个零集。任何人都可以告诉我我做错了什么以及如何使全文搜索正常工作吗?
最佳答案
我只是猜测,但文档指出:
A natural language search interprets the search string as a phrase in natural human language (a phrase in free text). There are no special operators. The stopword list applies. In addition, words that are present in 50% or more of the rows are considered common and do not match. Full-text searches are natural language searches if the IN NATURAL LANGUAGE MODE modifier is given or if no modifier is given.
因此,如果只有一行,并且包含“test”,则“test”出现在超过 50% 的行中,因此不被视为匹配项。也许尝试:
SELECT * FROM notes WHERE MATCH(title, body) AGAINST('test' IN BOOLEAN MODE)
关于sql - mysql全文搜索为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/371372/