I am using ruby on rails with a MySQL backend. I have a table called notes and here is the migration I use to create it:

我在带有MySQL后端的rails上使用ruby。我有一个名为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

I want to do full text searches on the title and body fields. The problem is that the full text searches always come back empty. For example if I add this row into the database: Title: test, Body: test. Then I run this query SELECT * FROM notes WHERE MATCH(title, body) AGAINST('test'). It returns a nil set. Can anybody tell me what I am doing wrong and how to get full text search working?

我想对标题和正文字段进行全文搜索。问题是全文搜索总是空回来。例如,如果我将此行添加到数据库中:Title:test,Body:test。然后我运行这个查询SELECT * FROM notes WHERE MATCH(title,body)AGAINST('test')。它返回一个零集。任何人都可以告诉我我做错了什么以及如何使全文搜索工作?

2 个解决方案

#1


7

I'm just guessing here, but the documentation states:

我只是在这里猜测,但文档说明:

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.

自然语言搜索将搜索字符串解释为自然人类语言(自由文本中的短语)中的短语。没有特殊的运营商。禁用词列表适用。另外,存在于50%或更多行中的单词被认为是常见的并且不匹配。如果给出IN NATURAL LANGUAGE MODE修改器或者没有给出修饰符,则全文搜索是自然语言搜索。

Therefore, if there is only one row, and it contains 'test', then 'test' is present in more than 50% of the rows and is therefore not considered a match. Perhaps try:

因此,如果只有一行,并且它包含'test',则'test'存在于超过50%的行中,因此不被视为匹配。也许试试:

SELECT * FROM notes WHERE MATCH(title, body) AGAINST('test' IN BOOLEAN MODE)

更多相关文章

  1. sqlserver,mysql,oracle通用的模拟和改进的全文搜索算法
  2. [深入理解Android卷一全文-第六章]深入理解Binder

随机推荐

  1. Android 简介:Android SDK 和开发框架简介
  2. android 屏幕方向切换 锁定方向
  3. Caused by: java.lang.IllegalStateExcep
  4. Android 基础 源码 工具
  5. Android 呼吸灯流程分析(一)
  6. android中校验email是否合法
  7. Android中设置控件透明度的方法
  8. 封装的一个android底部操作弹出窗
  9. Android文档阅读03—开发工具
  10. [置顶] Android修改源代码控制不锁屏