Announcement Announcement Module
Collapse
No announcement yet.
[neo4j] Building up the HelloWorlds example with tags property Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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
    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

    Comment


    • #3
      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!

      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

      Comment

      Working...
      X