Results 1 to 3 of 3

Thread: [neo4j] Building up the HelloWorlds example with tags property

  1. #1
    Join Date
    Apr 2012
    Posts
    6

    Default [neo4j] Building up the HelloWorlds example with tags property

    Hi all,

    I'm new to graph databases and spring, trying to learn from the examples on git. I downloaded the HelloWorlds example and got everything working. what I'd like to do is add a tags property to Worlds, so one could tag Earth is 'blue', 'water', 'civilization', etc. I added some tags to every world. What i'd like to be able to do is search by tag and get all worlds.

    so I added to World; I put set by varargs in constructor
    PHP Code:
    @Indexed(indexName "tags-index")
        private 
    Set<Stringtags = new HashSet<String>(); 
    And added method to WorldRepositoryImpl
    PHP Code:
    public Iterable<WorldfindResourcesByTag(String tag) {
            return 
    worldRepository.findAllByPropertyValue("tags-index""tags"tag);
        } 
    I added call to app
    PHP Code:
    Iterable<WorldbWorlds repo.findResourcesByTag("blue"); 
    but it returns nothing, when I started stepping thru but couldn't really follow along. I thought trying to make it a relationship but what would the end node be? A tag class didn't seem efficient, but maybe i was wrong? Ideas?

    Thanks for any advise!

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Good idea but it works a bit differently.

    You can store the tags as property on the world but it makes much more sense to store them as nodes. (And you cannot index collection attributes - yet - if you think this is important please file an JIRA issue at http://spring.neo4j.org/issues).

    The tag as node is not inefficient but the way graphs work.

    so you create

    Code:
    @NodeEntity
    public class Tag {
      @Indexed(unique = true) String name;
    }
    
    @NodeEntity
    public class World {
       @RelatedTo
       Set<Tag> tags;
    }  
    
    // and then add the tags either by adding them to the set or using template.createRelationshipBetween

    HTH

    Michael

  3. #3
    Join Date
    Apr 2012
    Posts
    6

    Default

    Hi Michael,

    Thanks for clarifying I should have implemented it that way the first time around.

    Says a lot that you're here answering questions as I have been watching your presentations and reading your Good Relationships tutorial.

    Thanks!

    Quote Originally Posted by MichaelHunger View Post
    Good idea but it works a bit differently.

    You can store the tags as property on the world but it makes much more sense to store them as nodes. (And you cannot index collection attributes - yet - if you think this is important please file an JIRA issue at http://spring.neo4j.org/issues).

    The tag as node is not inefficient but the way graphs work.

    so you create

    Code:
    @NodeEntity
    public class Tag {
      @Indexed(unique = true) String name;
    }
    
    @NodeEntity
    public class World {
       @RelatedTo
       Set<Tag> tags;
    }  
    
    // and then add the tags either by adding them to the set or using template.createRelationshipBetween

    HTH

    Michael

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •