negationst8 Posted February 17, 2010 Share Posted February 17, 2010 Hi, I am using a software which allows users to post advertisements. Unfortunately, the search function of the software isn't very sophisticated. For example, if there is an advertisement for a "black car with six gears" and a user performs a search on "black gears" the ad will appear in the search results. However, if a user performs a search on "gears black" the ad will not appear. I want the ad to be retrieved no matter what order a user types in the keywords. The code I need to manipulate is this: if(trim(preg_replace("/[\s,]+/", '', $text_search)) != '') { $keywords = preg_split("/[\s,]+/", $text_search); $keywords = array_unique($keywords); $search .= ' AND ('; $prefix = ''; for($i = 0; $i < count($keywords); $i++) { $search .= $prefix."a.ad_text LIKE '%".$keywords[$i]."%' "; $prefix = 'OR '; } $search .= ') AND a.published = 1'; } else { $search .= ' AND a.published = 1'; } Thank you for all your help. James Link to comment https://forums.phpfreaks.com/topic/192378-how-to-make-search-form-retrieve-results-no-matter-what-order-of-keywords/ Share on other sites More sharing options...
jl5501 Posted February 17, 2010 Share Posted February 17, 2010 I would strongly suggest that you have a fulltext index on your keywords field and then use MATCH... AGAINST ... sql to perform the search see http://dev.mysql.com/doc/refman/5.1/en/fulltext-fine-tuning.html Link to comment https://forums.phpfreaks.com/topic/192378-how-to-make-search-form-retrieve-results-no-matter-what-order-of-keywords/#findComment-1013711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.