rendered paste body $query = "SELECT * FROM {$pre}faq WHERE category <> '-1'";
if ( $_GET[search] ){
$search_query .= " &&";
$more_terms = 0;
$keywords = str_word_count($_GET[search],1);
for ($i = str_word_count($_GET[search])-1; $i >= 0; $i--){
if ( $more_terms == "1" ) { $search_query .= " &&"; }
$search_query .= " ( description LIKE '%$keywords[$i]%' || symptoms LIKE '%$keywords[$i]%' || solution LIKE '%$keywords[$i]%' )";
$more_terms = "1";
}
}
$query .= $search_query;
$query .= " ORDER BY description";
$res = mysql_query( $query );
if( !mysql_num_rows( $res ) )
echo "{$LANG[faq_no_results]}";
else
{
$results = array();
while( $row = mysql_fetch_array( $res ) )
{
$desc_count = $symptoms_count = $solution_count = 0;
// lylix // initialize and populate keywords array
$keywords = str_word_count($_GET[search],1);
// lylix // normalize the case of each keyword
foreach ($keywords as $key => $keyword)
$keywords[$key] = strtolower ($keyword);
// lylix // set keyword(s) counts // normalize input fields to lower case
for ($i = str_word_count($_GET[search])-1; $i >= 0; $i--){
$desc_count += substr_count( strtolower($row['description']), $keywords[$i] );
$symptoms_count += substr_count( strtolower($row['symptoms']), $keywords[$i] );
$solution_count += substr_count( strtolower($row['solution']), $keywords[$i] );
}
// lylix // get a weight total for this article // may need adjustment
$weight = ( $desc_count * 15 ) + ( $symptoms_count * 5 ) + ( $solution_count * 2 );
// dump results into an array
$results[] = array( id => $row['id'],
description => $row['description'],
category => $row['category'],
parent => $row['parent'],
weight => $weight
);
}