Hi
This is a script which combines many different video feeds together, at the moment you can see that it [PHP]shuffle($all);[/PHP] instead of an algorithm to sort the records, i would like to change it so that it is sorted by relevancy to a string which i could specify. Here is the whole code for the page, and bellow that is an algoryhtym which i tried to implement into the code but would not work. Can anyone either help me implement this algorithm or write one that will work with this code? [PHP]<?
function getall($searcht erms) {
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(st r_replace("+","-",$searchterms) );
}
$bannedwords = "bannedwords.tx t";
$fp = fopen($bannedwo rds, "r");
$wordstmp = fread($fp, filesize($banne dwords));
fclose($fp);
$words = explode("\n",$w ordstmp);
$words = array_map("strt olower",$words) ;
foreach($all as $index=>$arr) {
$arrtitle = $arr['title'];
foreach($words as $index2=>$word) {
if(strstr(strto lower($arrtitle ),strtolower(st r_replace("\n", "",str_replace( "\r","",$word)) ))) {
unset($all[$index]);
break;
}
}
}
srand((float)mi crotime() * 1000000);
shuffle($all);
foreach($all as $j=>$k) {
if(!trim($k['title'])||!trim($k['link']))
unset($all[$j]);
}
return $all;
}
?>[/PHP]
This is the sort of algorythym
[PHP]usort($multifee d,'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(),$t erm))
$x = 2;
elseif (stripos($a->get_content(), $term))
$x = 1;
$y = 0;
if (stripos($b->get_title(),$t erm))
$y = 2;
elseif (stripos($b->get_content(), $term))
$y = 1;
return $x <= $y
}[/PHP]
i also tried to use this code on this site http://www.webmastersherpa.com/tools/search.txt
Please can someone either help me adapt either of these algorithms or help me write one that will work with my code.
This is a script which combines many different video feeds together, at the moment you can see that it [PHP]shuffle($all);[/PHP] instead of an algorithm to sort the records, i would like to change it so that it is sorted by relevancy to a string which i could specify. Here is the whole code for the page, and bellow that is an algoryhtym which i tried to implement into the code but would not work. Can anyone either help me implement this algorithm or write one that will work with this code? [PHP]<?
function getall($searcht erms) {
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(st r_replace("+","-",$searchterms) );
}
$bannedwords = "bannedwords.tx t";
$fp = fopen($bannedwo rds, "r");
$wordstmp = fread($fp, filesize($banne dwords));
fclose($fp);
$words = explode("\n",$w ordstmp);
$words = array_map("strt olower",$words) ;
foreach($all as $index=>$arr) {
$arrtitle = $arr['title'];
foreach($words as $index2=>$word) {
if(strstr(strto lower($arrtitle ),strtolower(st r_replace("\n", "",str_replace( "\r","",$word)) ))) {
unset($all[$index]);
break;
}
}
}
srand((float)mi crotime() * 1000000);
shuffle($all);
foreach($all as $j=>$k) {
if(!trim($k['title'])||!trim($k['link']))
unset($all[$j]);
}
return $all;
}
?>[/PHP]
This is the sort of algorythym
[PHP]usort($multifee d,'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(),$t erm))
$x = 2;
elseif (stripos($a->get_content(), $term))
$x = 1;
$y = 0;
if (stripos($b->get_title(),$t erm))
$y = 2;
elseif (stripos($b->get_content(), $term))
$y = 1;
return $x <= $y
}[/PHP]
i also tried to use this code on this site http://www.webmastersherpa.com/tools/search.txt
Please can someone either help me adapt either of these algorithms or help me write one that will work with my code.
Comment