Hi,
I am trying to create a query that will return a list of Posts that a User has authored. A Post can be shown to other Users and/or a Grouping of Users. This is the code for my query which works, but I am unable to figure out how to get all the attributes for Users and Grouping also included in my results in addition to the vertex ids.
QUERY
CREATE QUERY getMyPosts(STRING uid) FOR GRAPH Rex SYNTAX V2{
SetAccum<VERTEX> @groupingSetAccum;
SetAccum<VERTEX> @userSetAccum;
me = SELECT m
FROM User:m
WHERE m.uid == uid;
posts = SELECT p
FROM me -(authors>)- Post:p;
posts2 = SELECT p
FROM posts:p -(show_to>)- Grouping:g
ACCUM p.@groupingSetAccum += g;
posts3 = SELECT p
FROM posts:p -(show_to_1>)- User:u
ACCUM p.@userSetAccum += u;
results = posts UNION posts2 UNION posts3;
PRINT results[results.@groupingSetAccum AS groups, results.@userSetAccum AS users, results.title AS title, results.description AS description];
}
OUTPUT
[
{
“results”: [
{
“attributes”: {
“description”: “Carbonite web goalkeeper gloves are ergonomically designed to give easy fit”,
“groups”: [
“662737d4-da5e-42f4-879c-02f0a96058be”
],
“title”: “Gloves”,
“users”: [
“e1392d37-70e2-497e-b99d-501b3b9c743c”,
“bf15e203-79a7-4ac5-a220-eb7062c32fed”,
“16fa9550-ec27-48cd-b254-b178ba63ba9c”
]
},
“v_id”: “f66d7eef-b41c-4f80-828d-65391407b83e”,
“v_type”: “Post”
},
…
]
According to the docs:
“Full details of vertices are printed only when part of a vertex set variable or vertex expression set. When a single vertex is printed (from a variable or accumulator whose data type happens to be VERTEX), only the vertex id is printed.”
So I was trying to figure out a way to convert the SetAccum into a vertex set variable but always ran into syntax errors. Maybe I’m going about this in the wrong way.
Any help would be appreciated. Thx
Alvin