Neo4j和Lucene多键查询(或:我应该使用Cypher?) [英] Neo4j and Lucene multikey queries (or: should I use Cypher?)

查看:288
本文介绍了Neo4j和Lucene多键查询(或:我应该使用Cypher?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Neo4j中有一个图,其中的节点代表平面中的随机点,每个节点的坐标存储为属性(x和y,值类型为 double )。
我创建节点并为它们建立索引:

  IndexManager index = graph.index(); 
索引< Node> nodesIndex = index.forNodes(points);

for(int i = 0; i Point p = points [i];
节点n;

Transaction tx = graph.beginTx();
尝试{
n = graph.createNode();
n.setProperty(x,p.getX());
n.setProperty(y,p.getY());

nodesIndex.add(n,x,new ValueContext(p.getX())。indexNumeric());
nodesIndex.add(n,y,new ValueContext(p.getY())。indexNumeric());

tx.success();
} finally {
tx.finish();


$ / code $ / pre

现在,我需要做的是查询在方形区域中的节点。例如,我做了这个查询:

  http:// localhost:7474 / db / data / index / node / points? query = x:[0.0 TO 3.0] AND y:[0.0 TO 3.0] 

这就是响应:

$ p $节点
属性
y 1.0
x 14.0
节点信息
self / db / data / node / 10

节点
属性
y 1.0
x 2.0
节点信息
self / db / data / node / 7

节点
属性
y 1.0
x 6.0
节点信息
self / db / data / node / 8

节点
属性
y 1.0
x 7.0
节点信息
self / db / data / node / 9

[Etc ...]

正如您所看到的,它不起作用。我不明白为什么(也许我需要配置索引?)。

请注意,我没有 来使用Lucene。如果有一种方法可以用Cypher收集这些信息(从以正方形区域为中心的节点开始)实际上会更好,因为我还需要找到的节点之间的关系。


其他信息
如果这很重要,该图表示的是飞机上任意一组点的Delaunay三角关系。用更抽象的术语来说,我需要抽取位于特定区域的整个子图。



任何帮助真的很感谢!

解决方案

不能通过Cypher来做到这一点。 Cypher没有办法推断出你想为这个查询使用一个数字的值上下文(可能在未来版本的某些索引元信息中),并且你需要能够以你想要的方式查询Lucene。 REST最简单的方法可能是使用Groovy,请参阅 http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-send-an-arbitrary-groovy -script --- lucene-sorting


I have a graph in Neo4j in which nodes represent random points in the plane, each node having the coordinates stored as properties (x and y, the value type is double).
I create the nodes and index them:

    IndexManager index = graph.index();
    Index<Node> nodesIndex = index.forNodes("points");

    for (int i = 0; i < points.length; i++) {
        Point p = points[i]; 
        Node n;

        Transaction tx = graph.beginTx();
        try {
            n = graph.createNode();
            n.setProperty("x", p.getX());
            n.setProperty("y", p.getY());

            nodesIndex.add(n, "x", new ValueContext(p.getX()).indexNumeric());
            nodesIndex.add(n, "y", new ValueContext(p.getY()).indexNumeric());

            tx.success();
        } finally {
            tx.finish();
        }
    }

Now, what I need to do, is query for the nodes which are in a square area. So for example I made this query:

http://localhost:7474/db/data/index/node/points?query=x:[0.0 TO 3.0] AND y:[0.0 TO 3.0]

And this is the response:

    Node
    Properties
    y   1.0
    x   14.0
    Node info
    self    /db/data/node/10

    Node
    Properties
    y   1.0
    x   2.0
    Node info
    self    /db/data/node/7

    Node
    Properties
    y   1.0
    x   6.0
    Node info
    self    /db/data/node/8

    Node
    Properties
    y   1.0
    x   7.0
    Node info
    self    /db/data/node/9

[Etc...]

As you see it is not working. And I don't understand why (maybe I need to configure the index?).
Note that I haven't got to use Lucene. If there is a way to gather that information with Cypher (starting from a node centered in the square area) would be actually better, for I also need the relationships between the nodes found.

Additional informations If that matters, the graph represents a Delaunay triangolation on a random set of points on the plane. In more abstract terms, I need to "extract" the entire subgraph that lays in a given area.

Any help is really appreciated!

解决方案

I am afraid you can't do this via Cypher. There is no way Cypher can infer that you want to use a numeric Value context for this query (could probably be in some indexing meta info in future releases), and you need that to be able to query Lucene the way you want to. Easiest way over REST is probably to use Groovy, see custom sorting (same issue) at http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-send-an-arbitrary-groovy-script---lucene-sorting

这篇关于Neo4j和Lucene多键查询(或:我应该使用Cypher?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆