Fix forum indexer and add date/time to forum search result output

This commit is contained in:
Sebastiaan Janssen
2015-06-25 18:40:51 +02:00
parent 2865debfef
commit 4791f0d1e2
3 changed files with 25 additions and 11 deletions
+1
View File
@@ -57,6 +57,7 @@
<div class="type-context">
<div class="type-name"><%=result.GetTitle() %></div>
<span class="type-datetime"><%=result.GetDate() %></span>
<div class="type-description"><%=result.GenerateBlurb(300) %></div>
</div>
</a>
+20 -7
View File
@@ -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);
}
+4 -4
View File
@@ -127,7 +127,7 @@ LEFT OUTER JOIN umbracoNode u2 ON (forumTopics.memberId = u2.id AND u2.nodeObjec
/// <returns></returns>
public IEnumerable<ReadOnlyTopic> 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<ReadOnlyTopic, ReadOnlyComment, ReadOnlyTopic>(
new TopicCommentRelator().Map,
sql, new { count = maxCount });
sql);
return result;
}