我将稍微改进一下这个问题。
description列包含一堆文本中的$15,USD15。
在布尔模式下使用全文搜索,但返回空结果
select * from books WHERE MATCH (description) select(在布尔模式下为‘USD$15’);空集合(0.00秒)
但
select * from books WHERE MATCH (description) select(布尔模式下的‘USD15’);
是成功的......
发布于 2013-09-06 23:01:04
不要对价格使用全文搜索,因为它的设计目的是在查询和适当的文本之间产生相关性。因此,它允许在大量文本中搜索特定的关键字。索引包含单词的标记化版本,不能用于逐个字符匹配。
使用类似DECIMAL(15,4)的代码,并将货币设置移动到单独的字段(ENUM/TINYINT)
在最坏的情况下(您不能影响表结构和插入的数据)-您可以使用常规的CHAR/VARCHAR与BTREE索引和搜索通过WHERE price LIKE ...接近。
发布于 2013-09-06 23:05:21
这可能是你的问题,而不是$
某些单词在全文搜索中被忽略:任何太短的单词都将被忽略。全文搜索找到的单词的默认最小长度为四个字符。
http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
您可以在此处更改此设置-但请务必考虑将被索引的所有其他3个字符的单词的后果:此设置上的my.cnf:ft_min_word_len = 3
还有- @webdevbyjoss钉钉实际问题-如果只是为了匹配价格,这更好地在全文搜索之外处理。
更新您是正确的,您还需要将$添加为有效的/包含的字符,否则它将被忽略。从documentation
如果要更改被视为单词字符的字符集,可以使用多种方法进行更改,如以下列表中所述。进行修改后,必须为包含所有全文索引的每个表重新生成索引。假设您想要将连字符('-')视为单词字符。使用以下方法之一:
发布于 2013-09-06 23:06:08
您正在尝试匹配3个字符的字符串,而默认值是4(我猜这也适用于您的情况)。
它在MySQL文档的this页面上写道:
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以微调全文搜索:
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更新:
来自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".这基本上意味着您可以尝试全文搜索将搜索短语括在双引号中,只要美元符号是您的列值中USD和price之间的唯一特殊字符(它们之间也没有空格),您就可以获得所需的结果。然而,全文搜索是为单词搜索而进行的,特殊字符被忽略了,因此依赖这种搜索是非常有风险的。
如果不可能在数据库中进行更改,也许您可以考虑使用SPHINX进行全文搜索。
https://stackoverflow.com/questions/18660603
复制相似问题