Forum Moderators: coopster
I have implemented MySQL Full-text Searching in boolean mode.
To retrieve the searchstring I use
$search = trim(mysql_escape_string($HTTP_GET_VARS['search'])); To execute the search I use
function getProductsbySearch($search){
$rs = mysql_query("SELECT *, MATCH(name, description) AGAINST ('$search') AS score FROM tbgameseek WHERE MATCH(name, description) AGAINST ('$search' IN BOOLEAN MODE) ORDER BY score DESC") or die(mysql_error());
return $rs;
} To highlight the searchstring in the results I use
$row['description']=eregi_replace(($search), '<b>'.strtoupper($search).'</b>', $row['description']); Highlighting works fine but
(1)only for single word searches without boolean operators.
At present I mention this in the FAQs of the site under construction, but I will be much obliged to anyone who has a more elegant solution.
(2)not when an ignorant user, no offence intended, searches for something like
+command +star which will produce Warning: eregi_replace(): REG_BADRPT in c:\easyphp1-8 for every result on the body of my page. + and ( have this detrimental effect) before using the eregi_replace method. I suspect that there is an elegant way of solving both problems in one go, for I have seen searches on shopping sites that do exactly what I desire, even highlighting multiple words of a default search in boolean mode.
I am looking forward to receive all well meant reactions.