【发布时间】:2011-08-26 03:16:06
【问题描述】:
我正在使用 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”。
如何将句子放入变量中并单独搜索每个变量?还是有更快的方法?
希望有人能给我一些帮助。谢谢
【问题讨论】:
标签: c# sql-server database search