Reporting back, I came up with the following query that does what I need:
m = [:];
g.idx("user").get("key", "%query%*")._()[0..5].sideEffect { x = it.key
}.out.in.uniqueObject.loop(3) { it.loops < 2 }.sideEffect {
  if (!m[x]) { m[x] = 0; };
  m[x]++
} >> -1;
m;

* I didn't use mapWithDefault because I'm sending via the REST API and want
to be able to see the values of the map in the result: "{1=1, 2=1, 3=8,
4=1}"
* The out.in is a feature of our data (each user node is always connected to
other user nodes via an intermediary node)
* The [0..5] allows me to page through the index to avoid one massive query.
* I'm thinking perhaps the "aggregate" step would be useful, but I haven't
figured out how to use it yet.
* I will unroll the loop as Marko suggested when I get to optimizing it

Thanks for all the help,
Xavier

On Thu, Sep 8, 2011 at 9:32 AM, Xavier Shay <xavier+ne...@squareup.com>wrote:

> Thanks everyone, this gives me plenty to work with. Will report back.
>
>
> On Thu, Sep 8, 2011 at 7:03 AM, Marko Rodriguez <okramma...@gmail.com>wrote:
>
>> Hey,
>>
>> > Won't this count dupes more than once?
>> >
>> > Xavier's requirements of "how many other nodes are they connected"
>> sounds
>> > like you should only count uniques, and that's why I am checking the
>> size of
>> > groupCount map instead of using count(). Instead of a map you could use
>> a
>> > Set with aggregate(), but I wasn't sure if they'd have the
>> aggregate-loop
>> > fix yet.
>>
>> Then add a uniqueObject to the pipeline.
>>
>>        g.idx(index_name)[[key:value]].both.loop(1){it.loops <
>> depth}.uniqueObject.count()
>>
>> > Also Xavier said, "For all nodes in a particular index". I took that to
>> mean
>> > all nodes in an index, not all nodes for a particular value in an index,
>> > hence the wildcard query:
>> >
>> > index_nodes = g.idx(index_name).get(index_key,Neo4jTokens.QUERY_HEADER +
>> > "*")
>> >
>> > However, I am not sure/can't remember if you can do a wildcard query
>> without
>> > at least one leading character.
>>
>>
>> Oh.... then yea, the %query% header can be used.
>>
>> Marko.
>>
>> http://markorodriguez.com
>> _______________________________________________
>> Neo4j mailing list
>> User@lists.neo4j.org
>> https://lists.neo4j.org/mailman/listinfo/user
>>
>
>
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to