gvp16 Posted December 8, 2011 Share Posted December 8, 2011 Hi, im doing a search which looks like this : if(isset($_GET["q"]) && $_GET["q"] !="")// get the search string { $words = explode(" ",$_GET["q"]);//explode on the spaces $count = count($words); for($i =0; $i<= $count; $i++) { if($words[$i] !="") { $qt .= "(description LIKE '%".addslashes($words[$i])."%' OR "; //build sql query $qt.= "productcode like '%".addslashes($words[$i])."%' ) AND "; } } $q = "select * FROM Main WHERE $qt stock > 0 AND wholesale = '1' AND itemStatus = '1' LIMIT 15";//run search the search works exactly as we want it, so it picks up any words with the key word in. But how can i order the results by relevance, eg. if i searched for "cat" i would get results like : dreamcatcher cat box cats picture how could i order the results so the whole word is at the top? eg. cat box casts picture dream catcher Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted December 8, 2011 Share Posted December 8, 2011 Ignoring the obvious problems with hacking together a full-text search.... why not script how you want the results ordered in php? Quote Link to comment Share on other sites More sharing options...
gvp16 Posted December 8, 2011 Author Share Posted December 8, 2011 eg. write and if statement or something that checks the results and orders them based on if they area whole word etc...? Quote Link to comment Share on other sites More sharing options...
fenway Posted December 9, 2011 Share Posted December 9, 2011 eg. write and if statement or something that checks the results and orders them based on if they area whole word etc...? Pretty much -- unless you're going to eliminate some of the before you sent them back, there's little advantage to doing the processing in the DB. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.