我有一個MySQL-query由FULLTEXT
-indexes組成,因爲我需要一個相關性排序。 缺點是,我需要有模式匹配像MySQL-FULLTEXT模式匹配
SELECT * FROM table WHERE colum LIKE %word%
有沒有辦法在FULLTEXT
-searches來實現這一點?
我有一個MySQL-query由FULLTEXT
-indexes組成,因爲我需要一個相關性排序。 缺點是,我需要有模式匹配像MySQL-FULLTEXT模式匹配
SELECT * FROM table WHERE colum LIKE %word%
有沒有辦法在FULLTEXT
-searches來實現這一點?
這裏是你如何使用MySQL full Text search:
在這裏,您不必爲打破更大的輸入字符串轉換成數組與每個單詞進行比較。
請參考下面的例子來寫自己:
是雙引號括起來(「「」)字符的短語匹配的
只是字面上包含該短語的行,因爲它是鍵入
我想解釋你有關Boolean Full Text Search;不過,我勸你請通過Full Text Search using Query Expansion也
讓我們看看示例表:
mysql> select * from articles;
+----+-----------------------+------------------------------------------+
| id | title | body |
+----+-----------------------+------------------------------------------+
| 1 | PostgreSQL Tutorial | DBMS stands for DataBase ... |
| 2 | How To Use MySQL Well | After you went through a ... |
| 3 | Optimizing MySQL | In this tutorial we will show ... |
| 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... |
| 5 | MySQL vs. YourSQL | In the following database comparison ... |
| 6 | MySQL Security | When configured properly, MySQL ... |
+----+-----------------------+------------------------------------------+
mysql> SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('"database comparison"' IN BOOLEAN MODE);
+----+-------------------+------------------------------------------+
| id | title | body |
+----+-------------------+------------------------------------------+
| 5 | MySQL vs. YourSQL | In the following database comparison ... |
+----+-------------------+------------------------------------------+
訂購事宜,當時的話被引用:
mysql> SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('"comparison database"' IN BOOLEAN MODE);
Empty set (0.01 sec)
當我們去掉引號,它將搜索行,包含單詞「數據庫」或「比較」:
mysql> SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('database comparison' IN BOOLEAN MODE);
+----+---------------------+------------------------------------------+
| id | title | body |
+----+---------------------+------------------------------------------+
| 1 | PostgreSQL Tutorial | DBMS stands for DataBase ... |
| 5 | MySQL vs. YourSQL | In the following database comparison ... |
+----+---------------------+------------------------------------------+
順序並不重要,現在:
mysql> SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('comparison database' IN BOOLEAN MODE);
+----+---------------------+------------------------------------------+
| id | title | body |
+----+---------------------+------------------------------------------+
| 1 | PostgreSQL Tutorial | DBMS stands for DataBase ... |
| 5 | MySQL vs. YourSQL | In the following database comparison ... |
+----+---------------------+------------------------------------------+
如果我們想要得到的行,包含無論是單詞「的PostgreSQL」或短語「數據庫的比較」,我們應該用這個請求:
mysql> SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('PostgreSQL "database comparison"' IN BOOLEAN MODE);
+----+---------------------+------------------------------------------+
| id | title | body |
+----+---------------------+------------------------------------------+
| 1 | PostgreSQL Tutorial | DBMS stands for DataBase ... |
| 5 | MySQL vs. YourSQL | In the following database comparison ... |
+----+---------------------+------------------------------------------+
確保,這樣的詞語,你正在搜索,不在list of stopwords中,那些被忽略。
在全文搜索中,您可以使用'*'進行通配符搜索。所以說你有'aabbbbcc,bbbb,bbbbxyz'的數據,你可以使用布爾模式作爲匹配(列)針對('bbbb *'IN布爾模式)' – 2015-03-02 10:43:17