Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有大数据集的Spring数据/Neo4j路径长度_Java_Neo4j_Spring Data_Spring Data Neo4j - Fatal编程技术网

Java 具有大数据集的Spring数据/Neo4j路径长度

Java 具有大数据集的Spring数据/Neo4j路径长度,java,neo4j,spring-data,spring-data-neo4j,Java,Neo4j,Spring Data,Spring Data Neo4j,我一直在运行以下查询,以查找与给定人员在一定“距离”内的亲属: @Query("start person=node({0}), relatives=node:__types__(className='Person') match p=person-[:PARTNER|CHILD*]-relatives where LENGTH(p) <= 2*{1} return distinct relatives") Set<Person> getRelatives(Person pers

我一直在运行以下查询,以查找与给定人员在一定“距离”内的亲属:

@Query("start person=node({0}), relatives=node:__types__(className='Person') match p=person-[:PARTNER|CHILD*]-relatives where LENGTH(p) <= 2*{1} return distinct relatives")
Set<Person> getRelatives(Person person, int distance);
这很好,在同一个数据存储上只需几分之一秒。但当我想把它放回Java时:

@Query("start person=node({0}) match p=person-[:PARTNER|CHILD*1..{1}]-relatives where relatives.__type__! = 'Person' return relatives")
Set<Person> getRelatives(Person person, int distance);
有没有更好的方法来设置路径长度限制?我不希望使用
where
,因为这将涉及加载所有路径,可能会加载数百万个节点,而我只需要深入10个节点。这大概不会让我有什么好下场

任何想法都将不胜感激


迈克尔来营救

我的解决方案:

public Set<Person> getRelatives(final Person person, final int distance) {

    final String query = "start person=node(" + person.getId() + ") "
        + "match p=person-[:PARTNER|CHILD*1.." + 2 * distance + "]-relatives "
        + "where relatives.__type__! = '" + Person.class.getSimpleName() + "' "
        + "return distinct relatives";

    return this.query(query);

    // Where I would previously instead have called 
    // return personRepository.getRelatives(person, distance);
}

public Set<Person> query(final String q) {

    final EndResult<Person> result = this.template.query(q, MapUtil.map()).to(Neo4jPerson.class);
    final Set<Person> people = new HashSet<Person>();

    for (final Person p : result) {
        people.add(p);
    }

    return people;
}
public Set getrelights(最终人物,最终整数距离){
最后一个字符串query=“start person=node(“+person.getId()+”)”
+“匹配p=人-[:伴侣|孩子*1..”+2*距离+“]-亲属”
+“where relatives.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
+“归亲”;
返回此.query(查询);
//我以前会打电话去的地方
//returnpersonrepository.getrelights(person,distance);
}
公共集查询(最终字符串q){
final-EndResult=this.template.query(q,MapUtil.map()).to(Neo4jPerson.class);
final Set people=new HashSet();
对于(最终人员p:结果){
新增(p);
}
还人,;
}
它跑得很快

你就快到了:)

您的第一个查询是一个完整的图形扫描,它有效地将整个数据库加载到内存中,并多次通过该模式匹配拉动所有节点

所以它不会很快,而且会返回大量数据集,不知道这是否是您想要的

第二个查询看起来不错,唯一的问题是不能参数化可变长度关系的最小-最大值。由于查询优化/缓存的影响

因此,现在您必须在回购协议中使用template.query()或不同的查询方法来获得不同的最大值。

您就快到了:)

您的第一个查询是一个完整的图形扫描,它有效地将整个数据库加载到内存中,并多次通过该模式匹配拉动所有节点

所以它不会很快,而且会返回大量数据集,不知道这是否是您想要的

第二个查询看起来不错,唯一的问题是不能参数化可变长度关系的最小-最大值。由于查询优化/缓存的影响


因此,现在您必须在回购协议中使用template.query()或不同的查询方法来获取不同的最大值。

感谢您的解释,也感谢您所做的所有工作!:谢谢你的解释,谢谢你的工作DDon不直接使用id,而是一个参数,与类名相同。否则,您将在运行时释放查询缓存,因为它必须重新解析每个查询!!不要直接使用id,而是一个参数,与类名相同。否则,您将在运行时释放查询缓存,因为它必须重新解析每个查询!!
[...]
Nested exception is Properties on pattern elements are not allowed in MATCH.
"start person=node({0}) match p=person-[:PARTNER|CHILD*1..{1}]-relatives where relatives.__type__! = 'Neo4jPerson' return relatives"
                                         ^
public Set<Person> getRelatives(final Person person, final int distance) {

    final String query = "start person=node(" + person.getId() + ") "
        + "match p=person-[:PARTNER|CHILD*1.." + 2 * distance + "]-relatives "
        + "where relatives.__type__! = '" + Person.class.getSimpleName() + "' "
        + "return distinct relatives";

    return this.query(query);

    // Where I would previously instead have called 
    // return personRepository.getRelatives(person, distance);
}

public Set<Person> query(final String q) {

    final EndResult<Person> result = this.template.query(q, MapUtil.map()).to(Neo4jPerson.class);
    final Set<Person> people = new HashSet<Person>();

    for (final Person p : result) {
        people.add(p);
    }

    return people;
}