不是所有的数据表都支持全文检索 mysql支持多种底层数据库引擎,但是并非所有的引擎支持全文检索 ,目前最常用引擎是是myisam和innodb;前者支持全文检索,后者不支持。
booolean模式操作符
| 操作符 | 含义 |
| + | 必须有 |
| - | 必须不包含 |
| > | 包含对应关键字的排名靠前 |
| < | 包含对应关键字的排名靠后 |
| ~ | 取反() |
| * | 放在词尾 类似通配符 |
| " " | 引号中间作为一个完整的值处理 |
实验:
表productnotes :

1.查询包含rabbit的行,并按照相关性排序
mysql> select note_text
-> from productnotes
-> where match(note_text) against('rabbit');
+----------------------------------------------------------------------------------------------------------------------+
| note_text |
+----------------------------------------------------------------------------------------------------------------------+
| customer complaint: rabbit has been able to detect trap, food apparently less effective now. |
| quantity varies, sold by the sack load. all guaranteed to be bright and orange, and suitable for use as rabbit bait. |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.01 sec)
2.显示每一条的相关性值
mysql> select note_text,
-> match(note_text) against('rabbit') as match_rank
-> from productnotes;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
| note_text | match_rank |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
| customer complaint:
sticks not individually wrapped, too easy to mistakenly detonate all at once.
recommend individual wrapping. | 0 |
| can shipped full, refills not available.
need to order new can if refill needed. | 0 |
| safe is combination locked, combination not provided with safe.
this is rarely a problem as safes are typically blown up or dropped by customers. | 0 |
| quantity varies, sold by the sack load.
all guaranteed to be bright and orange, and suitable for use as rabbit bait. | 1.5905543565750122 |
| included fuses are short and have been known to detonate too quickly for some customers.
longer fuses are available (item fu1) and should be recommended. | 0 |
| matches not included, recommend purchase of matches or detonator (item dtntr). | 0 |
| please note that no returns will be accepted if safe opened using explosives. | 0 |
| multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. recommend that customer considers using heavier anvils. | 0 |
| item is extremely heavy. designed for dropping, not recommended for use with slings, ropes, pulleys, or tightropes. | 0 |
| customer complaint: rabbit has been able to detect trap, food apparently less effective now. | 1.6408053636550903 |
| shipped unassembled, requires common tools (including oversized hammer). | 0 |
| customer complaint:
circular hole in safe floor can apparently be easily cut with handsaw. | 0 |
| customer complaint:
not heavy enough to generate flying stars around head of victim. if being purchased for dropping, recommend anv02 or anv03 instead. | 0 |
| call from individual trapped in safe plummeting to the ground, suggests an escape hatch be added.
comment forwarded to vendor. | 0 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
14 rows in set (0.00 sec)
3.有heavy 但是没有rope
mysql> select note_text
-> from productnotes
-> where match(note_text)
-> against('heavy -rope*' in boolean mode);
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| note_text |
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| customer complaint:
not heavy enough to generate flying stars around head of victim. if being purchased for dropping, recommend anv02 or anv03 instead. |
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)到此这篇关于mysql 全文检索的文章就介绍到这了,更多相关mysql 全文检索内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论