php - 当使用匹配语句使用转义斜杠时,Mysql 不返回结果

标签 php mysql match full-text-search

我有一条记录,其中 firstname 等于 \。由于某种原因,它没有返回给我记录。

SELECT 
    firstname,lastname,middlename,
    primary_emailaddress,alternate_emailaddress,personal_address_line1,
    personal_address_line2,personal_address_city,facebook_username,
    twitter_username,googleplus_username,linkedin_username,
    personal_website_url,birthday_month,notes,personal_address_zipcode,
    company_address_zipcode,home_phonenumber,company_phonenumber,
    cell_phonenumber,birthday_day,birthday_year,hash 
FROM contacts 
WHERE (
        MATCH( firstname,middlename,lastname,
            primary_emailaddress,alternate_emailaddress,personal_address_line1,
            personal_address_line2,personal_address_city,facebook_username,
            twitter_username,googleplus_username,linkedin_username,
            personal_website_url,birthday_month,notes ) AGAINST ('\\*' IN BOOLEAN MODE) 
        OR personal_address_zipcode REGEXP('(\\*)') 
        OR company_address_zipcode REGEXP('(\\*)') 
        OR home_phonenumber REGEXP('(\\*)') 
        OR company_phonenumber REGEXP('(\\*)') 
        OR cell_phonenumber REGEXP('(\\*)') 
        OR birthday_day REGEXP('(\\*)') 
        OR birthday_year REGEXP('(\\*)') 
    ) 
AND addressbook_id = 4

最佳答案

问题是,默认情况下,非常短的单词不会被索引。 Here是文档:

The minimum and maximum lengths of words to be indexed are defined by the ft_min_word_len and ft_max_word_len system variables. (See Section 5.1.4, “Server System Variables”.) The default minimum value is four characters; the default maximum is version dependent. If you change either value, you must rebuild your FULLTEXT indexes. For example, if you want three-character words to be searchable, you can set the ft_min_word_len variable by putting the following lines in an option file:

[mysqld]
ft_min_word_len=3

这适用于 bool 搜索和自然语言。您将需要更改选项并重建索引。

或者,您可以为 firstname 输入一个 regexp 表达式:

    OR firstname REGEXP('(\\*)') 

关于php - 当使用匹配语句使用转义斜杠时,Mysql 不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17936875/

相关文章:

php - 字段中包含数组的新表或字段 (php/mysql)

Javascript 搜索标签并获取它的 innerHTML

php - 如何查询第一个和最后一个日期

javascript - 如何默认隐藏表单并在点击时显示

php - 使用 shell_exec 时连接被拒绝

mysql - 将具有 rowid 和 rownum 的 Oracle 查询转换为 MySQL 查询

arrays - 确定数组/字符串中最大匹配序列的有效方法(在 Ruby 中)?

MySQL 匹配和喜欢

php - 我需要从 mysql_query 转换为 PDO 的帮助

php - Codeigniter 从数据库中删除行