我正在尝试修复工作搜索工具。这是我第一次遇到 ASP.NET。当前的搜索工具有一个单选按钮列表,其中包含如何搜索我们的本地目录的三个选项。然而,在我之前从事这个项目的人没有完成代码并且已经退出。单选按钮不影响搜索查询,因为我注意到无论您选择什么选项,查询都是相同的。
这是我尝试重写搜索功能以合并三个单选按钮选项。但是,当我将此功能合并到其余代码中时,页面根本不会呈现,并且我没有收到错误消息。我认为我在查询字符串中没有出错,因为我采用了原始字符串并通过省略包含语句对其进行了变体。我假设错误来自我的 if 语句或我试图比较 asp.net RadioButtonList ListItem 值的方式。
protected void btnclick_WorkspaceSearch(object sender, EventArgs e){
string strSearchTerm=tbSearch.Text.Trim()
if (rblSearchOption.SelectedValue == "all"){
// Find the search term in either a file name or file content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "OR CONTAINS(Contents, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue=="names"){
// Find the search term in a file name
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue =="contents") {
// Find the search term in a file's content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
searchIndex(indexQuery);
lit_strQueryString.Text = indexQuery;
}