[feature request]random pick node

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 
			}
		}
1 Like

Hey @yupengfei

Please open an issue on Github and we can do this at some point.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

See 3226 issue for more details