0

我正在尝试 Neo4j 2.0 (M3) 中的新标签功能,尤其是结合索引。Lucene 索引似乎被称为遗留索引,所以我猜标签索引是要走的路。我应该如何使用这种新方法编写通配符查询?我是否在下面的代码中遗漏了某些内容,或者此功能尚未实现?您可以使用正则表达式(如下所示)执行此操作,但您不使用架构索引。

public class IndexedLabelTest {

    public static void main(final String[] args) {
        final GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
        final Label label = DynamicLabel.label("A_LABEL");
        final Transaction tx = db.beginTx();
        db.schema().indexFor(label).on("name").create();
        final Node node = db.createNode(label);
        node.setProperty("name", "a_certain_name");

        final ExecutionEngine execEngine = new ExecutionEngine(db);

        // Find all nodes with label A_LABEL
        ExecutionResult result = execEngine.profile("MATCH node:A_LABEL RETURN node");
        System.out.println(result.dumpToString());
        System.out.println(result.executionPlanDescription());

        // Find all nodes with label A_LABEL and with a property 'name' that contains 'certain' (regex)
        result = execEngine.profile("MATCH node:A_LABEL WHERE node.name =~ '.*certain.*' RETURN node");
        System.out.println(result.dumpToString());
        System.out.println(result.executionPlanDescription());

        // Find all nodes with label A_LABEL and with a property 'name' that is 'a_certain_name'
        result = execEngine.profile("MATCH node:A_LABEL WHERE node.name = 'a_certain_name' RETURN node");
        System.out.println(result.dumpToString());
        System.out.println(result.executionPlanDescription());

        // Try to use wildcards, no such luck
        result = execEngine.profile("MATCH node:A_LABEL WHERE node.name = '*certain*' RETURN node");
        System.out.println(result.dumpToString());
        System.out.println(result.executionPlanDescription());

        tx.success();
        tx.finish();
        db.shutdown();
    }

}

输出:

+--------------------------------+
| node                           |
+--------------------------------+
| Node[1]{name:"a_certain_name"} |
+--------------------------------+
1 row

PatternMatch(g="", _rows=1, _db_hits=0)
Filter(pred="hasLabel(node: A_LABEL)", _rows=1, _db_hits=0)
  NodeByLabel(label="A_LABEL", identifier="node", _rows=1, _db_hits=0)
+--------------------------------+
| node                           |
+--------------------------------+
| Node[1]{name:"a_certain_name"} |
+--------------------------------+
1 row

PatternMatch(g="", _rows=1, _db_hits=0)
Filter(pred="(LiteralRegularExpression AND hasLabel(node: A_LABEL))", _rows=1, _db_hits=1)
  NodeByLabel(label="A_LABEL", identifier="node", _rows=1, _db_hits=0)
+--------------------------------+
| node                           |
+--------------------------------+
| Node[1]{name:"a_certain_name"} |
+--------------------------------+
1 row

PatternMatch(g="", _rows=1, _db_hits=0)
Filter(pred="(Property == Literal(a_certain_name) AND hasLabel(node: A_LABEL))", _rows=1, _db_hits=1)
  NodeByLabel(label="A_LABEL", identifier="node", _rows=1, _db_hits=0)
+------+
| node |
+------+
+------+
0 row

PatternMatch(g="", _rows=0, _db_hits=0)
Filter(pred="(Property == Literal(*certain*) AND hasLabel(node: A_LABEL))", _rows=0, _db_hits=1)
  NodeByLabel(label="A_LABEL", identifier="node", _rows=1, _db_hits=0)
4

1 回答 1

1

全文索引等尚未到来,可能在 2.1 中。暂时,做 1.9 索引来获得它。它主要围绕将复杂参数传递给标签索引以及配置全文、地理等需要在提交语法之前指定的内容进行设计。

感谢您所有伟大的 SO 贡献@tstorms!

/彼得

于 2013-06-30T09:28:49.360 回答