в силу некоторых причин я пока не могу использовать для задачи RT-индексы — не получится быстро переделать приложение так, чтобы наряду с выполнением запросов к mysql он их отправлял в sphinx
SELECT * FROM pybb_forum as ff,guardian_groupobjectpermission as gg, auth_permission as pp
WHERE codename = 'view_forum'
AND gg.group_id in (1,2,3)
AND gg.content_type_id = 9
AND ff.id = gg.object_pk
AND gg.permission_id = pp.id;
Forum.objects.extra(
tables = ['guardian_groupobjectpermission', 'auth_permission'],
where = [""" codename = "view_forum"
AND guardian_groupobjectpermission.group_id in (1,2,3)
AND guardian_groupobjectpermission.content_type_id = 9
AND pybb_forum.id = guardian_groupobjectpermission.object_pk
AND guardian_groupobjectpermission.permission_id = auth_permission.id
"""]
)
{
"_id" : 3,
"info" : [
{
"k" : "c",
"v" : 353
},
{
"k" : "e",
"v" : 113
}
]
}
db.test.drop();
db.test.insert({
"_id": 1,
"info": [{"k": "c", "v": 768}, {"k": "d", "v": 345}]
});
db.test.insert({
"_id": 2,
"info": [{"k": "e", "v": 333}]
});
db.test.insert({
"_id": 3,
"info": [{"k": "c", "v": 353}, {"k": "e", "v": 113}]
});
db.test.find().forEach(printjson);
var res = db.test.aggregate([
{$sort: {
"_id": 1
}},
{$unwind: "$info"},
{$group: {
"_id": "$info.k",
"v": {$last: "$info.v"}
}}
]);
printjson(res);
{
"result" : [
{
"_id" : "e",
"v" : 113
},
{
"_id" : "d",
"v" : 345
},
{
"_id" : "c",
"v" : 353
}
],
"ok" : 1
}