JnBrymn / minglbot

0 stars 0 forks source link

add get_user Abstract Syntax Tree #25

Open JnBrymn opened 10 years ago

JnBrymn commented 10 years ago

Build a language for user retrieval based upon python classes

The should be used like this

get_users(
    And(
        FriendOf('a','b'),FriendOf('c','d'),FriendOf('e','f'),
        Or(
            FollowerOf('g','h'),FollowerOf('i','j')
        )
    )
)

Issuing that should

JnBrymn commented 10 years ago

A query for

get_users(
    And(
        FriendOf('a','b'),FriendOf('c','d'),FriendOf('e','f'),
        Or(
            FollowerOf('g','h'),FollowerOf('i','j')
        )
    )
)

Should result in a cypher query

MATCH (x:User) WHERE x.screen_name IN ["a","b"]
  WITH collect(id(x)) AS fr0_id

MATCH (x:User) WHERE x.screen_name IN ["c","d"]
  WITH fr0_id, collect(id(x)) AS fr1_id

MATCH (x:User) WHERE x.screen_name IN ["e","f"]
  WITH fr0_id, fr1_id, collect(id(x)) AS fr2_id

MATCH (x:User) WHERE x.screen_name IN ["i","h","j","g"]
  WITH fr0_id, fr1_id, fr2_id, collect(id(x)) AS fo0_id

MATCH
  (fr0)-[:FOLLOWS]->(target),
  (fr1)-[:FOLLOWS]->(target),
  (fr2)-[:FOLLOWS]->(target),
  (target)-[:FOLLOWS]->(fo0)
WHERE
      id(fr0) IN fr0_id
  AND id(fr1) IN fr1_id
  AND id(fr2) IN fr2_id
  AND id(fo0) IN fo0_id
RETURN count(*) AS count, target.id AS id
ORDER BY count DESC
LIMIT 1000;