drvxclagw656708070 2011-07-18 19:45
浏览 29
已采纳

如何改善网站标题搜索结果

I'm a developer/designer for a community driven website: http://www.thegamesdb.net

The problem we have is quite straight forward:

Pac-Man is a game on the site. A person should be able to search "pacman" or "pac man" and the "Pac-Man" result should be shown. Currently, this does not happen.

Search code snippet is below but full code can be seen at: http://code.google.com/p/thegamesdb/source/browse/trunk/tab_listseries.php

if ($function == 'Search')
{
  $query = "SELECT g.*, p.name FROM games as g, platforms as p WHERE GameTitle LIKE '%$string%' and g.Platform = p.id";
  if(!empty($sortBy))
  {
    $query .= " ORDER BY $sortBy, GameTitle ASC";
  }
  else
  {
    $query .= " ORDER BY GameTitle";
  }
}

I'm not that familiar with coding search techniques, so any help would be appreciated... I've tried searching around on the net and all I've found is some pre-fabricated site search engines. We do not really want to go down this route... it's a little overkill for our needs.

Looking forward to some discussion,

Alex

  • 写回答

2条回答 默认 最新

  • dongqintong8972 2011-07-18 20:09
    关注

    MySQL has a string comparison feature called SOUNDS LIKE. This may be a good use case for it.

    http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#operator_sounds-like

    You would probably modify like so:

    SELECT * FROM blah WHERE SOUNDEX(column) LIKE CONCAT('%', SOUNDEX($search_string), '%')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 基于52单片机的酒精浓度检测系统加继电器和sim800
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答