如何重建Neo4j Lucene索引? - Neo4j.rb

发布于 2024-12-04 21:06:18 字数 293 浏览 1 评论 0原文

我在 Rails 3.1 上使用 Neo4j.rb gem (1.2.2) 在 Neo4j (1.4) 上运行

我遇到了 Neo4j 索引损坏的问题,我无法再运行数据库,如 这个 我删除了db/index dir 并且它有效。但是我需要再次重建索引。

我在文档中找不到有关如何重建索引的任何地方,有人可以帮忙吗?

多谢!

I am running on Neo4j (1.4) using Neo4j.rb gem (1.2.2) on Rails 3.1

I bumped into problem where neo4j index was corrupted that I cant run the database anymore, as mentioned in several forums like this I deleted the db/index dir and it worked. However I need to rebuild the index again.

I could not find anywhere in the docs on how to rebuild the index, could anybody please help?

Thanks alot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦纸 2024-12-11 21:06:18

您应该进入数据库目录并删除

  • 名为index的目录
  • 文件index.db

,然后遍历节点和边的孔集,更新每个节点的属性。

/普尔邦

You should go into your database directory and remove

  • Directory named index
  • The file index.db

and later on traverse the hole set of nodes and edges, updating the properties of each node.

/purbon

泪痕残 2024-12-11 21:06:18

我的问题是类似的 - 升级到 neo4j 1.5(从 1.4)后,我的索引被损坏。
我的案例:
我有两个索引:

  • __types__ :用于索引持久对象的类型(由 spring-data-neo4j 2.0.0.RC1 提供)
  • User :用于索引用户名字段,因此我可以在它们之后进行查找

这导致了一个主要问题,我可以通过它们的 id 找到所有节点,但无法在用户名之后进行查找,或列出某种类型的所有对象。

修复(我将提供 java 代码,但其他语言的想法也是相同的):

/* begin a transaction */
Transaction tx = graphDatabaseService.beginTx(); 
/* for all nodes in the database */
for (Node node : graphDatabaseService.getAllNodes()) { 
    /* reconstruct the saved object based on the __type__ property on the node - the result is a class that was annotated with @NodeEntity */
    DefaultDbNode ddn = neo4jTemplate.createEntityFromStoredType(node,
            null);
    /* reindex this node, adding it to the __types__ index, with key "className" (it is used by spring-data-neo4j) with the value __type__ */
    graphDatabaseService.index().forNodes("__types__")
            .add(node, "className", node.getProperty("__type__")); 
    /* if the reconstructed object is a User object */
    if (ddn instanceof User) { 
        /* add it to the User index, with the key "username" (which is also the saved fields name) */
        graphDatabaseService.index().forNodes("User")
                .add(node, "username", node.getProperty("username")); 
    }
}
/* end transaction */
tx.success();
tx.finish();

希望这可以帮助您或某人!

My problem was similar - after upgrading to neo4j 1.5 (from 1.4) my indexes got corrupted.
My case:
I had two indexes:

  • __types__ : for indexing the type of persisted objects (provided by spring-data-neo4j 2.0.0.RC1)
  • User : for indexing the username field, so I could do lookups after them

This resulted in a major problem, where I could find all the nodes by their id, but could not do lookups after username, or list all objects of a certain type.

The fix ( I will provide java code, but the idea would be the same in other languages too):

/* begin a transaction */
Transaction tx = graphDatabaseService.beginTx(); 
/* for all nodes in the database */
for (Node node : graphDatabaseService.getAllNodes()) { 
    /* reconstruct the saved object based on the __type__ property on the node - the result is a class that was annotated with @NodeEntity */
    DefaultDbNode ddn = neo4jTemplate.createEntityFromStoredType(node,
            null);
    /* reindex this node, adding it to the __types__ index, with key "className" (it is used by spring-data-neo4j) with the value __type__ */
    graphDatabaseService.index().forNodes("__types__")
            .add(node, "className", node.getProperty("__type__")); 
    /* if the reconstructed object is a User object */
    if (ddn instanceof User) { 
        /* add it to the User index, with the key "username" (which is also the saved fields name) */
        graphDatabaseService.index().forNodes("User")
                .add(node, "username", node.getProperty("username")); 
    }
}
/* end transaction */
tx.success();
tx.finish();

Hope this helps you or someone out!

三生路 2024-12-11 21:06:18

感谢所有试图提供帮助的人。就我而言,我通过采取以下步骤成功解决了该问题:

第 1 步按照 Neo4j 的 Michael Hunger(通过邮件列表)的建议,我使用了一个名为 checkindex 的工具来删除损坏的索引条目Lucene 和 Solr 的 Checkindex

第 2 步 删除损坏的文件后指数条目,剩下的问题是构建它们,以便 Lucene 可以再次开始查询它们。这可以简单地使用 Model.addindex(:index_name) 来完成。请注意,此操作需要包装在 Neo4j::Transaction 中。就我而言,我在 Railsconsole 上运行它,但我想您也可以在 Rails 应用程序中对它们进行编码。

示例:

Neo4j::Transaction.run do
  User.all.each do |user|
    user.add_index(:first_name)
    user.add_index(:email)
    user.save
  end
end

希望这可以帮助遇到同样问题的其他人。

干杯

Thanks to all who tried to help. In my case I have successfully solved the problem by taking the following steps:

Step 1 Following the recommendation from Neo4j's Michael Hunger (via mailing list), I used a tool called checkindex to remove corrupt index entries Lucene and Solr's Checkindex

Step 2 Upon removal of corrupt index entries, the remaining problem is to build them so Lucene can start querying them again. This could simply be done using using Model.addindex(:index_name). Note that this operation needs to be wrapped within a Neo4j::Transaction. In my case I ran it on railsconsole but I suppose you could also code them within the rails app.

Example:

Neo4j::Transaction.run do
  User.all.each do |user|
    user.add_index(:first_name)
    user.add_index(:email)
    user.save
  end
end

Hope this could help others who face the same problems.

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文