MYSQL 数据中有个文本字段maintext包含一段文章,现在我要进行关键词搜索
“PYTHON 程序员 能力”,希望优先返回包含“PYTHON程序员能力”类似的字段
也就是多个关键词靠的越近排名越靠前。求支招。
用regexp
https://blog.csdn.net/qq_31747765/article/details/90174482
给数据库连接加个分词器插件
可以用elasticsearch或ik
ik比较简单点,使用方法百度上都有
select *
from(
select
column1,column2,...
case when instr(maintext字段,'PYTHON')>0 then 1 else 0 end +
case when instr(maintext字段,'程序员')>0 then 1 else 0 end +
case when instr(maintext字段,'能力')>0 then 1 else 0 end +
case when instr(maintext字段,'PYTHON程序员能力')>0 then 999 else 0 end num
from table
) aa order by aa.num desc;
大概思路,提取关键字一步可以自己切割一下
用locate函数查出关键词在字段中位置,然后再根据位置的差来排序吧
我也感觉你说的情况用elasticsearch会简单点,如果后续需求很多这种类似搜索业务,就更要选择es了