3

I'm trying to query Episerver Community to get paged approved topics within a date range (e.g. within the last 2 days) that are ordered by the thread's last activity (activity being the thread's last approved reply or the thread's creation date if approved replies are 0).

I've tried using the GetTopics() method and aside from not being able to pass a date range, LastReply includes replies that are still in the moderation queue so the sort doesn't work correctly.

I've also tried to use the Query API but I'm unsure if it's possible to construct a query as complex as this. Is there any way of including AND/OR in the sort as well as making sure that the LastReply is approved? This is as far as I've got:

        var topicQuery = new TopicQuery
        {
            Created = new DateTimeCriterion(),
            Status = new EntityStatusCriterion
            {
                Operator = FlagsOperator.Equal,
                Value = EntityStatus.Approved
            },
            LastReply = new ReplyCriterion{
                Status = new EntityStatusCriterion(),
                Created = new DateTimeCriterion()
            }
        };

        //filter by days
        if (withinDays > 0)
        {
            topicQuery.Created.Operator = ComparisonOperator.GreaterThan | ComparisonOperator.Equals;
            topicQuery.Created.Value = DateTime.Now.AddDays(-withinDays);
        }

        //sort, this is incorrect, I am trying to sort by last approved reply date or created date if not available
        //Last reply is sometimes not approved and it needs to be...
        topicQuery.OrderBy.Add(new CriterionSortOrder(topicQuery.Created, SortingDirection.Descending));
        topicQuery.OrderBy.Add(new CriterionSortOrder(topicQuery.LastReply.Created, SortingDirection.Descending));

        var result = QueryHandler.GetQueryResult<Topic, MessageCollection>(topicQuery, page, pageSize);
Rach
  • 43
  • 4

0 Answers0