RethinkDB Python递归文档过滤器

时间:2015-08-05 23:33:18

标签: python recursion rethinkdb rethinkdb-python

尝试使用Python包装器对RethinkDB进行递归过滤器查询。让它运作起来很麻烦。

尝试了很多查询的变体,但无济于事。基本上,我试图找到没有嵌套在label下的文档的行与特定的user_id。

简单来说:如果当前用户已经标记了此示例,请不要再将其返回给他们。

我的非工作查询:

open_tasks = rdbt \
    .order_by(index=r.desc('labels_completed')) \
    .filter(r.row['locked'] == False) \
    .filter(lambda task:
            task['labels']['user_id'] != current_user.id) \
    .limit(qty) \
    .run(conn)

我的数据集

[
    {
        "id": "e54893b4-b1d0-49c5-b6aa-9aa9e7d2b73b",
        "image": "https://dl.dropboxusercontent.com/u/5822/crowdlabeler/ABLXOTODWJKTXECYZTST.jpg",
        "labels": [
            {
                "account_qty_labeled": 54,
                "account_signup_date": "Tue Aug 04 2015 10:12:25 GMT-04:00",
                "compensation": 0.01,
                "dataset_id": 144,
                "label": {
                    "$$hashKey": "object:45",
                    "answer": "Yes",
                    "selected": true
                },
                "label_duration_sec": 3,
                "labeled_at": "Wed Aug 05 2015 16:26:04 GMT-05:00",
                "sess_duration_sec": 3,
                "sess_qty_labeled": 0,
                "user_id": 1
            }
        ],
        "labels_completed": 0,
        "locked": false,
        "text": "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate adipisci vero minus laudantium reprehenderit exercitationem eius, suscipit facilis laboriosam consequuntur, eligendi quis mollitia excepturi deserunt dicta, dolorem quaerat pariatur provident sint explicabo. Magnam possimus dolorum beatae quidem excepturi quibusdam dolore reprehenderit accusantium quae ad libero, voluptatum laborum, incidunt, voluptate reiciendis."
    },
    {
        "id": "9f08869e-79fd-49c0-a184-c43d2a1c95cf",
        "image": "https://dl.dropboxusercontent.com/u/5822/crowdlabeler/ACSGHDYECQWQXDHIOBYC.jpg",
        "labels": [],
        "labels_completed": 0,
        "locked": false,
        "text": "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate adipisci vero minus laudantium reprehenderit exercitationem eius, suscipit facilis laboriosam consequuntur, eligendi quis mollitia excepturi deserunt dicta, dolorem quaerat pariatur provident sint explicabo. Magnam possimus dolorum beatae quidem excepturi quibusdam dolore reprehenderit accusantium quae ad libero, voluptatum laborum, incidunt, voluptate reiciendis."
    },
    {
        "id": "9fba0a39-4cfd-4a97-b48f-e8bf2b0d46c5",
        "image": "https://dl.dropboxusercontent.com/u/5822/crowdlabeler/ADMNIUYKUHAIOHMAFXBK.jpg",
        "labels": [],
        "labels_completed": 0,
        "locked": false,
        "text": "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate adipisci vero minus laudantium reprehenderit exercitationem eius, suscipit facilis laboriosam consequuntur, eligendi quis mollitia excepturi deserunt dicta, dolorem quaerat pariatur provident sint explicabo. Magnam possimus dolorum beatae quidem excepturi quibusdam dolore reprehenderit accusantium quae ad libero, voluptatum laborum, incidunt, voluptate reiciendis."
    }
]

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

这是一个艰难的,但解决方案最终是双重的。

保存时稍微修改架构,然后使用RethinkDB的_db.Stuffs .Where(n => n.NationId == User.NationId) .OrderBy(x => x.DateSent) .Select(x=> new Stuff { A = x.A, B = x.B .... /*Dont list attachment*/}); 方法。

以下是修改后的查询,效果很好。

contains