1

我无法使用 JAVA API 创建索引。我的代码是:

graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
registerShutdownHook();
// END SNIPPET: startDb

// START SNIPPET: addUsers
Transaction tx = graphDb.beginTx();
try
{
    nodeIndex = graphDb.index().forNodes( "nodes" );
    // Create some users and index their names with the IndexService
    for ( int id = 0; id < 100; id++ )
    {
        createAndIndexUser( idToUserName( id ) );
    }
    // END SNIPPET: addUsers

    // Find a user through the search index
    // START SNIPPET: findUser
    int idToFind = 45;
    String userName = idToUserName( idToFind );
    Node foundUser = nodeIndex.get( USERNAME_KEY, userName ).getSingle();

    System.out.println( "The username of user " + idToFind + " is "
        + foundUser.getProperty( USERNAME_KEY ) );
    // END SNIPPET: findUser

    // Delete the persons and remove them from the index
    for ( Node user : nodeIndex.query( USERNAME_KEY, "*" ) )
    {
        nodeIndex.remove(  user, USERNAME_KEY, user.getProperty( USERNAME_KEY ) );
        user.delete();
    }
    tx.success();
}
finally
{
    tx.finish();
}

错误:

线程“main”java.lang.IllegalArgumentException 中的异常:未找到索引提供程序“lucene”。也许预期的提供者(或它的一个以上依赖项)不在类路径上,或者它无法加载。

在 org.neo4j.kernel.IndexManagerImpl.getIndexProvider(IndexManagerImpl.java:90)
在 org.neo4j.kernel.IndexManagerImpl.findIndexConfig(IndexManagerImpl.java:141)
在 org.neo4j.kernel.IndexManagerImpl.getOrCreateIndexConfig(IndexManagerImpl.java:208 )
at org.neo4j.kernel.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:318)
at org.neo4j.kernel.NodeAutoIndexerImpl.getIndexInternal(NodeAutoIndexerImpl.java:85)
at org.neo4j.kernel.AbstractAutoIndexerImpl.getAutoIndex(AbstractAutoIndexerImpl.java: 82)
在 com.neo4j.Indexing.main(Indexing.java:39) Java 结果:1

4

1 回答 1

2

Neo4j 使用 Lucene 作为其默认索引提供程序。确保类路径中有 neo4j-lucene-index.jar。您可以从这里下载适当版本的 jar 。

于 2013-08-21T16:39:42.443 回答