java - Spring 数据 neo4j LIKE 查询不起作用

标签 java spring spring-boot neo4j spring-data-neo4j

我是 neo4j spring 数据的新手,我尝试执行的查询不适用于我的 spring boot 应用程序,但适用于 neo4j 网络界面。

我在数据库上有 3 个节点:“oracle”、“java”和“cloud” 我正在尝试运行的查询:

MATCH(interest:Interest) WHERE interest.name =~ '(?i).*cl.*' RETURN interest

因此,使用 neo4j 网络界面,如果我输入“cl”,它将返回“oracle”和“cloud”,这是正确的。

使用 spring 数据,我得到了所有 3 个结果,这是错误的。

我的存储库界面:

@Query("MATCH(interest:Interest) WHERE interest.name =~ '(?i).*{0}.*' RETURN interest")
Set<Interest> getKindOf(String value);

我的休息 Controller :

@ResponseBody
public Collection<Interest> getPersonByName(@PathVariable String name) {
    Set<Interest> interests = interestRepository.getKindOf(name);
    return interests;
}

检查 Spring 启动日志我可以看到查询:

INFO 12716 --- [nio-2016-exec-1] o.n.o.drivers.http.request.HttpRequest   : Thread: 22, url: http://localhost:7474/db/data/transaction/commit, request: {"statements":[{"statement":"MATCH(interest:Interest) WHERE interest.name =~ '(?i).*{0}.*' RETURN interest","parameters":{"0":"cl"},"resultDataContents":["graph"],"includeStats":false}]}

所以,问题是:为什么我使用 neo4j Web 界面得到 2 个结果(OK),而使用 spring data 得到 3 个结果(NOK)?

感谢您的帮助!

罗德里戈

最佳答案

完整的正则表达式应该作为参数传递(又名密码查询参数)

@Query("MATCH(interest:Interest) WHERE interest.name =~ {0} RETURN interest")
Set<Interest> getKindOf(String value);

--

@ResponseBody
public Collection<Interest> getPersonByName(@PathVariable String name) {
    String regex = "(?i).*" + name + ".*";
    Set<Interest> interests = interestRepository.getKindOf(regex);
    return interests;
}

注意这与密码参数处理有关,这不是 sdn 特有的

关于java - Spring 数据 neo4j LIKE 查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40438382/

相关文章:

java - Spring Boot 项目中的 application.properties 文件在哪里?

Java Scheduling API - 特定间隔

java - 如何在 JBoss AS 7 中部署 war 文件?

java - 是否可以在路由器中向消息添加 header ?

java - 在 Akka 中对一对外部服务调用进行排序的最佳方法

java - Spring Boot JAR 不适用于 Windows Server

java - 为什么签名的 java applet 无法连接到外部服务器?

java - 尝试从 java webservice 中的 json 对象获取值时出现异常

java - ApplicationContext ctx = 新的 FileSystemXmlApplicationContext 错误

java - Spring Boot2 Oauth2 隐式流程 - http ://localhost:8080/oauth/authorize getting Access Denied