/// <summary> /// Renders search results into HTML string. /// </summary> private string RenderResults(DataSet results, string searchText) { if (results == null) { // No results return(String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"); } else { UIRepeater repSearchResults = new UIRepeater(); IDictionary <string, DataView> indexCategories = new Dictionary <string, DataView>(StringComparer.InvariantCultureIgnoreCase); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (DataRow row in results.Tables["results"].Rows) { string index = (string)row["index"]; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, new DataView(results.Tables["results"], "index = '" + index + "'", "", DataViewRowState.CurrentRows)); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", new DataView(results.Tables["results"])); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = TransformationHelper.LoadTransformation(this, PredictiveSearchResultItemTransformationName); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Tables["results"].Rows.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, CreateSearchUrl(searchText))); } return(stringWriter.ToString()); } }
/// <summary> /// Renders search results into HTML string. /// </summary> private string RenderResults(List <SearchResultItem> results, string searchText) { if (results == null || results.Count == 0) { // No results return(String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"); } else { UIRepeater repSearchResults = new UIRepeater(); var indexCategories = new Dictionary <string, IEnumerable <SearchResultItem> >(StringComparer.InvariantCultureIgnoreCase); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (SearchResultItem resultItem in results) { string index = resultItem.Index; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, results.Where(item => String.Equals(item.Index, index, StringComparison.InvariantCultureIgnoreCase))); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", results); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = TransformationHelper.LoadTransformation(this, PredictiveSearchResultItemTransformationName); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, CreateSearchUrl(searchText))); } return(stringWriter.ToString()); } }
/// <summary> /// Renders search results into HTML string. /// </summary> private static string RenderResults(DataSet results, string searchText, string PredictiveSearchNoResultsContent, bool PredictiveSearchDisplayCategories, int PredictiveSearchMaxResults, string PredictiveSearchResultItemTransformationName, string PredictiveSearchMoreResultsContent, string searchURL) { if (results == null) { // No results return(String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"); } else { UIRepeater repSearchResults = new UIRepeater(); IDictionary <string, DataView> indexCategories = new Dictionary <string, DataView>(); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (DataRow row in results.Tables["results"].Rows) { string index = (string)row["index"]; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, new DataView(results.Tables["results"], "index = '" + index + "'", "", DataViewRowState.CurrentRows)); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", new DataView(results.Tables["results"])); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = new TextTransformationTemplate(CacheHelper.Cache(cs => CMS.PortalEngine.TransformationInfoProvider.GetTransformation(PredictiveSearchResultItemTransformationName), new CacheSettings(60, PredictiveSearchResultItemTransformationName)).TransformationCode); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Tables["results"].Rows.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, URLHelper.UpdateParameterInUrl(searchURL, "searchtext", HttpUtility.UrlEncode(searchText)))); } return(stringWriter.ToString()); } }
/// <summary> /// Renders search results into HTML string. /// </summary> private string RenderResults(DataSet results, string searchText) { if (results == null) { // No results return String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"; } else { UIRepeater repSearchResults = new UIRepeater(); IDictionary<string, DataView> indexCategories = new Dictionary<string, DataView>(); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (DataRow row in results.Tables["results"].Rows) { string index = (string)row["index"]; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, new DataView(results.Tables["results"], "index = '" + index + "'", "", DataViewRowState.CurrentRows)); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", new DataView(results.Tables["results"])); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = CMSDataProperties.LoadTransformation(this, PredictiveSearchResultItemTransformationName, false); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Tables["results"].Rows.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, CreateSearchUrl(searchText))); } return stringWriter.ToString(); } }