我正试图建立一个搜索工具。 它可以在我的搜寻纽扣上搜寻,并作出反应。 我增加了一些无线电台,用户可以用来确定某些环境。 我希望网站每当无线电台的检查发生变化时都会进行新的搜索,但这是我不得不做的事。
我试图在上做些什么。 答案是,但它没有帮助。
Here is my code
public class HelloWorld : Microsoft.SharePoint.WebPartPages.WebPart
{
Button btn;
TextBox textBx;
string _myProperty = "";
DataTable resultsDataTable = new DataTable();
RadioButton exactSearch;
RadioButton wildSearch;
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("My Property Group")]
[WebDisplayName("MyProperty")]
[WebDescription("Meaningless Property")]
public string MyProperty
{
get
{
if (_myProperty == null)
{
_myProperty = "Hello SharePoint";
}
return _myProperty;
}
set { _myProperty = value; }
}
protected override void CreateChildControls()
{
base.CreateChildControls();
textBx = new TextBox();
textBx.Text = "";
btn = new Button();
btn.Text = "Search";
exactSearch = new RadioButton();
exactSearch.GroupName = "searchSetting";
exactSearch.Checked = false;
wildSearch = new RadioButton();
wildSearch.GroupName = "searchSetting";
wildSearch.Checked = true;
//Events
btn.Click += new EventHandler(btn_Click);
wildSearch.CheckedChanged += new EventHandler(wildSearch_CheckedChanged);
//Adding to controls
this.Controls.Add(btn);
this.Controls.Add(textBx);
this.Controls.Add(exactSearch);
this.Controls.Add(wildSearch);
}
void wildSearch_CheckedChanged(object sender, EventArgs e)
{
search();
}
void btn_Click(object sender, EventArgs e)
{
search();
}
protected override void Render(HtmlTextWriter writer)
{
//Title
writer.Write("Super Lookup Service <br/>");
//Search block
textBx.RenderControl(writer);
writer.Write(" ");
btn.RenderControl(writer);
writer.Write("<br/>");
writer.Write("Exact Search ");
exactSearch.RenderControl(writer);
writer.Write(" ");
writer.Write("Wild Search ");
wildSearch.RenderControl(writer);
writer.Write("<br/><br/>");
//Search results
if (resultsDataTable.Rows.Count > 0)
{
writer.Write("<b> {0} Results:</b><br/>", resultsDataTable.Rows.Count);
foreach (DataRow row in resultsDataTable.Rows)
{
writer.Write("<a href="{0}">{1}</a> ({2}) - size: {3}<br/>", row["path"].ToString(), row["title"].ToString(), row["author"].ToString(), row["Size"].ToString());
}
}
else
{
writer.Write("<b>0 Results:</b>");
}
}
private void search()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
FullTextSqlQuery query = new FullTextSqlQuery(site);
string queryText = "";
if (wildSearch.Checked == true)
{
queryText = "SELECT title, path, author, Size from Scope() where title LIKE %" + textBx.Text + "% order by title asc ";
}
else if (exactSearch.Checked == true)
{
queryText = "SELECT title, path, author, Size from Scope() where title = " + textBx.Text + " order by title asc ";
}
query.QueryText = queryText;
query.ResultTypes = ResultType.RelevantResults;
query.RowLimit = 3000;
ResultTableCollection resultTables = query.Execute();
if (resultTables.Count > 0)
{
ResultTable relevantResults = resultTables[ResultType.RelevantResults];
resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges);
}
}
}
}
希望能帮助我。
BR