在内部查询中解析大于值

时间:2015-11-04 20:40:39

标签: android parse-platform

我正在使用Parse SDK进行数据存储。在我的应用程序中,用户可以对某些内容发表评论。该应用程序还具有通知功能,在您评论某些内容时,如果其他人对您发表评论,它会通知您,类似于Facebook。例如(“John Smith也评论了Sally的锻炼”)

我的查询如下:

    ParseQuery<ParseObject> innerQueryCommentsAlso = ParseQuery.getQuery("Comment");
    innerQueryCommentsAlso.whereEqualTo("commentOwnerID", ParseUser.getCurrentUser().get("userID"));


    ParseQuery<ParseObject> queryCommentsAlsoFinal = ParseQuery.getQuery("Comment");
    queryCommentsAlsoFinal.whereMatchesKeyInQuery("commentWorkoutID", "commentWorkoutID", innerQueryCommentsAlso);
    queryCommentsAlsoFinal.whereNotEqualTo("commentOwnerID", ParseUser.getCurrentUser().get("userID"));
    queryCommentsAlsoFinal.include("commentOwner");
    queryCommentsAlsoFinal.include("commentWorkout");
    queryCommentsAlsoFinal.include("commentWorkout.workoutOwner");
    queryCommentsAlsoFinal.orderByDescending("commentDate");

我需要做的事情(或者想要做的)是只在queryCommentsAlsoFinal中获取在innerQueryCommentsAlso中找到的最后一条注释之后发生的注释。注释包含一个字段,其中包含时间戳值的注释日期,因此比查询更大,但我不确定这是否可行。在获得结果后,我可能会对算法感到棘手,但因为Parse只允许从查询中返回1000个结果,所以我希望尽可能地限制结果。

1 个答案:

答案 0 :(得分:0)

您可以分两步完成:

  1. 首先获取当前用户的最后评论。
  2. 然后获取所有评论,而不是在所有者的最后评论之后发生的。
  3. ParseQuery<ParseObject> lastCommentQuery = ParseQuery.getQuery("Comment");
    lastCommentQuery.whereEqualTo("commentOwnerID", ParseUser.getCurrentUser().get("userID"));
    lastCommentQuery.orderByDescending("commentDate");
    lastCommentQuery.setLimit(1);
    lastCommentQuery.findInBackground(new FindCallback<Transaction>() {
        @Override
        public void done(List<Transaction> list, ParseException e) {
            if (e != null) {
                Date lastCommentDate = null;
                if (list.size() == 1) {
                    lastCommentDate = list.get(0).getDate("commentDate");
                }
                ParseQuery<ParseObject> queryCommentsAlsoFinal = ParseQuery.getQuery("Comment");
                if (lastCommentDate != null) {
                    queryCommentsAlsoFinal.whereGreaterThan("commentDate", lastCommentDate);
                }
                queryCommentsAlsoFinal.whereMatchesKeyInQuery("commentWorkoutID", "commentWorkoutID", innerQueryCommentsAlso);
                queryCommentsAlsoFinal.whereNotEqualTo("commentOwnerID", ParseUser.getCurrentUser().get("userID"));
                queryCommentsAlsoFinal.include("commentOwner");
                queryCommentsAlsoFinal.include("commentWorkout");
                queryCommentsAlsoFinal.include("commentWorkout.workoutOwner");
                queryCommentsAlsoFinal.orderByDescending("commentDate");
    
                //... execute queryCommentsAlsoFinal
            }
        }
    });