0) { $thisrow = mysql_fetch_array($result); $sites_qry = "and site_id = ".$thisrow[0]; } else { $sites_qry = ""; } $result = mysql_query("select domain_id from ".$mysql_table_prefix."domains where domain = '". $_SERVER['HTTP_HOST']. "'"); if (mysql_num_rows($result)> 0) { $thisrow = mysql_fetch_array($result); $domain_qry = "and domain_id = ".$thisrow[0]; } else { $domain_qry = ""; } /* searches from saved queries (query_log table) */ if ($suggest_history && $_GET['q']!='"') { $result = mysql_query($sql = " SELECT query as keyword, max(results) as results FROM {$mysql_table_prefix}query_log WHERE results > 0 AND (query LIKE '{$_GET['q']}%' OR query LIKE '\"{$_GET['q']}%') $domain_qry GROUP BY query ORDER BY results DESC LIMIT $suggest_rows "); if($result && mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { $values[$row['keyword']] = $row['results']; } } } /* phrase search !! LOCATE: in MySQL 3.23 this function is case sensitive, while in 4.0 it's only case-sensitive if either argument is a binary string */ if ($suggest_phrases) { $_GET['q'] = strtolower( str_replace('"','',$_GET['q'] )); $_words = substr_count($_GET['q'],' ') + 1; $result = mysql_query($sql = " SELECT count(link_id) as results, SUBSTRING_INDEX(SUBSTRING(fulltxt,LOCATE('{$_GET['q']}',LOWER(fulltxt))), ' ', '$_words') as keyword FROM {$mysql_table_prefix}links where fulltxt like '%{$_GET['q']}%' $sites_qry GROUP BY SUBSTRING_INDEX( SUBSTRING( fulltxt, LOCATE( '{$_GET['q']}', LOWER(fulltxt) ) ) , ' ', '$_words' ) LIMIT $suggest_rows "); if($result && mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { //$row['keyword'] = preg_replace("/[^\s\w]/ims",'',$row['keyword']);//array('.',',','?')$row['keyword']); $values[$row['keyword']] = $row['results']; } } } /* keyword search */ elseif ($suggest_keywords) { for ($i=0;$i<=15; $i++) { $char = dechex($i); $result = mysql_query($sql = " SELECT keyword, count(keyword) as results FROM {$mysql_table_prefix}keywords INNER JOIN {$mysql_table_prefix}link_keyword$char USING (keyword_id) JOIN {$mysql_table_prefix}links USING (link_id) WHERE keyword LIKE '{$_GET['q']}%' $sites_qry GROUP BY keyword ORDER BY results desc LIMIT $suggest_rows "); if($result && mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { $values[$row['keyword']] = $row['results']; } } } arsort($values); $values = array_slice($values, 0, $suggest_rows); } if (is_array($values)) { arsort($values); if (is_array($values)) foreach ($values as $_key => $_val) { $js_array[] = 'new Array("' .str_replace('"','\"',$_key) . '", " ' . $_val . ' results")'; } print utf8_encode("new Array(" . implode(", ", $js_array) . ")"); } ?>