我正在尝试匹配关键字,但不是很精确,一些相关的东西,我使用sql就像通配符%%类似'%mens, shoe%',将匹配每个数据与男人,男人的鞋子,甚至两者都匹配,但问题是,如果用户使用撇号符号像这样的'%men\'s, shoe%',这将只匹配记录有男鞋或有男鞋与撇号,而不会匹配男人或男人有一种方法,我可以用撇号签名匹配记录没有撇号他签名感谢任何帮助
我正在编辑我的问题并添加SQL语句
SELECT SQL_CALC_FOUND_ROWS p.product_id,p.title,p.price,p.unit_sold,p.slug,p.discount,p.free_shipping,free_return,
p.profile_img,p.store_name,p.item_number,
(
(-- Title score
if (title LIKE '%men\'s, shoe%',6,0) + if (title LIKE '%men\'s%',5,0) + if (title LIKE '%shoe%',5,0)
)+
(-- description
if (description LIKE '%men\'s, shoe%',5,0) + if (description LIKE '%men\'s%',4,0) + if (description LIKE '%shoe%',4,0)
)+
(-- item number
if (item_number = 'men\'s, shoe',4,0) + if (item_number = 'men\'s',3,0) + if (item_number = 'shoe',3,0)
)+
(-- category id
if (category_id = 'men\'s, shoe',4,0) + if (category_id = 'men\'s',3,0) + if (category_id = 'shoe',3,0)
)
) as relevance
FROM products p
WHERE p.is_active = '1'
HAVING relevance > 0
ORDER BY relevance DESC LIMIT 2,2https://stackoverflow.com/questions/51336963
复制相似问题