我正在使用MSSQL和C#編寫搜索引擎。我在數據庫中遇到了一堆停用詞。在我的default.aspx頁面中,我有一個文本框和一個搜索按鈕。用戶可以在文本框中輸入整個句子。如何將單詞放入變量並檢查它是否與數據庫中的數據匹配
我寫了搜索單個關鍵字但不是整個句子的代碼。這是default.aspx.cs
private void ImageSearch()
{
if (txtSearch.Text.Trim().Equals(""))
{
//when types nothing
txtSearch.Focus();
Warning.Text = "Please enter the keyword to search";
//display message
return;
}
else
{
int check = Process.CheckStopWord(txtSearch.Text.Trim());
//check if the keyword is stop word
if (check == 0)
{
txtSearch.Focus();
Warning.Text = "No stop word found";
}
else
{
txtSearch.Focus();
Warning.Text = "Found Stop word";
}
}
}
,爲checkstopword功能
public static int CheckStopWord(string keyword)
{
string check = "0";
string query = "SELECT COUNT (stopword) FROM stopwordtb WHERE [stopword] like '" + keyword + "'";
//count how many stop word matches the keyword entered, return a string of a number
accessDB dbaccess = new accessDB();
DataSet ds = dbaccess.queryData(query);
DataTable dt = ds.Tables[0];
if (dt.Rows[0][0].ToString() == check)
{
return 0;
//keyword != stop word in stopwordtb
// begin search in image database - not implemented yet
}
else
{
return 1;
//keyword = stop word in stopwordtb
}
}
我的問題是功能,如果在整個句子的用戶類型?例如,如果他在文本框中鍵入「The tree」,但「The」是停用詞,那麼我將忽略「the」並只搜索圖像數據庫中的「tree」。
如何將句子放入變量並分別搜索每個變量?或者有沒有更快的方法?
希望有人能給我一些幫助。謝謝