我有一条记录,其中 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/