【问题标题】:How to build a custom Lucene index for Neo4j graph?如何为 Neo4j 图形构建自定义 Lucene 索引?
【发布时间】:2012-10-25 01:22:00
【问题描述】:

我正在使用 Gremlin 和 Neo4j 来操纵来自 infochimps 的 ENRON dataset。该数据集有两种类型的顶点MessageEmail Addresss 和两种类型的边SENTRECEVIED_BY。我想在此数据集上创建一个自定义索引,为type: 'Message' 的每个顶点创建一个Lucene 文档,并将来自关联顶点的信息(例如v.in()v.out())合并为Lucene 中的附加字段文档。

我正在考虑类似于

的代码
g = new Neo4jGraph('enron');

PerFieldAnalyzerWrapper analyzer =
    new PerFieldAnalyzerWrapper(new StandardAnalyzer());
analyzer.addAnalyzer("sender", new KeywordAnalyzer());
analyzer.addAnalyzer("recipient", new KeywordAnalyzer());

IndexWriter idx = new IndexWriter (dir,analyzer,IndexWriter.MaxFieldLength.UNLIMITED);

g.V.filter{it.type == 'Message'}.each { v ->
    Document doc = new Document();
    doc.add(new Field("subject", v.subject));
    doc.add(new Field("body", v.body));
    doc.add(new Field("sender", v.in().address);
    v.out().each { recipient -> 
        doc.add(new Field("recipient", recipient.address));
    }
    idx.addDocument(doc);
}
idx.close();

我的问题是:

  1. 是否有更好的方法来枚举顶点以进行索引?
  2. 我可以为此使用自动索引吗?如果可以,如何指定应该索引的内容?
  3. 我可以指定我自己的Analyzer,还是我坚持使用默认值?默认是什么?
  4. 如果我必须创建自己的索引,我应该为此使用 gremlin,还是使用 Java 程序更好?

【问题讨论】:

  • 你解决了吗?我面临同样的问题......(具体来说,我担心你问题中的项目符号 1 和 2)。

标签: neo4j gremlin


【解决方案1】:

我将在这里谈论直接 Neo4j 访问,因为我在 Gremlin 的旅行并不好。

所以您想在图形本身“外部”构建一个 Lucene 索引?否则,您可以使用内置的 graphDb.index().forNodes("myIndex", configForMyIndex) 来获取(按需创建)与 neo4j 关联的 Lucene 索引。然后,您可以通过调用 index.add(node, key, value) 向每个文档添加多个字段,其中每个节点将由该 Lucene 索引中的一个文档表示。

1) 在 Gremiln... 我不知道

2) 见http://docs.neo4j.org/chunked/milestone/auto-indexing.html

3) 见http://docs.neo4j.org/chunked/milestone/indexing-create-advanced.html

4) 您是否需要完全在数据库之外创建它?如果有,为什么?

【讨论】:

  • 我看过那个例子,但它不允许我指定分析器。请参阅页面底部关于高级索引的 cmets(上面的第二个链接)。
【解决方案2】:

我刚刚使用 Java 进程完成了导入,这真的很简单,在我看来,通过 Gremlin 更好地包容。

无论如何,如果进程失败是因为您无法创建 StandardAnalyzer 的新对象。该类的所有构造函数都需要参数,因此您应该创建一个包装类或使用正确版本的 Lucene 创建它,例如构造函数中的参数。

直到今天,Neo4J 只接受到 lucene 版本 36。

【讨论】:

    猜你喜欢
    • 2013-05-10
    • 1970-01-01
    • 2015-06-20
    • 2013-04-29
    • 2012-09-28
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多