Dave Burke : Freelance .NET Web Developer specializing in Online Communities

CS Queensryche Series: On Aggregated Post List Sorting

It's been a while for a more code-heavy, Operation MindCrime Community Server post.  I haven't been giving Queensryche their due. 


We're an underground revolution working overtime
There's a job for you in the system boy with nothing to sign


This post addresses a CS Forums Space question on how to sort the Aggregated Post List Sorting by Post Title.  Interesting Queensryche topic!

The first thing to remember is that sorting is dictating by the BlogThreadQuery we build in AggregatePostList, which is passed to the Weblog Data Provider.  The BlogThreadQuery.SortBy property supports three sort options as listed in the BlogThreadSortBy enum.

 

public enum BlogThreadSortBy
{
   MostRecent = 0,
   MostViewed = 1,
   MostComments = 2,
   PostTitle = 3 // Added

};

 

We want to sort by title, so we'd need to add an enumator member name and value, say, PostTitle = 3. 

The BlogThreadQuery is created with the new query.SortBy = PostTitle value and sent off to the Weblog Data Provider where a @sqlPopulate parameter is created with a helper BuildQuery() method. 

 

public override ThreadSet GetBlogThreads(BlogThreadQuery query)
{
.....
using(SqlCommand command = new SqlCommand(databaseOwner +
     ".[cs_shared_Threads_GetThreadSet]", connection))
{
    command.CommandType = CommandType.StoredProcedure;
    .....
    command.Parameters.Add("@sqlPopulate", SqlDbType.NText).Value =
          new BlogThreadQueryBuilder(query,databaseOwner).BuildQuery() ;

 

This is a sample @sqlPopulate value returned from BuildQuery(). 


SET Transaction Isolation Level Read UNCOMMITTED Select P.PostID From dbo.cs_Posts P right join dbo.cs_Threads t on (P.ThreadID = T.ThreadID) inner join dbo.cs_Sections S on S.SectionID = P.SectionID where P.SettingsID = 1000 and P.SectionID in (4,17,18,5,3) and S.IsActive = 1 and S.SectionID in (4,17,18,5,3) and S.SectionID = P.SectionID and S.ApplicationType = 1 and P.ApplicationPostType & 1 <> 0 and P.PostConfiguration & 3 = 3 and P.IsApproved = 1 and P.PostDate <= getdate() and P.IsApproved = 1 and P.PostDate <= getdate() Order by P.PostDate desc

What we need to do, of course, is change the "Order by P.PostDate desc."  The way to change this is by applying the new BlogThreadSortBy.PostTitle enumerator member to the CS.SqldataProvider.BlogThreadQueryBuilder.cs ApplySort() method switch statement.

 

switch (query.SortBy) {
case BlogThreadSortBy.MostViewed:
sb.Append(" Order by P.TotalViews");
break;

case BlogThreadSortBy.MostComments:
sb.Append(" Order by TotalReplies");
break;

case BlogThreadSortBy.PostTitle:  // Added
sb.Append(" Order by P.Subject");
break;

default:
sb.Append(" Order by P.PostDate");
break;

}

 

The only thing we'll want to do yet in our scenario to display by post title is to add a query.SortOrder property when building the original query in AggreagtePostlist.cs to display A-Z rather than the default sortby DESC with a Z-A listing.

 

[Queensryche]

Comments (2) | Post RSS RSS comment feed

Posted on 1/15/2007 9:33:29 AM by Dave Burke
Categories: Community Server
Tags:

Related posts

Comments (2) -

1/18/2007 1:22:52 AM Permalink

Hi Dave, nice topic. As I understand this is for CS version 2.1 correct? Or maybe there haven't been major changes in 3.0 concerning the query component?

As a suggestion, we recently found a need to sort by the ranking of topics - maybe its already added in 3.0? Smile

Best,
Anders

Anders Vindberg |

1/18/2007 5:05:32 AM Permalink

Hi, Anders, good to hear from you.  Yes, CS 2.1.  There are new front-end application-specific data controls in Chameleon, but I haven't looked at the 3.0 source enough to see how deep the changes go.  I suspect not very far, since the Query and DBProvider model shouldn't be any different.  A ranking sort, eh? Smile

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke