Neo4j 索引不起作用



我正在使用批插入方法创建neo4j图数据库。加载DBpedia数据集并构建其属性图。

public Neo4jBatchHandler(BatchInserter db2, int indexCache, int timeout) {
    this.db = db2;
    this.indexCache = indexCache;
    this.timeout = timeout;
    BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(
            db);
    index = indexProvider.nodeIndex("ttlIndex",
            MapUtil.stringMap("type", "exact"));
    index.setCacheCapacity("__URI__", indexCache + 1);
}

这是我用来索引的代码。


在查询操作期间,为了提高效率,我想使用索引的可能性。但不幸的是,它不起作用。这是我的代码:

    IndexHits<Long> hits = index.get("__URI__",
                    resourceName);

它返回null,但我确信db包含具有resourceName的资源。我应该如何在这里使用索引进行查询?

您真的将节点添加到索引中了吗?例如:

index.add(node,properties)

您是否在批量插入过程中进行查询?如果是,请刷新索引

index.flush();

使得新索引的节点对于查询是可见的。建议您不要经常这样做,请参阅http://neo4j.com/docs/stable/indexing-batchinsert.html

最新更新