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 Link to comment https://forums.phpfreaks.com/topic/252744-mysql-search-order-help/ 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? Link to comment https://forums.phpfreaks.com/topic/252744-mysql-search-order-help/#findComment-1295877 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...? Link to comment https://forums.phpfreaks.com/topic/252744-mysql-search-order-help/#findComment-1295983 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. Link to comment https://forums.phpfreaks.com/topic/252744-mysql-search-order-help/#findComment-1296045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.