MySQL全文檢索的實(shí)現(xiàn)示例
不是所有的數(shù)據(jù)表都支持全文檢索 MySQL支持多種底層數(shù)據(jù)庫(kù)引擎,但是并非所有的引擎支持全文檢索 ,目前最常用引擎是是MyISAM和InnoDB;前者支持全文檢索,后者不支持。
booolean模式操作符
操作符 | 含義 |
+ | 必須有 |
- | 必須不包含 |
> | 包含對(duì)應(yīng)關(guān)鍵字的排名靠前 |
< | 包含對(duì)應(yīng)關(guān)鍵字的排名靠后 |
~ | 取反() |
* | 放在詞尾 類似通配符 |
" " | 引號(hào)中間作為一個(gè)完整的值處理 |
實(shí)驗(yàn):
表productnotes :
1.查詢包含rabbit的行,并按照相關(guān)性排序
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.顯示每一條的相關(guān)性值
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 但是沒(méi)有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)
到此這篇關(guān)于MySQL 全文檢索的文章就介紹到這了,更多相關(guān)MySQL 全文檢索內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mysql將查詢結(jié)果集轉(zhuǎn)換為JSON數(shù)據(jù)的實(shí)例代碼
這篇文章主要介紹了Mysql將查詢結(jié)果集轉(zhuǎn)換為JSON數(shù)據(jù)的實(shí)例代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03MySQL百萬(wàn)數(shù)據(jù)深度分頁(yè)優(yōu)化思路解析
這篇文章主要為大家介紹了MySQL百萬(wàn)數(shù)據(jù)深度分頁(yè)優(yōu)化思路分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05mysql中數(shù)據(jù)庫(kù)與數(shù)據(jù)表編碼格式的查看、創(chuàng)建及修改
這篇文章給大家介紹了如何查看、創(chuàng)建以及修改數(shù)據(jù)庫(kù)與數(shù)據(jù)表的編碼格式,另外還給大家分享了添加和刪除外鍵的示例代碼,文中介紹的很詳細(xì),對(duì)大家的理解和學(xué)習(xí)具有一定的參考借鑒價(jià)值,有需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2016-11-11詳解MySQL查看執(zhí)行慢的SQL語(yǔ)句(慢查詢)
查看執(zhí)行慢的SQL語(yǔ)句,需要先開啟慢查詢?nèi)罩荆琈ySQL的慢查詢?nèi)罩?,記錄在MySQL中響應(yīng)時(shí)間超過(guò)閥值的語(yǔ)句(具體指運(yùn)行時(shí)間超過(guò)long_query_time值的SQL,本文給大家介紹MySQL查看執(zhí)行慢的SQL語(yǔ)句,感興趣的朋友跟隨小編一起看看吧2024-03-03配置Mysql主從服務(wù)實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了配置Mysql主從服務(wù)實(shí)現(xiàn)實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05mysql把一段數(shù)據(jù)變成一個(gè)臨時(shí)表
這篇文章主要介紹了mysql把一段數(shù)據(jù)變成一個(gè)臨時(shí)表,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-02-02一個(gè) 20 秒 SQL 慢查詢優(yōu)化處理方案
這篇文章主要分享一個(gè) 20 秒 SQL 慢查詢優(yōu)化的經(jīng)歷與處理方案,頁(yè)面無(wú)法正確獲取數(shù)據(jù),經(jīng)排查原來(lái)是接口調(diào)用超時(shí),而最后發(fā)現(xiàn)是因?yàn)镾QL查詢長(zhǎng)達(dá)到20多秒而導(dǎo)致了問(wèn)題的發(fā)生,下面來(lái)看問(wèn)題具體介紹吧2022-01-01