Episerver社区查询并按上次活动排序

时间:2015-06-29 09:30:19

标签: episerver

我正在尝试查询Episerver社区,以便在该主题的最后一项活动订购的日期范围内(例如,在过去2天内)获取分页已批准主题(活动是该主题的最后已批准回复或线程的创建日期,如果已批准的回复为0)。

我尝试过使用GetTopics()方法,除了无法传递日期范围外,LastReply还包含仍在审核队列中的回复,因此排序无法正常工作。

我还尝试使用查询API,但我不确定是否可以构建一个像这样复杂的查询。有没有办法在排序中包含AND / OR以及确保LastReply被批准?就我而言:

        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);

0 个答案:

没有答案