This is what you would use indexing for, for storing starting points that
you can then use for traversing the graph.


<updated-example>

       GraphDatabaseService graphDb = new EmbeddedGraphDatabase("poc_test");
       // ADDED: add an index service to your system
       IndexService index = new LuceneIndexService( graphDb );




       Transaction tx = graphDb.beginTx();
       try {
           for(CSVObject object : csv){
               Node trigramme = graphDb.createNode();
               Node cp = graphDb.createNode();
               Node description = graphDb.createNode();
               Node category = graphDb.createNode();

               Relationship ispartOf =
trigramme.createRelationshipTo(cp, RelTypes.IS_PART_OF);
               Relationship isDescribedBy
= trigramme.createRelationshipTo(description, RelTypes.IS_DESCRIBED_BY);
               Relationship isCategorizedIn
= description.createRelationshipTo(category, RelTypes.IS_CATEGORIZED_IN);

               trigramme.setProperty("value", object.getTrigram());
               cp.setProperty("value", object.getCp());
               description.setProperty("value", object.getDescription());
               category.setProperty("value", object.getCategory());

               ispartOf.setProperty("relationship", "ispartOf ");
               isDescribedBy.setProperty("relationship", "ispartOf");
               isCategorizedIn.setProperty("relationship", "ispartOf");

               // ADDED: add the code for indexing your start nodes
               index.index( description, "description",
description.getProperty("value") );

           }

           tx.success();
       }catch (Exception e){
           e.printStackTrace();
       }
       finally {
           tx.finish();
       }

       public void retreiveStuff( Object descriptionValue ) {

               // ADDED: retrieve your start node through the index before
traversal
               Node description = index.getSingleNode( "description",
descriptionValue );
               if ( description == null ) { throw
theDescriptionValueTheUserProvidedDoesNotExist(); }

               Traverser friendsTraverser = description.traverse(
                       Traverser.Order.BREADTH_FIRST,
                       StopEvaluator.DEPTH_ONE,
                       ReturnableEvaluator.ALL_BUT_START_NODE,
                       RelTypes.IS_DESCRIBED_BY,
                       Direction.INCOMING );
                       // Traverse the node space and print out the result
                       //System.out.println( "Testing values : " );
                       for ( Node friend : friendsTraverser )
                       {

                       System.out.println( "At depth : "+
                       friendsTraverser.currentPosition().depth()+"
with value : "+
                       friend.getProperty( "value" ) );
                       }
       }

</updated-example>


Cheers,
Tobias

On Tue, Jul 6, 2010 at 8:39 AM, Boban Erakovic <[email protected]>wrote:

> Hi,
> the reason of using neo4j is the main problem of my question. Just as Toni
> Menzel said "Directly falling back to the index service does not really
> embrace why you are a graph db at all." The question is, because my
> employee
> want to perform some project, within what he (me) will demonstrate the use
> of graph db. That is the problem, because there is no any particular
> problem, I am aiming to resolve, and for that and that I need graph db.
> However, one thing which bothering me is : Can I perform selection like in
> relational database (so I have saved some data some time ago, and I want to
> retrieve it again)?
> In all neo4j examples, data is retrieved from the same part of the code
> which perform saving earlier.
> Is it at all possible to select data, like 10 days after saving?
>
> Every example is like this :
>
>        GraphDatabaseService graphDb = new
> EmbeddedGraphDatabase("poc_test");
>
>        Transaction tx = graphDb.beginTx();
>        try {
>            for(CSVObject object : csv){
>                Node trigramme = graphDb.createNode();
>                Node cp = graphDb.createNode();
>                Node description = graphDb.createNode();
>                Node category = graphDb.createNode();
>
>                Relationship ispartOf = trigramme.createRelationshipTo(cp,
> RelTypes.IS_PART_OF);
>                Relationship isDescribedBy =
> trigramme.createRelationshipTo(description, RelTypes.IS_DESCRIBED_BY);
>                Relationship isCategorizedIn =
> description.createRelationshipTo(category, RelTypes.IS_CATEGORIZED_IN);
>
>                trigramme.setProperty("value", object.getTrigram());
>                cp.setProperty("value", object.getCp());
>                description.setProperty("value", object.getDescription());
>                category.setProperty("value", object.getCategory());
>
>                ispartOf.setProperty("relationship", "ispartOf ");
>                isDescribedBy.setProperty("relationship", "ispartOf");
>                isCategorizedIn.setProperty("relationship", "ispartOf");
>
>                Traverser friendsTraverser = description.traverse(
>                        Traverser.Order.BREADTH_FIRST,
>                        StopEvaluator.DEPTH_ONE,
>                        ReturnableEvaluator.ALL_BUT_START_NODE,
>                        RelTypes.IS_DESCRIBED_BY,
>                        Direction.INCOMING );
>                        // Traverse the node space and print out the result
>                        //System.out.println( "Testing values : " );
>                        for ( Node friend : friendsTraverser )
>                        {
>
>                        System.out.println( "At depth : "+
>                        friendsTraverser.currentPosition().depth()+" with
> value : "+
>                        friend.getProperty( "value" ) );
>                        }
>            }
>
>            tx.success();
>        }catch (Exception e){
>            e.printStackTrace();
>        }
>        finally {
>            tx.finish();
>            graphDb.shutdown();
>        }
>      }
>
> So Traverser is using the node previously created, in order to iterate over
> database.
> But, how can I perform (simple example), to save user's data when he
> register, and after 10 days when he log in again, to retrieve that data?
> And
> is this kind of concept, which I use in relational db, possible to apply to
> graph database? I mean, if I cannot get saved data after some time, what is
> the purpose of the graph db?
> Hope you understood my problem and question, and thanks in advance to your
> answers !
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Tobias Ivarsson <[email protected]>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to