ojsimon Posted February 3, 2008 Share Posted February 3, 2008 Hi On my video site this is the code that merges the results and prepares them for displaying. <? function getall($searchterms) { <? function getall($searchterms) { require("yt.php"); require("gv.php"); require("dm.php"); require("mc.php"); $yt = yt($searchterms); $gv = gv($searchterms); $dm = dm($searchterms); $mc = mc($searchterms); $all = array_merge($yt,$gv,$dm,$mc); if(count($all)) { include_once "latest.php"; updatelatest(str_replace("+","-",$searchterms)); } $bannedwords = "bannedwords.txt"; $fp = fopen($bannedwords, "r"); $wordstmp = fread($fp, filesize($bannedwords)); fclose($fp); $words = explode("\n",$wordstmp); $words = array_map("strtolower",$words); foreach($all as $index=>$arr) { $arrtitle = $arr['title']; foreach($words as $index2=>$word) { if(strstr(strtolower($arrtitle),strtolower(str_replace("\n","",str_replace("\r","",$word))))) { unset($all[$index]); break; } } } srand((float)microtime() * 1000000); shuffle($all); foreach($all as $j=>$k) { if(!trim($k['title'])||!trim($k['link'])) unset($all[$j]); } return $all; } ?> At the moment this shuffles the results so they are in random order, i want to make them in order of relevance so i found this algorythym usort($multifeed,'funnySort'); function funnySort($a,$b) { // assign numerical value so we can sort on // whether "term" is in title or content or neither $term = 'funny'; $x = 0; if (stripos($a->get_title(),$term)) $x = 2; elseif (stripos($a->get_content(),$term)) $x = 1; $y = 0; if (stripos($b->get_title(),$term)) $y = 2; elseif (stripos($b->get_content(),$term)) $y = 1; return $x <= $y } I have tried just putting this in the place of shuffle and changing the variables, but it doesnt work, how can i make this work? any help is appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89218-using-this-algorithm-somethings-gone-wrong/ Share on other sites More sharing options...
ojsimon Posted February 4, 2008 Author Share Posted February 4, 2008 Please help Quote Link to comment https://forums.phpfreaks.com/topic/89218-using-this-algorithm-somethings-gone-wrong/#findComment-457759 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.