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("<SupportedFormats>");
 queryXml.Append("</SupportedFormats>");
 queryXml.Append("<Range>");
 queryXml.Append("<Count>50</Count>");
 queryXml.Append("</Range>");
 queryXml.Append("<Context>");
 queryXml.Append("<QueryText language=\"en-US\" type=\"FQL\">");
 queryXml.Append(txtBoxQuery.Text);
 queryXml.Append("</QueryText>");
 queryXml.Append("</Context>");
 queryXml.Append("</Query>");
 queryXml.Append("</QueryPacket>");
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 http://rsugjan12.eventbrite.com/

Leave a comment