def get_todays_recent_posts():
    query = '''
    MATCH (user:USER)-[:PUBLISHED]->(post:POST)<-[:TAGGED]-(tag:TAG)
    WHERE post.date = {today}
    RETURN user.username AS username, post, COLLECT(tag.name) AS tags
    ORDER BY post.timestamp DESC LIMIT 5
    '''

    return GRAPH.run(query, today=neo4jutils.date())
    def get_recent_posts(self):
        query = '''
        MATCH (user:USER)-[:PUBLISHED]->(post:POST)
        OPTIONAL MATCH (post)<-[:TAGGED]-(tag:TAG)
        WHERE user.username = {username}
        RETURN post, COLLECT(tag.name) AS tags
        ORDER BY post.timestamp DESC LIMIT 5
        '''

        return GRAPH.run(query, username=self.identity_value)
    def get_similar_users(self):
        # Find three users who are most similar to the logged-in user
        # based on tags they've both blogged about.
        query = '''
        MATCH (you:USER)-[:PUBLISHED]->(:POST)<-[:TAGGED]-(tag:TAG),
              (they:USER)-[:PUBLISHED]->(:POST)<-[:TAGGED]-(tag)
        WHERE you.username = {username} AND you <> they
        WITH they, COLLECT(DISTINCT tag.name) AS tags
        ORDER BY SIZE(tags) DESC LIMIT 3
        RETURN they.username AS similar_user, tags
        '''

        return GRAPH.run(query, username=self.identity_value)
Exemple #4
0
    def get_commonality_of_user(self, other):
        # Find how many of the logged-in user's posts the other user
        # has liked and which tags they've both blogged about.
        query = '''
        MATCH (they:USER {username: {they} })
        MATCH (you:USER {username: {you} })
        OPTIONAL MATCH (they)-[:PUBLISHED]->(:POST)<-[:TAGGED]-(tag:TAG),
                       (you)-[:PUBLISHED]->(:POST)<-[:TAGGED]-(tag)
        RETURN SIZE((they)-[:LIKED]->(:POST)<-[:PUBLISHED]-(you)) AS likes,
               COLLECT(DISTINCT tag.name) AS tags
        '''

        return GRAPH.run(query, they=other.identity_value, you=self.identity_value).next()