About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, September 14, 2011

Create SharePoint search results programatically

private void ComplexSearch()
        {
            SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue();
            SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue("Search_Service_CUSTOM");
            KeywordQuery keywordQuery = new KeywordQuery(searchProxy);
            string SearchScope = "PEOPLE";
            keywordQuery.HiddenConstraints = "scope:" + "\"" + SearchScope + "\"";

            keywordQuery.TrimDuplicates = true;
            keywordQuery.EnableStemming = true;
            keywordQuery.IgnoreAllNoiseQuery = true;
            keywordQuery.QueryText =  "SELECT AccountName,PreferredName,PictureUrl,WorkEmail,JobTitle,Department,InternalNumber,OfficeNumber,AboutMe,Responsibility,Skills,HitHighlightedSummary,InternalTelephone,OfficeNumber,AboutMe,Responsibility,Skills,HitHighlightedSummary,HitHighlightedProperties,CollapsingStatus,Path,FirstName,LastName FROM Scope() WHERE ('scope'='People')";


            keywordQuery.EnablePhonetic = true;           
            keywordQuery.ResultsProvider = SearchProvider.Default;
            keywordQuery.ResultTypes = ResultType.RelevantResults | ResultType.SpecialTermResults ;
            ResultTableCollection resultsTableCollection = keywordQuery.Execute();
            ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults];
            DataTable resultsDataTable = new DataTable();
            resultsDataTable.TableName = "Results";
            resultsDataTable.Load(searchResultsTable, LoadOption.OverwriteChanges);

            DataView view = new DataView(resultsDataTable);
            SearchGrid.DataSource = resultsDataTable;
            SearchGrid.DataBind();
        }

No comments:

My Masters