【问题标题】:Function not searching for a specific word函数不搜索特定单词
【发布时间】:2010-03-03 08:32:18
【问题描述】:

这很奇怪,但我的搜索功能可以从我的项目表中搜索除单词“grinder”之外的任何单词。我已经尝试了一切,但它似乎没有搜索那个词。谁能帮帮我?

CREATE FULLTEXT INDEX item_name_other_name_desc_index 
    ON item (name,other_name,description) 

public static function Search($string) 
{    

    $delims = ',.; '; 
        $word = strtok($string,$delims); 
        while($word) 
        { 

           $result['accepted'][] = $word;                    
           $word = strtok($delims); 

        } 

          $string = implode(" ", $result['accepted']); 

    $sql = 'SELECT item_id,name,other_name,description,price,discounted_price, thumbnail_photo,large_photo 
    FROM item 
    WHERE  
    MATCH(name,other_name,description) 
    AGAINST(:string)' ; 
    $parameters = array(':string' => $string); 
    $result['items'] = DB::GetAll($sql,$parameters); 
    return $result; 
} 

物品名称: 9 合 15 安培电机角磨机
8 台式磨床
1/4 英寸角模磨床
7 英寸角磨机
3 直磨床
Ryobi HP512K 无绳电钻/起子套件
6 件装喷漆
非接触式电压测试仪

当我将以上内容更改为:
9 合 15 安培电机角磨机
8 在台式研磨
1/4 英寸角模研磨
7 英寸角磨
3 直磨
Ryobi HP512K 无绳电钻/起子套件
6 件装喷漆
非接触式电压测试仪

我搜索 Grinder,记录 => 9 In 15 AMP Motor Angle Grinder 正在显示。

【问题讨论】:

  • 能否提供item中的数据示例?
  • 你能显示一个示例记录吗?
  • 我想我找到了问题所在。我的表项中有 7 项。其中 5 个名为 Grinder。当我搜索 Grinder 时,它没有显示任何结果。当我将名为 Grinder 的项目中的 4 个更改为 Grind 时,然后我搜索 Grinder,它显示项目 Grinder .. 我很困惑!!

标签: php mysql search


【解决方案1】:

默认情况下,mysql全文搜索将出现在50%以上的单词或行视为停用词(http://dev.mysql.com/doc/refman/5.1/en/fulltext-natural-language.html)。尝试在布尔模式 (http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html) 下搜索,您没有 50% 的阈值。

【讨论】:

    【解决方案2】:

    如果 Grinder 这个词在文本中移动,那么“15 AMP Motor Angle Grinder”会变成“15 AMP Motor Angle Grinder Test”,会有什么不同吗?我问这个是因为 Grinder 总是这个名字的最后一部作品。

    我不是全文搜索方面的专家,但这是我要开始的地方。

    【讨论】:

      猜你喜欢
      • 2016-05-20
      • 2019-12-29
      • 2015-05-22
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      相关资源
      最近更新 更多