【问题标题】:mysql ft_min_word_len change on ubuntu does not workubuntu 上的 mysql ft_min_word_len 更改不起作用
【发布时间】:2014-06-24 19:33:11
【问题描述】:

我正在尝试实现完整的测试搜索。为此,我首先将 /etc/mysql/my.cnf 上 ft_min_word_len = 2 的值更改为

[mysqld]
#
# * Basic Settings
#

#
# * IMPORTANT
#   If you make changes to these settings and your system uses apparmor, you may
#   also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
ft_min_word_len = 2

现在保存并重新启动服务器。 我知道,如果我已经在表中有一个带有 FULLTEXT 的索引,我将需要删除索引并重建或修复表。 但我已将表格创建为

create table 
`comments` 
(   `id` int(11), 
    `comment` varchar(200), 
    `iduser` int(11) , 
    `date_added` datetime
) 
ENGINE=MyISAM;

ALTER TABLE comments
ADD FULLTEXT INDEX comment_index
(comment);

然后在上表中我手动添加了一些 cmets。

当我尝试以

的形式搜索某些内容时
SELECT * FROM comments where MATCH (comment) AGAINST ('the') ; // "the" is very common word of length to see my test result

它返回 0 行。

但是,如果我将 AGAINST 设置为 4 字长,它会起作用。

我试图检查 ft_ 变量为

mysql>  show variables like 'ft_%';
+--------------------------+----------------+
| Variable_name            | Value          |
+--------------------------+----------------+
| ft_boolean_syntax        | + -><()~*:""&| |
| ft_max_word_len          | 84             |
| ft_min_word_len          | 2              |
| ft_query_expansion_limit | 20             |
| ft_stopword_file         | (built-in)     |
+--------------------------+----------------+

有趣的是/etc/mysql/my.cnf 我只能看到ft_min_word_lenft_max_word_len 不存在,更重要的是,小于长度 4 的搜索根本不起作用。

这让我发疯了,不确定是否还有其他配置写完所有内容并且似乎也无法找到它们。

任何帮助将不胜感激。

我的开发机中的Mysql版本是

mysql  Ver 14.14 Distrib 5.1.63, for debian-linux-gnu (i686) using readline 6.2  

【问题讨论】:

    标签: mysql ubuntu full-text-search


    【解决方案1】:

    我能够找到问题和修复方法。

    全文搜索设置很好,因为我想用 alt east 2 个词搜索,我有 ft_min_word_len = 2

    现在在进行更多测试时,我发现它会随机搜索几个 2 个字符的单词而忽略其他单词。

    这是一个例子

    CREATE TABLE articles (
        id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
        title VARCHAR(200),
        body TEXT,
        FULLTEXT (title,body)
    );
    
    INSERT INTO articles (title,body) VALUES
    ('MySQL Tutorial','DBMS stands for DataBase ...'),
    ('How To Use MySQL Well','After you went through a ...'),
    ('Optimizing MySQL','In this tutorial we will show ...'),
    ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
    ('MySQL vs. YourSQL','In the following database comparison ...'),
    ('MySQL Security','When configured properly, MySQL ...');
    
    mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('use');
    Empty set (0.00 sec)
    
    mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('Use');
    Empty set (0.00 sec)
    
    mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('you');
    Empty set (0.00 sec)
    
    mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('the');
    Empty set (0.00 sec)
    
    mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('vs.');
    Empty set (0.00 sec)
    

    但以下工作

    mysql> SELECT * FROM articles
        -> WHERE MATCH (title,body) AGAINST ('run');
    +----+-------------------+-------------------------------------+
    | id | title             | body                                |
    +----+-------------------+-------------------------------------+
    |  4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... |
    +----+-------------------+-------------------------------------+
    

    所以它是别的东西,显然找到了它的 ft_stopword_file,它有一个单词列表,如果其中一个发生任何搜索,它不会做任何事情。

    名单在这里http://dev.mysql.com/doc/refman/5.1/en/fulltext-stopwords.html

    所以在这种情况下,允许任何长度至少为 2 个字符的单词搜索

    • 将 ft_min_word_len 设置为 2
    • 然后在 mysql 配置文件中,为 debian /etc/mysql/my.cnf 添加 ft_stopword_file='path/to/stopword_file.txt'
    • 如果需要,我们可以将此文件留空。

    哦还有一件事,一旦我们做了上述设置,我们需要重新启动 mysql,如果我们更改ft_min_word_len,那么我们需要重新构建索引或修复表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 2017-04-25
      • 1970-01-01
      • 2011-06-08
      • 2014-10-12
      • 1970-01-01
      相关资源
      最近更新 更多