【问题标题】:MATCH AGAINST Mysql not giving correct resultsMATCH AGAINST Mysql 没有给出正确的结果
【发布时间】:2014-04-08 13:17:55
【问题描述】:

我正在运行如下 SQL 查询:

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 或更多,而我至少需要一次。

但同样的结果即将到来。我想如果有多个单词要匹配,那么它应该匹配 name 中的所有单词。

 MATCH (a.name) AGAINST ('blue +cushion')

【问题讨论】:

标签: mysql search full-text-search match


【解决方案1】:

您必须使用 IN BOOLEAN MODE 修饰符,因为默认情况下 MySQL 执行 natural language search

使用此修饰符,某些字符在 搜索字符串中单词的开头或结尾。

来源:Boolean Full-Text Searches

只需像这样重写您的查询:

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

【讨论】:

  • 它不工作。它给了我零记录,而我的产品名称为“DEAUVILLE red VELVET 褶皱靠垫”
  • 这两个词不一定要在一起。它们可以在名称中的任何位置,但两个词必须在名称中。 '+' 符号表示 0 或更多,而我至少需要一次。
  • @user3110655 - '+'-符号不表示 0 或更多,它表示 必须 一词。如果您不需要将两个单词作为一个精确的短语放在一起,但希望两个单词都存在,无论如何,请省略 "(双引号)并在第二个单词中添加一个 '+'-sign。'+blue +cushion'
  • 我尝试了同样的方法,但没有成功。 :(。它给我的结果只有 suhion,例如“SINTRA 紫色天鹅绒贴花垫”
猜你喜欢
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-01
  • 1970-01-01
相关资源
最近更新 更多