It is correct that getNodeById is much faster than an index lookup, but IDs
are assigned by Neo4j, there is no way for you as a user to assign IDs,
which makes it a very blunt tool for looking up entities. To know which id
corresponds to a particular name or similar attribute, you would have to go
through an index, and that is exactly what the Neo4j index API does for you.

By the way, the LuceneIndexService is a deprecated API, use
GraphDatabaseService#index() instead:
http://components.neo4j.org/neo4j/1.3.M04/apidocs/org/neo4j/graphdb/GraphDatabaseService.html#index()

Cheers,
Tobias

On Wed, Mar 23, 2011 at 3:45 AM, 孤竹 <[email protected]> wrote:

> HI,all
>
>       I Found something interesting, The test as  follow:
>
> public static void main(String args[]) {
>        GraphDatabaseService db = new EmbeddedGraphDatabase("testDB");
>        indexService = new LuceneIndexService(db);
>        Long startTime = System.currentTimeMillis();
>        for(int i =0 ;i <10000;i++){
>            Node node = getNodeByIndexProperty(db,String.valueOf(i));
>        }
>        Long endTime = System.currentTimeMillis();
>        System.out.println("time = " + (endTime - startTime));
>    }
>    public static Node getNodeByIndexProperty(GraphDatabaseService db,
> String keyValue) {
> //        Node node = indexService.getSingleNode(KEY_NAME, keyValue);
>        Node node = db.getNodeById(Long.valueOf(keyValue));
>        return node;
>    }
>
> When I try to use the method indexService.getSingleNode...... with 9999
> times, It will take 2 seconds (nearly) , BY when I use db.getNodeById....
> same times, It just take 350 millisecond . Does it mean getById is faster
> than use index ? or Does that mean the natural index is better than index if
> I can use it ?
>
> thanks for your help ,and replies, that help me very much!
> _______________________________________________
> 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