Mysql全文搜索特定单词

时间:2013-03-20 08:27:27

标签: php mysql

tag1 - Novel, My pession, Holi, Book, My book, Having book
tag2 - Holi Novel, My pession, Book, My book, Having book
tag3 - Romantic Novel, My Novel, Book, My book, Having book
tag4 - Novel based, My Novel, Book, My book, Having book
tag5 - Ovel based, My Novel, Book, My book, Having book, Novel
tag6 - Based, My Novel, Book, Novel, Having book, Presume

我想只搜索那些Novel的标签。它应该是搜索tag1tag5 在全文搜索

3 个答案:

答案 0 :(得分:2)

WHERE
    tag1 REGEXP '(^|, )[[:<:]]Novel[[:>:]](,|$)' AND
    tag5 REGEXP '(^|, )[[:<:]]Novel[[:>:]](,|$)'

答案 1 :(得分:1)

我通常以下列方式存储每个关键字

,Novel,My Passion,Holi, 

即。逗号在开头和字符串结尾处,所以现在可以在'%,Novel,%'命令中搜索LIKE而不是Novel,它就像魅力一样。

答案 2 :(得分:1)

SELECT * FROM your_table 主题如“小说”

UNION

SELECT * FROM your_table 主题是“小说,%”

UNION

SELECT * FROM your_table 主题LIKE'%,Novel,%'

UNION

SELECT * FROM your_table 主题LIKE'%,Novel'