我正在运行SQL Query,如下所示:
SELECT a.id as id,a.name as name , a.price as price , a.saleprice as saleprice, a.images as images, a.slug as slug,a.hover_name as hover_name, MATCH (a.name) AGAINST ('+"blue cushion"') AS title_relevance FROM gc_products a WHERE ( ( ( MATCH (a.name) AGAINST ('+"blue cushion"') ) OR (a.sku like '%blue cushion%') ) and (a.enabled=1) ) ORDER BY title_relevance DESC
但它给了我错误的结果,它也向我展示了名字就像"蓝色蜡烛" ,"红色垫子"
我也试过
MATCH (a.name) AGAINST ('blue cushion')
MATCH (a.name) AGAINST ('+blue cushion')
MATCH (a.name) AGAINST ('+blue +cushion')
这两个词在一起并不是必要的。它们可以是名称中的任何一个,但两个词必须在名称中。 ' +'当我需要至少一次时,符号表示0或更多。
但同样的结果即将到来。我想如果要匹配多个单词,那么它应匹配名称中的所有单词。
MATCH (a.name) AGAINST ('blue +cushion')
答案 0 :(得分:0)
您必须使用IN BOOLEAN MODE
修饰符,因为默认情况下MySQL会执行natural language search。
使用此修饰符,某些字符具有特殊含义 搜索字符串中单词的开头或结尾。
只需重写您的查询:
SELECT a.id as id,a.name as name , a.price as price , a.saleprice as saleprice,
a.images as images, a.slug as slug,a.hover_name as hover_name,
MATCH (a.name) AGAINST ('+"blue cushion"' IN BOOLEAN MODE) AS title_relevance
FROM gc_products a
WHERE ( ( ( MATCH (a.name) AGAINST ('+"blue cushion"' IN BOOLEAN MODE) )
OR (a.sku like '%blue cushion%') )
AND (a.enabled=1) )
ORDER BY title_relevance DESC