Hi Arin,

I just ran into this same problem. I am not sure about the scalability
of my solution, but I only had 20,000 users. It may scale, but I just
wanted you to know that I didn't test for it. My goal was to "step"
into the graph using a string based query, that is supplying a user's
name. An index seemed like overkill to me.

I created my users with all of the relationships that I needed for
modeling, however I created one extra relationship that attached to a
sub-reference node that attached to the reference node.  So when I
needed to needed a user, I could open the reference node, got to the
"people" sub-reference node, and traverse to all of my people nodes
adding them to a hashmap<string:name,long:nodeId>. This hashmap can be
used to resolve users to their nodeId for other queries along the
graph.

Code is below.

-Todd

        private static HashMap<String,Long> getMap(String type, NeoService neo)
        {
                long referenceNodeId = 0;
                HashMap<String,Long> map = new HashMap<String,Long>();
                Node referenceNode = neo.getNodeById(referenceNodeId);
                if (type.equals("topic"))
                {
                        Node topicNodes =
referenceNode.getSingleRelationship(RelationshipTypes.TOPICS,
Direction.OUTGOING).getEndNode();
                        for (Relationship topic :
topicNodes.getRelationships(RelationshipTypes.TOPIC,
Direction.OUTGOING))
                {
                                Node topicNode = topic.getEndNode();
                                
map.put(topicNode.getProperty("topic").toString(), topicNode.getId());
                }
                }
                else if (type.equals("person"))
                {
                        Node personNodes =
referenceNode.getSingleRelationship(RelationshipTypes.PEOPLE,
Direction.OUTGOING).getEndNode();
                        for (Relationship person :
personNodes.getRelationships(RelationshipTypes.PERSON,
Direction.OUTGOING))
                {
                                Node personNode = person.getEndNode();
                                
map.put(personNode.getProperty("name").toString(), personNode.getId());
                }
                }
                return map;
        }





On Thu, Dec 10, 2009 at 2:19 PM, Arin Sarkissian <[email protected]> wrote:
> Hey guys,
>
> I'm pretty new to Neo4j, especially the indexing stuff.
>
> Here's my situation. I want to be able to get nodes via one of their
> properties; in this case let's say the Nodes represent a user & I want
> to be able to grab a User's node via their username.
>
> So, my initial attempt may be naive (no batching etc) but I've been
> reading thru a a large text file (CSV format: username, userid),
> creating a node for each of these lines & indexing the username
> component.
>
> Now this needs to be unique (given that usernames are unique) so I've
> been using the SingleValueIndex and have run into a problem: It looks
> like the SingleValueIndex actually does allow multiple values for a
> given lookup (ex: username = phatduckk) however when trying to fetch a
> Node from the index that has multiples (ie: username=phatduckk was
> indexed twice) I get a NotFoundException with "More than one
> relationship xxxx" as the message.
>
> I have posted a skeleton piece of code that surfaces this problem over
> at: http://gist.github.com/253553
> This code does not make sure that the Node being indexed for a key is
> always the same - it actually does the opposite: it tries to index
> username=phatduckk w/ a different node each time.
>
> The bit of code at http://gist.github.com/253569 does the opposite: i
> tries to index the same node for the index username=phatduckk each
> time.
>
> I also have a few random questions sprinkled in the code as comments
> which illustrate my noobiness =)
>
> Honestly, I'm not claiming this is a bug - I may be completely
> misusing and misunderstanding the indexing functionality but with my
> limited experience it doesn't seem that SingleValueIndex is "single"
> at all (hopefully - i'm just wrong and made a dumb mistake).
>
> Thanks for the help guys,
> Arin
> _______________________________________________
> Neo mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to