bulletlegend
bulletlegend
ATApache TinkerPop
Created by bulletlegend on 8/1/2023 in #questions
Gremlin query has strange behavior with range() and limit()
Hey everyone, I have a Neptune database and use gremlin to query it. I have user vertices that could be connected with edges like "friends", "follows", "blocks", "reports". I want to make a query that gives "suggestions" to the user by presenting him with users that the people he follows follow. These users shouldn't be followed, blocked, or reported by the the current user and also should be up to 3 suggestions per user he follows. I have constructed the following query : g .V(userId) .Out("follows") .As(ConnectingFollowerLabel) .Local<Vertex>(__ .Out("follows") .HasLabel("User") .Not(__.Both("blocks").HasId(userId)) .Not(__.In("reported").HasId(userId)) .Not(__.In("follows").HasId(userId)) .Not(__.HasId(userId)) .Limit<Vertex>(maxProfileSuggestionsPerCommonUser)) .Dedup(); As it is it returns the results as it should. But for users that follow many users it gets kind of slow, so I added a limit() on the users fetched and added pagination with range() like this g .V(userId) .Out("follows") .As(ConnectingFollowerLabel) .Local<Vertex>(__ .Out("follows") .HasLabel("User") .Not(__.Both("blocks").HasId(userId)) .Not(__.In("reported").HasId(userId)) .Not(__.In("follows").HasId(userId)) .Not(__.HasId(userId)) .Limit<Vertex>(maxProfileSuggestionsPerCommonUser)) .Limit<Vertex>(maxProfileSuggestions) .Dedup() .Range<Vertex>(Scope.Global, offset, offsetLimit); As soon as I add the limit and range step the results change and I get suggestions with people I already follow. I tried ordering the result before the range step but that doesn't seem to work either. Any help would be greatly appreciated.
17 replies