2016-05-23 11 views
2

range()を使用して部分的な結果を返すようにしています。また、全体的な結果のレコードの総数をレスポンスの一部として返す必要があります。応答は次のようになります。Gremlin:結果の数と結果を返す

{ 
    postcount: 239, 
    posts: [ 
    { 
     postID: 1, 
     postTitle:'First post' 
    }, 
    { 
     postID: 2, 
     postTitle:'Second post' 
    }, 
    { 
     postID: 3, 
     postTitle:'Third post' 
    } 
    ] 
} 

私は運で、この作品のようなものを作ろうとしてきた:

g.V().hasLabel('post').as('postcount','posts').select('postcount','posts').by(__.count()).by(__.range(0,2).valueMap())

各項目にpostcount = 1プロパティを追加しこと。これをどうすれば調整できますか?

答えて

1

回答:

In 3.2.0:

> g.V().hasLabel("person").fold().project("users","userCount").by(range(local, 
> 0, 2)).by(count(local)) 

前3.2.0:

g.V().hasLabel("person").fold().as("users","userCount").select("users","userCount").by(range(local, 
> 0, 2)).by(count(local)) 
1

unionステップを実行して、何をしたいかを達成できます。例:

詳細情報については
g.V().hasLabel("post").union(
       __.select("postcount").by(__.count()), // postcount property 
       __.range(0,2).valueMap() // your range 
      ) //end of union 

docs

+0

'Union'は正しいアプローチのように思えるが、私はまだ構文で苦労しています。私はあなたの例を試しましたが、「トラバース戦略は完了し、トラバーサルはもはや調整できません」。私はまた、以下のことを試しました: 'gV()。hasLabel(" post ")。as(" postcount "、" post ")。union(select(" postcount " (__。range(0,2).valueMap())) 'によって返されますが、post、count = 1、post、count = 1の各行を返します。 – Fook

+0

ああ、あなたの例では、 '.count()'の前に '_'がありません。しかし、「範囲」に関係なくすべての投稿を出力するだけで、カウントは含まれません。それがなぜ機能しないのか分かりません。なぜなら、私は思考プロセスに従うからです。私はそれが重要であればコンソールでこれを実行しています。 – Fook

1

をチェックあなたは2つのクエリにそれを破ることができます:ダニエルKuppitzごとGremlin-Users listで見つけ

pCount = g.V().hasLabel("post").count().next(); 
pList = g.V().hasLabel("post").range(0,2).valueMap().toList(); 
map = ["postcount": pCount, "posts": pList] 
関連する問題