1

neo4j サーバーにアクセスしてデータを保持しようとしていますが、コードと server-properties.file の両方が同じデータベースの場所を示しているにもかかわらず、webadmin インターフェイスで結果を確認できません。

これが私が書いたコードです(以前にユーザーを作成したので、ユーザー作成コードは含まれていません):

package graph;

import java.util.Iterator;
import java.util.Random;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.index.Index;

public class GraphTest {

    static GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( "data/graph.db" );
    static Index<Node> nodeIndex = graphDb.index().forNodes("nodes");

    private static enum RelTypes implements RelationshipType
    {
        CALLED
    }

    public static void addRelationships(){
        int caller;
        int temp=0;
        int callee;
        Random rand = new Random();

        for(int i = 0 ;i<1000;i++){
            caller=rand.nextInt(100);
            temp=rand.nextInt(100);
            while(temp==caller)
                temp=rand.nextInt(100);
            callee=temp;


            String callerName = idToUserName( caller );
            Node foundCaller= nodeIndex.get( "uname", callerName ).getSingle();
            System.out.println( "The username of user " + caller + " is "
            + foundCaller.getProperty( "uname" ) );

            String calleeName = idToUserName( callee);
            Node foundCallee= nodeIndex.get( "uname", calleeName ).getSingle();
            System.out.println( "The username of user " + callee + " is "
            + foundCallee.getProperty( "uname" ) );


            System.out.println(callerName+" called " + calleeName);

            foundCaller.createRelationshipTo(foundCallee, RelTypes.CALLED);
            Iterable<Relationship> rels = foundCaller.getRelationships(RelTypes.CALLED, Direction.OUTGOING);
            Iterator<Relationship> x = rels.iterator();
            while(x.hasNext()){
                Relationship r = x.next();
                System.out.println(r.toString());
            }

        }

    }

    private static String idToUserName( final int id )
    {
        return "user" + String.valueOf(id) ;
    }

    private static Node createAndIndexUser( final String username )
    {
        Node node = graphDb.createNode();
        node.setProperty( "uname", username );
        nodeIndex.add( node,"uname", username );
        return node;
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Node firstNode;
        Node secondNode;
        Relationship relationship;

        System.out.println(nodeIndex.getName()+"  " +
nodeIndex.getGraphDatabase().getNodeById(45).getProperty("uname") );
        registerShutdownHook( graphDb );

        Transaction tx = graphDb.beginTx();
        try
        {
        // Updating operations go here
            // Create some users and index their names with the IndexService

            int idToFind = 67;
            String userName = idToUserName( idToFind );
            Node foundUser = nodeIndex.get( "uname", userName ).getSingle();
            System.out.println( "The username of user " + idToFind + " is "
            + foundUser.getProperty( "uname" ) );


            addRelationships();





            tx.success();

        }
        finally
        {
            tx.finish();

        }

        graphDb.shutdown();

    }

    private static void registerShutdownHook(final GraphDatabaseService graphDb) {
        // TODO Auto-generated method stub
        // Registers a shutdown hook for the Neo4j instance so that it
        // shuts down nicely when the VM exits (even if you "Ctrl-C" the
        // running application).
        Runtime.getRuntime().addShutdownHook( new Thread()
        {
        @Override
        public void run()
        {
        graphDb.shutdown();
        }
        } );

    }

}

そして、これは conf/neo4j-server.properties ファイルの内容です:

# location of the database directory 
org.neo4j.server.database.location=data/graph.db

次のようなクエリを webadmin インターフェイス (でhttp://localhost:7474/webadmin)に書き込もうとすると、次のようになります。

START n=node:nodes(uname="user45")
RETURN n

エラー メッセージが表示Index 'nodes' doesnt existされます。または、私は何を間違っていますか?

Neo4j バージョン: 1.9.3

4

2 に答える 2

2

コードが Neo4j サーバーと同じ作業ディレクトリで実行されていることを本当に確信していますか? Java プログラムの現在の作業ディレクトリのパスを出力できますか?

于 2013-09-02T21:14:10.480 に答える
-1

Web コンソールで入力index --indexesすると、使用可能なすべてのインデックスを表示できます。

于 2013-09-02T08:17:15.823 に答える