简体   繁体   English

全文索引无法正常工作

[英]Fulltext Index does not work properly

this is my first post although I read your threads on a regular base. 这是我的第一篇文章,尽管我定期阅读您的主题。

The problem I face has to do with the FULLTEXT index on a table of mine. 我面临的问题与我的表上的FULLTEXT索引有关。 You can see the procedure I followed below: 您可以在下面看到我遵循的过程:

CREATE TABLE dost(
  author VARCHAR(30),
  title VARCHAR(40),
  isbn SMALLINT NOT NULL)ENGINE MyISAM;

ALTER TABLE dost ADD FULLTEXT(author);

ALTER TABLE dost ADD FULLTEXT(author);

ALTER TABLE dost ADD FULLTEXT(author);

After I inserted some data into the table, it looked something like this: 将一些数据插入表后,它看起来像这样:

author                 title                               isbn

Fyodor Dostoyevsky     Poor Folk                           225125
Fyodor Dostoyevsky     Crime and Punishment                121320
Fyodor Dostoyevsky     The Gambler                         124239
Rowan Williams         Dostoyevsky                         083409
Joseph Frank           Dostoyevsky: A Writer In His Time   089823

The problem occurs when I try to use the MATCH AGAINST command to the author column. 当我尝试对作者列使用MATCH AGAINST命令时,会出现问题。 To be more specific, when I type 更具体地说,当我输入

SELECT author,title FROM dost WHERE MATCH(author) AGAINST('Williams');

I get the expected result ( Rowan Williams Dostoyevsky ) BUT when I follow the same procedure and change the AGAINST input from 'Williams' to 'Dostoyevsky' it outputs an empty set as a result. 当我遵循相同的过程并将AGAINST输入从'Williams'更改为'Dostoyevsky'时,我得到了预期的结果(Rowan Williams Dostoyevsky)但它输出一个空集。 On the other hand, the FULLTEXT index on the title column works fine. 另一方面,标题列上的FULLTEXT索引可以正常工作。 Any ideas why this problem is caused? 任何想法为什么会导致此问题?

Thanks for your time! 谢谢你的时间!

You're doing what is called a natural language search. 您正在执行所谓的自然语言搜索。 In this type of search, any word that is in 50% or more of the rows will be ignored as a "common value." 在这种类型的搜索中,行中50%或更多的任何单词都将被忽略为“公共值”。 Reference . 参考

If that limitation isn't what you want, then you'll need to do a boolean full-text search instead, like this: 如果该限制不是您想要的,那么您将需要进行布尔型全文本搜索,如下所示:

SELECT author,title FROM dost WHERE MATCH(author) AGAINST('+Dostoyevsky' IN BOOLEAN MODE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM