使用Pointt.veinBBox()使用Cypher DSL查询neo4j

snz8szmq  于 2022-10-21  发布在  其他
关注(0)|答案(1)|浏览(117)

我想在我的 neo4j 数据库中找到边界框内的位置。我想要使用一个名为point t.veinBBox()的函数。我使用Cypher DSL动态构建查询。这是我要运行的查询类型:

MATCH (loc:Location)
WHERE point.withinBBox(loc.coordinates, point({longitude: 2.592773, latitude: 46.346928}), point({longitude: 18.654785, latitude: 55.714735}))
RETURN loc

在我的Java代码中,我动态地链接如下条件:

conditions = Conditions.noCondition();
conditions = conditions.and(new_condition);

因此,我想获得一个Condition,它封装了point.witinBBox()部分。

mrphzbgm

mrphzbgm1#

目前还没有内置的Functions调用来执行此操作,但您可以通过Cypher.call轻松创建自定义调用。通过.asCondition()可以将返回的函数变成条件,如下所示:

@Test
void bbBox() {

    Node location = Cypher.node("Location").named("loc");
    Expression sw = Functions.point(Cypher.mapOf("latitude", Cypher.literalOf(46.346928), "longitude", Cypher.literalOf(2.592773)));
    Expression ne = Functions.point(Cypher.mapOf("latitude", Cypher.literalOf(55.714735), "longitude", Cypher.literalOf(18.654785)));
    Expression withinBBox = Cypher.call("point.withinBBox")
        .withArgs(location.property("coordinates"), sw, ne).asFunction();

    Condition conditions = Conditions.noCondition();
    conditions = conditions.and(withinBBox.asCondition());

    String stmt = Cypher.match(location).where(conditions).returning(location).build().getCypher();
    assertThat(stmt).isEqualTo("MATCH (loc:`Location`) WHERE point.withinBBox(loc.coordinates, point({latitude: 46.346928, longitude: 2.592773}), point({latitude: 55.714735, longitude: 18.654785})) RETURN loc");
}

相关问题