private DataTable GetItems() { DataTable resultsDataTable = new DataTable(); if (tags.Length > 0) { SPSite site = new SPSite(SPContext.Current.Site.Url); /* * FullTextSqlQuery query = new FullTextSqlQuery(site); * query.Hint = QueryHint.OptimizeWithPropertyStore; * // inserito per prendere tutto. BUG della search * query.TrimDuplicates = false; * query.QueryText = "SELECT Path, title, Created, Tags, TipoContenuto, SiteTitle, SiteName FROM scope() WHERE \"scope\"='All Sites' AND (CONTAINS(Tags,'\"" + tags[0] + "\"')"; * if (tags.Length > 1) * { * for (int i = 1; i < tags.Length; i++) * { * query.QueryText += " OR CONTAINS(Tags,'\"" + tags[i] + "\"')"; * } * } * query.QueryText += ") ORDER BY LastModifiedTime Desc"; * query.SiteContext = new Uri(site.Url); * query.ResultTypes = ResultType.RelevantResults; * */ SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site)); KeywordQuery query = new KeywordQuery(proxy); //query.EnableFQL = true; query.QueryText = propertyName + ":\"" + tags[0] + "\""; if (tags.Length > 1) { for (int i = 1; i < tags.Length; i++) { query.QueryText += " OR " + propertyName + ":\"" + tags[i] + "\""; } } query.ResultsProvider = SearchProvider.Default; query.ResultTypes = ResultType.RelevantResults; query.StartRow = 0; query.RowLimit = 5000; query.TrimDuplicates = false; query.SelectProperties.Add("Path"); query.SelectProperties.Add("title"); query.SelectProperties.Add("Descrizione"); query.SelectProperties.Add(propertyName); query.SelectProperties.Add("TipoContenuto"); query.SelectProperties.Add("Created"); query.SelectProperties.Add("SiteTitle"); query.SelectProperties.Add("SiteName"); query.SortList.Add("Rank", Microsoft.Office.Server.Search.Query.SortDirection.Descending); // ResultTableCollection resultTables = query.Execute(); ResultTable relevantResults = resultTables[ResultType.RelevantResults]; resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges); } return(resultsDataTable); }
public string GetSearchResult(string messageInput) { string k = GetSearchKeyWord(messageInput); string ret = string.Empty; using (SPMonitoredScope scope = new SPMonitoredScope("MyCustomMessageHandler.GetSearchResult")) { //KeywordQuery keywordquery = new KeywordQuery(SPContext.Current.Site); //keywordquery.ResultTypes = ResultType.RelevantResults; //keywordquery.QueryText = string.Concat("ContentSource=", contentSourceName, " ", AppearInWeChat, "=True"); //keywordquery.SelectProperties.Add(WeChatResult); //keywordquery.TrimDuplicates = false; //keywordquery.RowsPerPage = 0; //keywordquery.RowLimit = 10; //keywordquery.Timeout = 5000; //SearchExecutor searchexecutor = new SearchExecutor(); //2013 foundation 里面的SearchExecutor这里没有 //ResultTableCollection resulttablecollection = searchexecutor.ExecuteQuery(keywordquery); //ResultTable resulttable = resulttablecollection.Filter("TableType", KnownTableTypes.RelevantResults).FirstOrDefault(); //https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ms493601(v=office.14) SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site)); KeywordQuery query = new KeywordQuery(proxy); query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default; query.QueryText = string.Concat("ContentSource=", contentSourceName, " ", AppearInWeChat, "=True"); query.ResultTypes |= ResultType.RelevantResults; ResultTableCollection searchResults = query.Execute(); if (searchResults.Exists(ResultType.RelevantResults)) { ResultTable searchResult = searchResults[ResultType.RelevantResults]; DataTable result = new DataTable(); result.TableName = "Result"; result.Load(searchResult, LoadOption.OverwriteChanges); StringBuilder sb = new StringBuilder(); foreach (DataRow r in result.Rows) { sb.Append(r[WeChatResult]); sb.Append(System.Environment.NewLine); } ret = sb.ToString(); } } return(ret); }
void searchButton_Click(object sender, EventArgs e) { //Only search if there are search terms if (searchTermsTextbox.Text != string.Empty) { //First, we must connect to the service application proxy SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site)); //Create and configure a Keyword Query object KeywordQuery query = new KeywordQuery(proxy); query.ResultsProvider = SearchProvider.Default; query.QueryText = searchTermsTextbox.Text; //Relevant Results are the main search results query.ResultTypes = ResultType.RelevantResults; //Now we can execute the query ResultTableCollection searchResults = query.Execute(); if (searchResults.Exists(ResultType.RelevantResults)) { //There are relevant results. We need them in a Data Table //so we can bind them to the Data Grid for display ResultTable resultTable = searchResults[ResultType.RelevantResults]; //Tell the user how many results we got resultsLabel.Text = String.Format("There are {0} results", resultTable.TotalRows.ToString()); //Set up and load the data table DataTable resultDataTable = new DataTable(); resultDataTable.TableName = "Result"; resultDataTable.Load(resultTable, LoadOption.OverwriteChanges); //Bind the datatable to the Data Grid resultsGrid.DataSource = resultDataTable; resultsGrid.DataBind(); } else { //Search executed but found nothing resultsLabel.Text = "There were no relevant results. Try other search terms"; } } else { //No search terms in the textbox resultsLabel.Text = "Please enter at least one search term"; } }
protected void ExecuteSearchQuery(string searchQueryText) { Logging.Logger.Instance.Info("Executing Search Query"); //TODO: Refactor this to allow reuse with the btnSave code below SPServiceContext serviceContext = SPServiceContext.Current; SPServiceApplicationProxy proxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)); SearchServiceApplicationProxy searchAppProxy = proxy as SearchServiceApplicationProxy; string scopeName = String.Empty; if (SPContext.Current.Site.RootWeb.AllProperties.Contains(SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE)) { scopeName = SPContext.Current.Site.RootWeb.AllProperties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE] as string; } Logging.Logger.Instance.Info(String.Format("Scope retrieved from property bag setting. Scope: {0}; Setting Name: {1} ; Site: {2}", scopeName, SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE, SPContext.Current.Site.RootWeb.Url), Logging.DiagnosticsCategories.eCaseSearch); if (!String.IsNullOrEmpty(searchQueryText)) { using (KeywordQuery query = new KeywordQuery(SPContext.Current.Site)) { int rowsPerSet = 50; query.QueryText = queryLabel.Text; query.ResultsProvider = SearchProvider.Default; query.ResultTypes = ResultType.RelevantResults; query.RowLimit = rowsPerSet; query.TrimDuplicates = false; query.EnableStemming = true; if (!String.IsNullOrEmpty(scopeName)) { query.HiddenConstraints = "scope:\"" + scopeName + "\""; } ResultTableCollection resultsTableCollection = query.Execute(); rowCountSpan.InnerText = resultsTableCollection[ResultType.RelevantResults].TotalRows.ToString(); } } }
private static ResultTableCollection GetSearchResults(SPSite site, string q, int top, int skip, string select, string orderBy, bool includeRefiners, string r) { var query = new KeywordQuery(site); query.QueryText = q; query.StartRow = skip; if (top > 0) { query.RowLimit = top; } FillSelectProperties(select, query); FillSortList(orderBy, query); query.ResultTypes = ResultType.RelevantResults; if (includeRefiners) { query.ResultTypes |= ResultType.RefinementResults; query.Refiners = r; } return(query.Execute()); }
private static ResultTableCollection ExecuteKeywordQuery(SPSite site, string queryText) { SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site)); KeywordQuery query = new KeywordQuery(proxy); query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default; query.SelectProperties.Add("ItemID"); query.QueryText = queryText; query.ResultTypes |= ResultType.RelevantResults; query.RowLimit = 0; ResultTableCollection searchResults = query.Execute(); return searchResults; //if (searchResults.Exists(ResultType.RelevantResults)) //{ // ResultTable searchResult = searchResults[ResultType.RelevantResults]; // DataTable result = new DataTable(); // result.TableName = "Result"; // result.Load(searchResult, LoadOption.OverwriteChanges); // FillResultsGrid(result); //} }
private DataTable GetItems() { DataTable resultsDataTable = new DataTable(); if (tags.Length > 0) { SPSite site = new SPSite(SPContext.Current.Site.Url); /* FullTextSqlQuery query = new FullTextSqlQuery(site); query.Hint = QueryHint.OptimizeWithPropertyStore; // inserito per prendere tutto. BUG della search query.TrimDuplicates = false; query.QueryText = "SELECT Path, title, Created, Tags, TipoContenuto, SiteTitle, SiteName FROM scope() WHERE \"scope\"='All Sites' AND (CONTAINS(Tags,'\"" + tags[0] + "\"')"; if (tags.Length > 1) { for (int i = 1; i < tags.Length; i++) { query.QueryText += " OR CONTAINS(Tags,'\"" + tags[i] + "\"')"; } } query.QueryText += ") ORDER BY LastModifiedTime Desc"; query.SiteContext = new Uri(site.Url); query.ResultTypes = ResultType.RelevantResults; * */ SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site)); KeywordQuery query = new KeywordQuery(proxy); //query.EnableFQL = true; query.QueryText = propertyName + ":\"" + tags[0] + "\""; if (tags.Length > 1) { for (int i = 1; i < tags.Length; i++) { query.QueryText += " OR " + propertyName + ":\"" + tags[i] + "\""; } } query.ResultsProvider = SearchProvider.Default; query.ResultTypes = ResultType.RelevantResults; query.StartRow = 0; query.RowLimit = 5000; query.TrimDuplicates = false; query.SelectProperties.Add("Path"); query.SelectProperties.Add("title"); query.SelectProperties.Add("Descrizione"); query.SelectProperties.Add(propertyName); query.SelectProperties.Add("TipoContenuto"); query.SelectProperties.Add("Created"); query.SelectProperties.Add("SiteTitle"); query.SelectProperties.Add("SiteName"); query.SortList.Add("Rank", Microsoft.Office.Server.Search.Query.SortDirection.Descending); // ResultTableCollection resultTables = query.Execute(); ResultTable relevantResults = resultTables[ResultType.RelevantResults]; resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges); } return resultsDataTable; }
protected void saveSearchResultsButton_Click(object sender, EventArgs e) { Logging.Logger.Instance.Info("Begin Saving Search Results"); string scopeName = String.Empty; if (SPContext.Current.Site.RootWeb.AllProperties.Contains(SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE)) { scopeName = SPContext.Current.Site.RootWeb.AllProperties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE] as string; } Logging.Logger.Instance.Info(String.Format("Scope retrieved from property bag setting. Scope: {0}; Setting Name: {1} ; Site: {2}", scopeName, SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE, SPContext.Current.Site.RootWeb.Url), Logging.DiagnosticsCategories.eCaseSearch); SPServiceContext serviceContext = SPServiceContext.Current; SPServiceApplicationProxy proxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)); SearchServiceApplicationProxy searchAppProxy = proxy as SearchServiceApplicationProxy; if (!String.IsNullOrEmpty(savedSearchNameTextBox.Text)) //&& !String.IsNullOrEmpty(Request.QueryString["query"])) { using (KeywordQuery query = new KeywordQuery(SPContext.Current.Site)) { int rowsPerSet = 50; query.QueryText = queryLabel.Text; query.ResultsProvider = SearchProvider.Default; query.ResultTypes = ResultType.RelevantResults; query.TrimDuplicates = false; query.EnableStemming = true; if (!String.IsNullOrEmpty(scopeName)) { Logging.Logger.Instance.Info(String.Format("Adding scope to hidden constraints: {0}", scopeName), Logging.DiagnosticsCategories.eCaseSearch); query.HiddenConstraints = "scope:\"" + scopeName + "\""; } query.RowLimit = rowsPerSet; ResultTableCollection resultsTableCollection = query.Execute(); if (resultsTableCollection.Count > 0) { //save search result entry string connectionString = SPContext.Current.Site.RootWeb.Properties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_DB_CONNECTION_STRING]; Int64 searchRowIdentity = 0; using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString)) { Logging.Logger.Instance.Info(String.Format("Opening database connection to: {0}", connectionString)); conn.Open(); using (System.Data.SqlClient.SqlTransaction trans = conn.BeginTransaction()) { //Insert the Saved Search Results Parent Entry using (System.Data.SqlClient.SqlCommand parentInsertCommand = new System.Data.SqlClient.SqlCommand()) { parentInsertCommand.Connection = conn; parentInsertCommand.Transaction = trans; parentInsertCommand.CommandType = CommandType.StoredProcedure; parentInsertCommand.CommandText = "CreateSavedSearchResult"; if (!IsNew) { parentInsertCommand.Parameters.AddWithValue("@Id", Request.QueryString["id"]); } parentInsertCommand.Parameters.AddWithValue("@Name", savedSearchNameTextBox.Text); parentInsertCommand.Parameters.AddWithValue("@Description", savedSearchDescriptionTextBox.Text); parentInsertCommand.Parameters.AddWithValue("@Query", queryLabel.Text); parentInsertCommand.Parameters.AddWithValue("@Owner", SPContext.Current.Web.CurrentUser.LoginName); searchRowIdentity = (Int64)parentInsertCommand.ExecuteScalar(); } using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter()) { if (IsNew) //skip updating the results if this isn't a new result set to save time and effort { string maxResultsString = SPContext.Current.Site.RootWeb.Properties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_MAX_RESULTS]; int maxResults; if (!int.TryParse(maxResultsString, out maxResults)) { int.TryParse(SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagDefaultValues.ECASE_SAVED_SEARCH_RESULTS_MAX_RESULTS, out maxResults); } Logging.Logger.Instance.Info(String.Format("Results limit: {0}", maxResults), Logging.DiagnosticsCategories.eCaseSearch); ResultTable results = resultsTableCollection[ResultType.RelevantResults]; int startRow = 0; int rowsFound = 0; int lastRow = startRow + results.RowCount; using (System.Data.SqlClient.SqlCommand childInsertCommand = new System.Data.SqlClient.SqlCommand()) { childInsertCommand.Connection = conn; childInsertCommand.Transaction = trans; childInsertCommand.CommandText = @"INSERT INTO SavedSearchResultItems ( SavedSearchResultId, WorkId, Rank, Author, Size, Path, Description, SiteName, HitHighlightedSummary, HitHighlightedProperties, ContentClass, IsDocument, PictureThumbnailUrl, Url, ServerRedirectedUrl, FileExtension, SpSiteUrl, docvector, fcocount, fcoid, PictureWidth, PictureHeight ) VALUES ( @SavedSearchResultId, @WorkId, @Rank, @Author, @Size, @Path, @Description, @SiteName, @HitHighlightedSummary, @HitHighlightedProperties, @ContentClass, @IsDocument, @PictureThumbnailUrl, @Url, @ServerRedirectedUrl, @FileExtension, @SpSiteUrl, @docvector, @fcocount, @fcoid, @PictureWidth, @PictureHeight )"; childInsertCommand.Parameters.Add("@SavedSearchResultId", System.Data.SqlDbType.BigInt); childInsertCommand.Parameters["@SavedSearchResultId"].Value = searchRowIdentity; childInsertCommand.Parameters.Add("@WorkId", System.Data.SqlDbType.NVarChar, 50, "WorkId"); childInsertCommand.Parameters.Add("@Rank", System.Data.SqlDbType.Int, 0, "Rank"); childInsertCommand.Parameters.Add("@Author", System.Data.SqlDbType.NVarChar, 50, "Author"); childInsertCommand.Parameters.Add("@Size", System.Data.SqlDbType.Int, 50, "Size"); childInsertCommand.Parameters.Add("@Path", System.Data.SqlDbType.NVarChar, 500, "Path"); childInsertCommand.Parameters.Add("@Description", System.Data.SqlDbType.NVarChar, 500000, "Description"); childInsertCommand.Parameters.Add("@SiteName", System.Data.SqlDbType.NVarChar, 500, "SiteName"); childInsertCommand.Parameters.Add("@HitHighlightedSummary", System.Data.SqlDbType.NVarChar, 500000, "HitHighlightedSummary"); childInsertCommand.Parameters.Add("@HitHighlightedProperties", System.Data.SqlDbType.NVarChar, 500000, "HitHighlightedProperties"); childInsertCommand.Parameters.Add("@ContentClass", System.Data.SqlDbType.NVarChar, 50, "ContentClass"); childInsertCommand.Parameters.Add("@IsDocument", System.Data.SqlDbType.Bit, 0, "IsDocument"); childInsertCommand.Parameters.Add("@PictureThumbnailUrl", System.Data.SqlDbType.NVarChar, 500, "PictureThumbnailUrl"); childInsertCommand.Parameters.Add("@Url", System.Data.SqlDbType.NVarChar, 500, "Url"); childInsertCommand.Parameters.Add("@ServerRedirectedUrl", System.Data.SqlDbType.NVarChar, 500, "ServerRedirectedUrl"); childInsertCommand.Parameters.Add("@FileExtension", System.Data.SqlDbType.NVarChar, 500, "FileExtension"); childInsertCommand.Parameters.Add("@SpSiteUrl", System.Data.SqlDbType.NVarChar, 500, "SpSiteUrl"); childInsertCommand.Parameters.Add("@docvector", System.Data.SqlDbType.NVarChar, 500, "docvector"); childInsertCommand.Parameters.Add("@fcocount", System.Data.SqlDbType.Int, 0, "fcocount"); childInsertCommand.Parameters.Add("@fcoid", System.Data.SqlDbType.NVarChar, 50, "fcoid"); childInsertCommand.Parameters.Add("@PictureWidth", System.Data.SqlDbType.Int, 0, "PictureWidth"); childInsertCommand.Parameters.Add("@PictureHeight", System.Data.SqlDbType.Int, 0, "PictureHeight"); da.InsertCommand = childInsertCommand; //if we've found a number of rows <= the total rows in the result set AND //the current result set contains > 0 results (there are still new results being found) AND //we've found <= the maximum number of rows we're allowing to be saved while (rowsFound <= results.TotalRows && results.RowCount > 0 && rowsFound <= maxResults) { da.Update(results.Table); //set the start row = the last row we found query.StartRow = lastRow; //increment the last row we found by the number of results we retrieved lastRow += results.RowCount; rowsFound += results.RowCount; Logging.Logger.Instance.Info(String.Format("Results Found: {0}; Last Result Found: {1}", rowsFound, query.StartRow), Logging.DiagnosticsCategories.eCaseSearch); resultsTableCollection = query.Execute(); results = resultsTableCollection[ResultType.RelevantResults]; } } } using (System.Data.SqlClient.SqlDataAdapter permsAdapter = new System.Data.SqlClient.SqlDataAdapter()) { //for permissions, always remove all items and then add them back using (System.Data.SqlClient.SqlCommand permsDeleteCommand = new System.Data.SqlClient.SqlCommand()) { permsDeleteCommand.Connection = conn; permsDeleteCommand.Transaction = trans; permsDeleteCommand.CommandText = @"DELETE FROM SavedSearchResultPermissions WHERE SavedSearchResultsId = @SavedSearchResultsId "; permsDeleteCommand.Parameters.Add("@SavedSearchResultsId", System.Data.SqlDbType.BigInt); permsDeleteCommand.Parameters["@SavedSearchResultsId"].Value = searchRowIdentity; permsDeleteCommand.ExecuteNonQuery(); } using (System.Data.SqlClient.SqlCommand permsInsertCommand = new System.Data.SqlClient.SqlCommand()) { permsInsertCommand.Connection = conn; permsInsertCommand.Transaction = trans; permsInsertCommand.CommandText = @"INSERT INTO SavedSearchResultPermissions ( SavedSearchResultsId, PermissionName ) VALUES ( @SavedSearchResultsId, @PermissionName )"; permsInsertCommand.Parameters.Add("@SavedSearchResultsId", System.Data.SqlDbType.BigInt); permsInsertCommand.Parameters["@SavedSearchResultsId"].Value = searchRowIdentity; permsInsertCommand.Parameters.Add("@PermissionName", System.Data.SqlDbType.NVarChar, 100, "PermissionName"); foreach (object account in shareWithPeopleEditor.Accounts) { permsInsertCommand.Parameters["@PermissionName"].Value = account.ToString(); permsInsertCommand.ExecuteNonQuery(); } } } } trans.Commit(); Microsoft.SharePoint.Utilities.SPUtility.Redirect( Microsoft.SharePoint.Utilities.SPUtility.GetPageUrlPath(Context) + String.Format("?id={0}", searchRowIdentity), Microsoft.SharePoint.Utilities.SPRedirectFlags.Default, Context ); } } } } } PopulateSavedSearchResultsSetsInfo(); SetFormDisplayMode(false); }
public SearchResponseWrapper Search(string searchText) { var searchRows = new List<SearchTableRowsResult>(); using (var site = new SPSite(SharepointSiteUrl)) { var web = site.OpenWeb(); web.AllowUnsafeUpdates = true; var ssaProxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy. GetProxy(SPServiceContext.GetContext(new SPSite(SharepointSiteUrl))); var keywordQuery = new KeywordQuery(ssaProxy); keywordQuery.ResultsProvider = SearchProvider.SharepointSearch; keywordQuery.QueryText = searchText + " +isDocument:1"; keywordQuery.HiddenConstraints = "site:\"" + SharepointSiteUrl + "\""; keywordQuery.KeywordInclusion = KeywordInclusion.AllKeywords; keywordQuery.ResultTypes |= ResultType.RelevantResults; keywordQuery.SelectProperties.Add("Title"); keywordQuery.SelectProperties.Add("Path"); keywordQuery.SelectProperties.Add("HitHighlightedSummary"); var searchResults = keywordQuery.Execute(); if (searchResults.Exists(ResultType.RelevantResults)) { var searchResultTable = searchResults[ResultType.RelevantResults]; var result = new DataTable {TableName = "SearchResults"}; result.Load(searchResultTable, LoadOption.OverwriteChanges); searchRows.AddRange(from DataRow resultRow in result.Rows select new SearchTableRowsResult() { Value = resultRow.ItemArray[0].ToString(), }); } web.AllowUnsafeUpdates = false; } var response = new SearchResponseWrapper() { SearchResponse = new SearchResponse() { Query = new SearchResult() { Metadata = new SearchResponseMetaData() { }, PrimaryQueryResult = new SearchPrimaryQueryResult() { RelevantResults = new SearchRelevantResults() { Table = new SearchTable() { Rows = new SearchTableRows() { Results = searchRows } } } } } } }; return response; }