SPSVB – Developer’s Introduction to SharePoint Search

The morning session on Search seemed to go over well with a lot of great questions.  Here is the slide deck from the session:
Source Code for the Manager Web Part is below:
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Query;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.Office.Server.UserProfiles;
using System.Collections.Specialized;
using Microsoft.SharePoint.Administration;
using System.Collections;
using System.Data;
using System.Text;
namespace NextConnect.Search.Presentation.DisplayManagers { [ToolboxItemAttribute(false)] public class DisplayManagers : WebPart { protected Literal literalMessage;
protected override void CreateChildControls() { this.literalMessage = new Literal(); this.literalMessage.ID = "literalMessage"; this.Controls.Add(this.literalMessage); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); DisplayFullText(); }
protected void DisplayFullText() { StringBuilder messages = new StringBuilder(); DataTable results = new DataTable();
string searchProxyName = "Search Service Application"; SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue(); SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue(searchProxyName); FullTextSqlQuery mQuery = new FullTextSqlQuery(searchProxy);
try { mQuery.QueryText = "SELECT LastName, FirstName, JobTitle, accountname FROM SCOPE() WHERE ("scope" = 'People') AND CONTAINS(JobTitle, 'Manager') AND NOT CONTAINS(Department, '1099')";
mQuery.ResultTypes = ResultType.RelevantResults; mQuery.TrimDuplicates = false; mQuery.RowLimit = 100; //mQuery.KeywordInclusion = KeywordInclusion.AnyKeyword; //mQuery.AuthenticationType = QueryAuthenticationType.NtAuthenticatedQuery;
ResultTableCollection resultTables = mQuery.Execute(); if (resultTables.Count > 0) { ResultTable relevantResults = resultTables[ResultType.RelevantResults]; results.Load(relevantResults, LoadOption.OverwriteChanges); } messages.AppendFormat(@"
Found {0} result(s).
    ", results.Rows.Count);
foreach (DataRow row in results.Rows) { messages.AppendFormat(@"
  • {0}, {1} - {2}
  • ", row[0].ToString(), row[1].ToString(), row[2].ToString(), row[3].ToString()); } messages.AppendFormat(@"
    ");
    this.EnsureChildControls(); this.literalMessage.Text = messages.ToString(); } catch (Exception ex) { this.EnsureChildControls(); this.literalMessage.Text = "Error: " + ex.Message.ToString(); } finally { mQuery.Dispose(); } } } }

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    %d bloggers like this: