keep in mind this is completely untested, and may not have the intended result at all:
Code:
#
# Generate additional fields string
#
$add_fields_string = '';
$scorestr="";
// Add score to fields - LNJ
if (!empty($data["by_title"]) && count($search_words)>0) {
$scorestr.="if($sql_tbl[products].product like '%". $data["substring"] ."%',5,0) + "; //Add high score for exact match - LNJ
$topscore=4; // Yeah I know HARDCODED - LNJ
$scoredesc=$topscore/count($search_words); //Get decrementing number for scores - LNJ
foreach($search_words as $search_word){
$scorestr.="if($sql_tbl[products].product like '%". $search_word ."%',$topscore,0) + "; //add individual word score - LNJ
// $topscore=$topscore-$scoredesc; //Descrement individual score for word - LNJ
}
}
if (!empty($data["by_shortdescr"]) && count($search_words)>0) {
$scorestr.="if($sql_tbl[products].descr like '%". $data["substring"] ."%',3,0) + "; //Add high score for exact match - LNJ
$topscore=2;
$scoredesc=$topscore/count($search_words); //Get decrementing number for scores - LNJ
foreach($search_words as $search_word){
$scorestr.="if($sql_tbl[products].descr like '%". $search_word ."%',$topscore,0) + "; //add individual word score - LNJ
// $topscore=$topscore-$scoredesc;//Descrement individual score for word - LNJ
}
}
if (!empty($data["by_longdescr"]) && count($search_words)>0) {
$scorestr.="if($sql_tbl[products].fulldescr like '%". $data["substring"] ."%',3,0) + "; //Add high score for exact match - LNJ
$topscore=2;
$scoredesc=$topscore/count($search_words); //Get decrementing number for scores - LNJ
foreach($search_words as $search_word){
$scorestr.="if($sql_tbl[products].fulldescr like '%". $search_word ."%',$topscore,0) + "; //add individual word score - LNJ
// $topscore=$topscore-$scoredesc;//Descrement individual score for word - LNJ
}
}
$add_fields[]=$scorestr . " 0 as searchscore"; // Add this field to the list - LNJ
if(!empty($add_fields) && @is_array($add_fields)) {
$add_fields_string = ", ".implode(", ", $add_fields);
}