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
UPDATE:
来自MySQL文档:
A phrase that is enclosed within double quote (“"”)
characters matches only rows that contain the
phrase literally, as it was typed.
The full-text engine splits the phrase into words
and performs a search in the FULLTEXT index for the words.
Nonword characters need not be matched exactly:
Phrase searching requires only that matches contain exactly
the same words as the phrase and in the same order.
For example, "test phrase" matches "test, phrase".
3 回答
不要使用全文搜索价格,因为它旨在产生查询和适当文本之间的相关性 . 因此,它允许在大量文本中搜索特定关键字 . 索引包含单词的标记化版本,不能用于逐字符匹配 .
使用DECIMAL(15,4)之类的东西,将货币设置移动到单独的字段(ENUM / TINYINT)
在最坏的情况下(您不能影响表结构和插入的数据) - 您可以使用带有BTREE索引的常规CHAR / VARCHAR并通过WHERE价格LIKE ...方法进行搜索 .
这可能是你的问题,而不是
$
http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
您可以在此更改此设置 - 但请务必考虑将被编入索引的所有其他3字符字词的后果:
my.cnf
此设置:ft_min_word_len = 3
另外 - @webdevbyjoss指出了实际问题 - 如果只是为了匹配价格,这可以在全文搜索之外更好地处理 .
UPDATE 您是对的,您还需要将
$
添加为有效/包含的字符,否则将被忽略 . 来自documentation:你试图匹配3个字符串,而默认值是4(我想这也是你的情况) .
它在MySQL文档的_835335页面上说:
Any word that is too short is ignored. The default minimum length of words that are found by full-text searches is four characters.
检查this以进行微调全文搜索:
UPDATE:
来自MySQL文档:
这基本上意味着你可以尝试用双引号括起搜索短语的全文搜索,只要美元符号是你的列值中唯一的美元和价格之间的特殊字符(它们之间也没有空格),你就可以获得所需的结果 . 但是,FULLTEXT搜索用于单词搜索,并且忽略特殊字符,因此依赖于此非常危险 .
如果数据库中的更改不可能,您可以考虑使用SPHINX进行全文搜索 .