我在我的網站上運行了一個簡單的搜索引擎,但每次搜索「6月7日」這個非常具體的術語時,它都會顯示與「june」在數據庫中。我無法弄清楚如何讓我的PHP搜索引擎從數據庫調用特定的關鍵字..幫助?PHP搜索引擎與MySQL數據庫中的特定術語不匹配
這裏是我的代碼..
<?PHP
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//initializing connection to the database
$connection_string = dirname(__FILE__) . "/connectionstring.php";
require_once($connection_string);
//selecting table
mysql_select_db("jaguartr_logins") or die ('Unable to select database.');
//max number of results on the page
$RESULTS_LIMIT=1000;
if(isset($_GET['search_term']) && isset($_GET['search_button']))
{
$search_term = $_GET['search_term'];
if(!isset($first_pos))
{
$first_pos = "0";
}
$start_search = getmicrotime();
// initializing MySQL query
$sql_query = mysql_query("SELECT * FROM news WHERE MATCH(title,article) AGAINST('$search_term')");
// additional check. Insurance method to re-search the database again in case of too many matches (too many matches cause returning of 0 results)
if($results = mysql_num_rows($sql_query) != 0)
{
$sql = "SELECT * FROM news WHERE MATCH(title,article) AGAINST('$search_term') LIMIT $first_pos, $RESULTS_LIMIT";
$sql_result_query = mysql_query($sql);
}
else
{
$sql = "SELECT * FROM news WHERE (title LIKE '%".mysql_real_escape_string($search_term)."%' OR article LIKE '%".$search_term."%') ";
$sql_query = mysql_query($sql);
$results = mysql_num_rows($sql_query);
$sql_result_query = mysql_query("SELECT * FROM news WHERE (title LIKE '%".$search_term."%' OR article LIKE '%".$search_term."%') LIMIT $first_pos, $RESULTS_LIMIT ");
}
$stop_search = getmicrotime();
//calculating the search time
$time_search = ($stop_search - $start_search);
}
?>
<?PHP
if($results != 0)
{
?>
你有更長的搜索條件相同的問題嗎?我的意思是,7只是一個字符短,可以忽略。嘗試更長的時間。 –
是的,如果我在搜索欄中輸入「June 7」,它會在數據庫中提取以「J」開頭的任何內容 – Tom