My Session in RSUG Jan 2012

On 2/2/2012 it was my third session in RSUG with my friends Jerry , Megren and AhmadAbouAbdo. We all talked about SharePoint 2010 Search. My session was focus on custom development search.


First, I listed why we need custom development and what are the reasons:

  • Modify the end user experience
  • Create new visual elements (chart , maps)
  • Search for related items
  • Querying external data sources (Exchange Emails)
  • Adding extra actions to results
  • Querying Multiple Federated Locations at same web part
  • Bring results to another locations
and then I talked, what the ways to query the search in custom development which are:
  • Search Webservice
  • Object Model

Web Service

first, build the query XML as below

StringBuilder queryXml=new StringBuilder();
queryXml.Append("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\">");
 queryXml.Append("<Query domain=\"QDomain\">");
 queryXml.Append("<QueryText language=\"en-US\" type=\"FQL\">");
return queryXml.ToString();

then, call the webservice as below after adding the web service reference http://<yoursite>/_vti_bin/search.asmx

 SearchWS.QueryService queryService = new SearchWS.QueryService();
 queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
 System.Data.DataSet queryResults = queryService.QueryEx(GetXMLString());
 resultsGrid.DataSource = queryResults.Tables[0];

Object Model

but you need to add the following assemblies:

  • Microsoft.Office.Server
  • Microsoft.Office.Server.Search
KeywordQuery query = new KeywordQuery("http://win8r2:2000/");
 query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
query.QueryText = txtBoxQuery.Text;
 query.ResultTypes = ResultType.VisualBestBetsResults | ResultType.RelevantResults;
 ResultTableCollection searchResults = query.Execute();
 if (searchResults.Exists(ResultType.RelevantResults))
 ResultTable searchResult = searchResults[ResultType.VisualBestBetsResults];
 DataTable result = new DataTable();
 result.TableName = "Result";
 result.Load(searchResult, LoadOption.OverwriteChanges);
resultsGrid.DataSource = result;

and this is the link


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s