php mysql 包含字符串_使用包含关键字的字符串在PHP中进行MySql全...

正如MySQL手册所说:

A phrase that is enclosed within double quote (“””) characters matches

only rows that contain the phrase literally, as it was typed.

我们来看一下示例表:

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)

当我们删除引号时,它将搜索包含“database”或“comparison”字样的行:

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”或短语“database comparison”的行,我们应该使用此请求:

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中,但会被忽略.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值