What I want to do is random pick N node to recommend to the user, now I do it in two query, first query the count of node satisfy the requirement, then I calculate a offset randomly, to implement the feature that random recommendation.
If there is a query like
q(func: ..., random: N)
This query will be much faster.
Blow is the detail of what I have done now.
First, I count all node satisfy the requirement
{
me as var(func:eq(user_id, %s)) {
uname
A as university_name
total_score
}
var(func: uid(me)) {
fl as follow {
}
}
TopRecommendationCount(func:eq(university_name, val(A))) @filter(gt(total_score, %d) and not ( uid(me, fl))) {
total: count(uid)
}
}
then I calculate a offset randomly, and then another query
{
me as var(func:eq(user_id, %s)) {
uname
A as university_name
total_score
}
var(func: uid(me)) {
fl as follow {
}
}
TopRecommendations(func:eq(university_name, val(A)), first: %d, offset: %d) @filter(gt(total_score, %d) and not ( uid(me, fl))) {
user_id
uname
university_name
total_score
}
}