SELECT * FROM `a_admin_shichang`  WHERE title REGEXP '农业|新华'
缺点
在数据量比较大或传入的参数数量比较多时,SQL执行效率会降低,建议控制传入的参数数量,或将此类数据存入搜索引擎Elasticsearch效果更好。

SELECT * FROM article WHERE 
title REGEXP "车|摩托|红色|美国|2006"
OR subtitle REGEXP "车|摩托|红色|美国|2006"
OR tag REGEXP "车|摩托|红色|美国|2006"

SELECT * FROM article WHERE 
CONCAT_WS(" ", title, subtitle, tag) REGEXP "车|摩托|红色|美国|2006"

SELECT *,
(
    (IF( CONCAT_WS(" ", title, subtitle, tag) LIKE "%车%", 1, 0))
    + (IF( CONCAT_WS(" ", title, subtitle, tag) LIKE "%摩托%", 1, 0))
    + (IF( CONCAT_WS(" ", title, subtitle, tag) LIKE "%红色%", 1, 0))
    + (IF( CONCAT_WS(" ", title, subtitle, tag) LIKE "%美国%", 1, 0))
    + (IF( CONCAT_WS(" ", title, subtitle, tag) LIKE "%2006%", 1, 0))
) AS keyweight
FROM article WHERE 
CONCAT_WS(" ", title, subtitle, tag) REGEXP "车|摩托|红色|美国|2006"
ORDER BY keyweight DESC

MySQL实现多关键词模糊搜索,搜索结果按照匹配关键词的多少来排序


要是把数字转成字符串再拼合就没事了:

SELECT * FROM article WHERE 
CONCAT_WS("", CHAR(time), title) REGEXP "关键词"

参考网站
https://blog.csdn.net/lsk0909/article/details/126466580
http://lao.si/120

发表评论 已发布 0

还可以输入 800 个字
 
 
打印