Graph Blog analysed Part 1

Graph Blog analysed Part 1

  • @Tsartsaris

    Posted on 2013-10-22

    ‚ÄčWhat you see here....
    is nothing more than a simple blog with an isotope layout. Even thought the language used for programming all the features so far is php, the database that this blog is based on is Neo4j.
    Why neo4j?

    The answer is simple: Simplicity, easiness, persistent and a vision for later expanding.
    At the moment everything is plane simple. I have a blog node (I could pass this but thinking about expanding in the future I could let users to create their own blog).

    To create the blog (node) I use Cypher and the merge writing clause. I add a Blog label to quickly short the Blog nodes later if needed.

    MERGE (n:Blog {title : 'Graph Blog'})
    RETURN n;

    Graph Blog analysed 1

    (You can add properties here like time created , author etc.)
    To create the user I use a merge writing clause again with 2 labels

    MERGE (user:User:Admin { name:'Tsartsaris Sotirios' , email:''})
    RETURN user;

    Graph Blog analysed 2

    So after the merge clause I have a user (me) with 2 labels indicating that I am a User and Admin. So it will be easy enough later on to short out simple users with match reading clause.

    MATCH n:User RETURN n;

    I could use separate nodes to define privileges and create relationships to each user to give exclusive rights, but in my opinion it's a lot easier to use labels.
    Next step is to create a post.

    MERGE (n:Post { title : 'Post Tile' , slug : 'Post Slug' , img_url : '/var/www/image something' , body_url : '/var/www/text something' , created : 'the timestamp' , author : 'Tsartsaris Sotirios' })
    RETURN n;

    Graph Blog analused 3

    Let's brake down the cypher query above: I use MERGE again (even thought duplicates are treated in php).

    I add a LABEL :Post so later on to retrieve posts I can MATCH on this label.
    Title is the title as to be seen in the post.
    The Slug will be used in the get url to query the database and retrieve the Post.
    I use a preview image which I save the src as property.
    And the body url of my post I save it as a txt document. You could save the body of the post in a property but I do not recommend this, Neo4j is not for this purpose.
    The created timestamp and Author are extra properties to retrieve those values fast later on, even though I am creating relationships to indicate those values (You will see later on).



Social Me!

Twitter Logo LinkedIn Logo Google+ Logo Tumblr Logo