Ejemplo n.º 1
0
        public static DataTable ExecuteQuery(string SiteCollection, string QueryString)
        {
            SPSite        col = new SPSite(SiteCollection);
            ServerContext ctx = ServerContext.GetContext(col);

            FullTextSqlQuery ftq = new FullTextSqlQuery(ctx);

            ftq.ResultTypes    = ResultType.RelevantResults;
            ftq.EnableStemming = true;
            ftq.TrimDuplicates = true;
            ftq.QueryText      = QueryString;

            ResultTableCollection allresults = ftq.Execute();

            ResultTable relevant = allresults[ResultType.RelevantResults];

            DataTable dt = null;

            if (relevant.RowCount > 0)
            {
                dt = new DataTable("Search Result");
                dt.Columns.Add("Title");
                dt.Columns.Add("URL");
                while (relevant.Read())
                {
                    DataRow row = dt.NewRow();
                    row[0] = relevant.GetString(0);
                    row[1] = relevant.GetString(1);
                    dt.Rows.Add(row);
                }
            }

            return(dt);
        }
Ejemplo n.º 2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            SPSite                 col       = new SPSite(txtSC.Text);
            ServerContext          ctx       = ServerContext.GetContext(col);
            DropDownHelper <Scope> dds       = (DropDownHelper <Scope>)cbScope.SelectedItem;
            string                 ScopeName = dds.Item.Name;

            string query = "Select title, url FROM Scope() where \"Scope\" = '" + ScopeName + "' AND Freetext('" + txtPhrase.Text + " ')";


            FullTextSqlQuery ftq = new FullTextSqlQuery(ctx);

            ftq.ResultTypes    = ResultType.RelevantResults;
            ftq.EnableStemming = true;
            ftq.TrimDuplicates = true;
            ftq.QueryText      = query;

            ResultTableCollection allresults = ftq.Execute();

            ResultTable relevant = allresults[ResultType.RelevantResults];

            DataTable dt = null;

            if (relevant.RowCount > 0)
            {
                dt = new DataTable("Search Result");
                dt.Columns.Add("Title");
                dt.Columns.Add("URL");
                while (relevant.Read())
                {
                    DataRow row = dt.NewRow();
                    row[0] = relevant.GetString(0);
                    row[1] = relevant.GetString(1);
                    dt.Rows.Add(row);
                }

                gvResult.DataSource = dt;
                gvResult.AutoResizeColumns();
            }
        }
Ejemplo n.º 3
0
 public string GetString(int index)
 {
     return(m_resultTable.GetString(index));
 }