Forum Moderators: coopster

Message Too Old, No Replies

Trying to display "Related Articles"

My code is just not rendering the best results

         

kamikaze Optimizer

5:18 am on Sep 18, 2007 (gmt 0)

10+ Year Member



Hi: I am trying to display the most relevant content on my site in a related articles function. The problem is, my code is just not delivering great results.

Any pointers on where I could improve?

$boxtitle = " Related Articles";
function textAfterExclusion($OrgTextArray,$ExcludeList)
{
$NewArray=array();
$ctr=0;
for ($i=0;$i<count($OrgTextArray) ; $i++, $ctr++) {

for ($j=0;$j<count($ExcludeList) ; $j++ ) {
$flag='n';
if ($OrgTextArray[$i]==$ExcludeList[$j]) {
$flag='y';
break;
}

}
if ($flag=='n') {
$NewArray[count($NewArray)]=$OrgTextArray[$i] ;

}
}
Return $NewArray;
}// end func

$ExcludeList=Array("the", "of", "to", "and", "a", "is", "it", "for", "by", "e", "one");

$chktitle = explode(' ', $title);
$searchtitle = '';
$NewchktitleArray=textAfterExclusion($chktitle,$ExcludeList);
$NewchktitleString=implode(" ",$NewchktitleArray);
$searchtitle="(hometext like '".$NewchktitleString."') or (bodytext like '".$NewchktitleString."') or (";
$lastelement=count($chktitle);
$i=1;
foreach($chktitle as $stitle) {
if ($i==$lastelement) {

//$searchtitle.=" title like '%".$stitle."%' ";
$searchtitle.=" MATCH (title)AGAINST ('".$stitle."')";

}
else
{
//$searchtitle.=" title like '%".$stitle."%' or ";
$searchtitle.=" MATCH (title)AGAINST ('".$stitle."') or";

}
$i++;
}
$searchtitle.=") or (";
$lastelement=count($chktitle);
$i=1;
foreach($chktitle as $stitle) {
if ($i==$lastelement) {
//$searchtitle.=" hometext like '%".$stitle."%' ";
$searchtitle.=" MATCH (hometext)AGAINST ('".$stitle."')";

}
else
{
//$searchtitle.=" hometext like '%".$stitle."%' or ";
$searchtitle.=" MATCH (hometext)AGAINST ('".$stitle."') or";

}
$i++;
}
$searchtitle.=") or (";
$lastelement=count($chktitle);
$i=1;
foreach($chktitle as $stitle) {
if ($i==$lastelement) {
//$searchtitle.=" bodytext like '%".$stitle."%' ";
$searchtitle.=" MATCH (bodytext)AGAINST ('".$stitle."')";

}
else
{
//$searchtitle.=" bodytext like '%".$stitle."%' or ";
$searchtitle.=" MATCH (bodytext)AGAINST ('".$stitle."') or";

}
$i++;
}
$searchtitle.=")";
//echo($searchtitle);
$sql="select sid, title from ".$prefix."_stories where (" . $searchtitle . ") AND sid!= " . intval($sid) . " $querylang order by counter desc limit 0,20";
//echo($sql);

$resultset = $db->sql_query($sql);
$boxstuff .= "<table cellspacing='2'>";
while($row = $db->sql_fetchrow($resultset)){
//$topstory = intval($row9['sid']);
$ttitle = stripslashes(check_html($row['title'], "nohtml"));
$fsid = intval($row['sid']);
$title = stripslashes(check_html($row['title'], "nohtml"));
$arr=explode(" ",$title);
$ftitle=implode("_",$arr);
$ftitle1 = stripslashes($row['title']);
$boxstuff .= "<tr><td><a href=\"$fsid-$ftitle.html\">$ttitle</a></font></center></td></tr>";
}
$boxstuff .= "</table>";

jatar_k

12:10 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



code aside

how are you approaching the logical relationship of 'related'?

kamikaze Optimizer

8:13 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



What I did to incorporate an exclude list in search:
Preamble-1: Suppose there is a title “The sensational actor, singer and a wholesome performer Jennifer Lopez was born as Jennifer Lynn Lopez on July 24th in 1969. She is more popular as Jenny or J Lo among her fans across the world”

Preamble-2: we have an exclusion list of common such as: “the”, “of”, “to”, “and”, “a”, “is” “it”, ”as”, ”on”, “in”,”or”

Step 1: Before searching I have reframed the title after applying exclusion list.

So now the title is “sensational actor, singer wholesome performer Jennifer Lopez was born Jennifer Lynn Lopez July 24th 1969.She more popular Jenny J Lo among her fans across world”

Step2:
Now search is going on as per the following precedence
1)exact match in hometext or exact match in bodytext
2)then it is searching for title having Exact match (sensational or actor or singer wholesome or performer or Jennifer or Lopez or was or born or Jennifer or Lynn or Lopez or July or 24th or 1969 or .She or more popular or Jenny or J or Lo or among or her or fans or across or world)
3)then it is searching for hometext having Exact match (sensational or actor or singer wholesome or performer or Jennifer or Lopez or was or born or Jennifer or Lynn or Lopez or July or 24th or 1969 or .She or more popular or Jenny or J or Lo or among or her or fans or across or world)
4)then it is searching for bodytext having Exact match (sensational or actor or singer wholesome or performer or Jennifer or Lopez or was or born or Jennifer or Lynn or Lopez or July or 24th or 1969 or .She or more popular or Jenny or J or Lo or among or her or fans or across or world)