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

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

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), '%')

ultimately, you will need to decide how to perform a fuzzy match.

for your example - you might consider removing all whitespace, and any '-' character - then perform the like '%$string%' match. you might also consider UPPER on both sides of that LIKE.

you can do more or less in your own way of determining fuzziness.