From 4791f0d1e212989dea2714b13ee641df7a650a06 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 25 Jun 2015 18:40:51 +0200 Subject: [PATCH] Fix forum indexer and add date/time to forum search result output --- OurUmbraco.Site/Views/Search/Search.aspx | 1 + our.umbraco.org/SearchResultExtensions.cs | 27 +++++++++++++++++------ uForum/Services/TopicService.cs | 8 +++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/OurUmbraco.Site/Views/Search/Search.aspx b/OurUmbraco.Site/Views/Search/Search.aspx index eb181006..893b73b5 100644 --- a/OurUmbraco.Site/Views/Search/Search.aspx +++ b/OurUmbraco.Site/Views/Search/Search.aspx @@ -57,6 +57,7 @@
<%=result.GetTitle() %>
+ <%=result.GetDate() %>
<%=result.GenerateBlurb(300) %>
diff --git a/our.umbraco.org/SearchResultExtensions.cs b/our.umbraco.org/SearchResultExtensions.cs index 2f802712..8b237b8b 100644 --- a/our.umbraco.org/SearchResultExtensions.cs +++ b/our.umbraco.org/SearchResultExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data.SqlClient; using System.Web; using Examine; @@ -17,10 +18,13 @@ namespace our public static string GetIcon(this SearchResult result) { var icon = "icon-Chat"; - if(result.Fields["nodeTypeAlias"] == "project"){ + if (result.Fields["nodeTypeAlias"] == "project") + { icon = "icon-Box"; - }else if(result.Fields["nodeTypeAlias"] == "documentation"){ - icon = "icon-Book-alt"; + } + else if (result.Fields["nodeTypeAlias"] == "documentation") + { + icon = "icon-Book-alt"; } return icon; @@ -30,13 +34,22 @@ namespace our { try { - return HttpContext.Current.Server.HtmlEncode(string.Format("Last update: {0}", GetFormattedDateTime(result["updateDate"], "MMMM dd, yyyy"))); + var createDate = GetFormattedDateTime(result["createDate"], "MMMM dd, yyyy"); + var updateDate = GetFormattedDateTime(result["updateDate"], "MMMM dd, yyyy"); + return + HttpContext.Current.Server.HtmlEncode(string.Format("Created: {0} - Last update: {1}", createDate, + updateDate)); } catch (FormatException ex) { // Catches "String was not recognized as a valid DateTime." errors // TODO: Figure out why these errors occur.. } + catch (KeyNotFoundException ex) + { + // Catches "The given key was not present in the dictionary." errors for result["createDate"] + // TODO: Figure out why these errors occur.. + } return string.Empty; } @@ -47,7 +60,7 @@ namespace our { return GetFormattedDateTime(result["updateDate"], "yyyy-MM-dd HH:mm"); } - catch (FormatException ex) + catch (FormatException ex) { // Catches "String was not recognized as a valid DateTime." errors // TODO: Figure out why these errors occur.. @@ -81,7 +94,7 @@ namespace our : string.Format("/{0}/{1}-{2}.aspx", url.Substring(0, url.LastIndexOf('.')).Trim('/'), result.Fields["__NodeId"], result.Fields["urlName"]); } - if(result.Fields.ContainsKey("url")) + if (result.Fields.ContainsKey("url")) { return result["url"]; } @@ -108,7 +121,7 @@ namespace our } var helper = new UmbracoHelper(UmbracoContext.Current); - + return helper.Truncate(text, noOfChars); } diff --git a/uForum/Services/TopicService.cs b/uForum/Services/TopicService.cs index 64e9fb41..05841ba5 100644 --- a/uForum/Services/TopicService.cs +++ b/uForum/Services/TopicService.cs @@ -127,7 +127,7 @@ LEFT OUTER JOIN umbracoNode u2 ON (forumTopics.memberId = u2.id AND u2.nodeObjec /// public IEnumerable QueryAll(bool ignoreSpam = true, int maxCount = 1000) { - const string sql1 = @"SELECT TOP @count forumTopics.*, u1.[text] as LastReplyAuthorName, u2.[text] as AuthorName, u2.[id] as topicAuthorId + var sql1 = @"SELECT TOP " + maxCount + @" forumTopics.*, u1.[text] as LastReplyAuthorName, u2.[text] as AuthorName, u2.[id] as topicAuthorId, forumComments.body as commentBody, forumComments.created as commentCreated, forumComments.haschildren, forumComments.id as commentId, forumComments.isSpam as commentIsSpam, forumComments.memberId as commentMemberId, forumComments.parentCommentId, forumComments.position, forumComments.score, forumComments.topicId @@ -142,14 +142,14 @@ WHERE ORDER BY forumTopics.updated DESC, forumComments.created DESC "; - const string sqlx = sql1 + sql2; - const string sqli = sql1 + " (forumTopics.isSpam <> 1) AND (forumComments.id IS NULL OR forumComments.isSpam <> 1) AND " + sql2; + var sqlx = sql1 + sql2; + var sqli = sql1 + " (forumTopics.isSpam <> 1) AND (forumComments.id IS NULL OR forumComments.isSpam <> 1) AND " + sql2; var sql = ignoreSpam ? sqlx : sqli; var result = _databaseContext.Database.Query( new TopicCommentRelator().Map, - sql, new { count = maxCount }); + sql); return result; }