簡體   English   中英

使搜索引擎忽略特定的關鍵字

[英]Make the search engine ignore specific keywords

我目前正在使用

    $terms = explode(" ", $k);
    $query = "SELECT * FROM search WHERE ";


    foreach ($terms as $each) {
        $i++;

        if ($i == 1)
            $query .= "keywords = '%$each%' ";
        else
            $query .= "OR keywords LIKE '%$each%' ";
}

    // connect
    mysql_connect("localhost", "root", "password");
    mysql_select_db("search");

    $query = mysql_query($query);
    $numrows = mysql_num_rows ($query);
    if ($numrows > 0) {

        while ($row = mysql_fetch_assoc($query)) {
            $id = $row['id'];
            $title = $row['title'];
            $description = $row['description'];
            $keywords = $row['keywords'];
            $links = $row['link'];

            echo "<h2>$title</h2><p>$description</p>";

        }

    }
    else
        echo "No Search Results have been found for \"<b>$k</b>\"";

    // disconnect
    mysql_close();



?>

我從一個教程中學到的這段代碼開始了我的搜索引擎。 老實說,我不知道任何PHP,並且了解這里發生的事情確實是一場艱苦的斗爭。

如何處理這段代碼,以便如果我搜索“ Swarthmore College”或“ Swarthmore”,將顯示Swarthmore結果。 我需要確保僅輸入“ College”或“ swar”或“ a”不會觸發Swarthmore結果。 但是我需要像“大學”,“大學”和“芝加哥”這樣的常用詞來共同觸發諸如“芝加哥大學”的大學搜索。 還應使用“ UChicago”之類的縮寫來觸發。

很抱歉,我想問的問題很多,但我完全迷失了。 先感謝您。

您應該包括elseif子句。 該代碼將是:

if ($numrows == 1) {
    // You dont need to iterate if you want to show only unique result
    $row = mysql_fetch_assoc($query);
    $id = $row['id'];
    $title = $row['title'];
    $description = $row['description'];
    $keywords = $row['keywords'];
    $links = $row['link'];

    echo "<h2>$title</h2><p>$description</p>";
}
elseif ($numrows > 1)
    echo "More than one Search Results have been found for \"<b>$k</b>\". Please be more specific ";
else
    echo "No Search Results have been found for \"<b>$k</b>\"";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM