在 MySQL 中,您是否尝试过使用
MATCH() 和 AGAINST() 函数的组合
我猜他们会产生你正在寻找的结果。
例如
对于以下数据集::
mysql> select * from temp;
+----+---------------------------------------------+
| id | string |
+----+---------------------------------------------+
| 1 | James Wood is the matyr. |
| 2 | Wood James is the saviour. |
| 3 | James thames are rhyming words. |
| 4 | Wood is a natural product. |
| 5 | Don't you worry child - Swedish House Mafia |
+----+---------------------------------------------+
5 rows in set (0.00 sec)
如果您需要 james 或 wood 存在,此查询将返回以下结果
mysql> select string from temp where match (string) against ('james wood' in bo
olean mode);
+---------------------------------+
| string |
+---------------------------------+
| James Wood is the matyr. |
| Wood James is the saviour. |
| James thames are rhyming words. |
| Wood is a natural product. |
+---------------------------------+
4 rows in set (0.00 sec)
如果您要求 James 和 Wood 这两个词都应该出现,则此查询将起作用。注意单词前的“+”号。检查这个布尔模式
mysql> select string from temp where match (string) against ('+james +wood' in b
oolean mode);
+----------------------------+
| string |
+----------------------------+
| James Wood is the matyr. |
| Wood James is the saviour. |
+----------------------------+
2 rows in set (0.00 sec)
查找具有任何后缀的单词,它的工作方式类似
mysql> select string from temp where match (string) against ('Jame*' in boolean
mode);
+---------------------------------+
| string |
+---------------------------------+
| James Wood is the matyr. |
| Wood James is the saviour. |
| James thames are rhyming words. |
+---------------------------------+
3 rows in set (0.02 sec)
但请注意,Mysql 的全文搜索尚不支持前缀搜索
mysql> select string from temp where match (string) against ('*ame*' in boolean
mode);
Empty set (0.00 sec)
我希望这有帮助。
顺便说一句,这个回复很晚,但我有足够的兴趣来回复。
要了解更多信息,请查看此链接http://dev.mysql.com/doc/refman/5.5/en//fulltext-search.html