【问题标题】:Neo4j: Lucene query syntax in SDN4Neo4j:SDN4 中的 Lucene 查询语法
【发布时间】:2015-07-24 02:37:09
【问题描述】:

有人可以解释适当的 Cypher 查询语法以从下面提到的存储库查询中获得以下结果吗?下面提到的团队名称已保存到存储库中。

  • 洛杉矶湖人队
  • 阿纳海姆洛杉矶快船队
  • 金州勇士队
  • 洛杉矶阿纳海姆拍板队
  • 阿纳海姆洛杉矶拖鞋

有人建议我使用以下 Cypher,它最终出现在 NPE 中。 Neo4j: Native Java API(or equivalent cypher query) in Spring Data Neo4j

    //Repository     
    public interface TeamRepository extends GraphRepository<Team>
    {
        @Query("start team=node:teamName({0}) RETURN team")
        List<Team> findByTeamName(String query);
    }

以下调用在调用时会引发 NPE,如下所示:

teamRepository.findByTeamName("The Los Angeles Will be Playing in a state of Golden");

空指针异常:

Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:675)
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:690)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
    at com.directv.service.Sports.main(Sports.java:134)
Caused by: java.lang.NullPointerException
    at org.apache.lucene.util.SimpleStringInterner.intern(SimpleStringInterner.java:54)
    at org.apache.lucene.util.StringHelper.intern(StringHelper.java:39)
    at org.apache.lucene.index.Term.<init>(Term.java:38)
    at org.apache.lucene.queryParser.QueryParser.getFieldQuery(QueryParser.java:643)

【问题讨论】:

  • 这看起来像是您的查询字符串的 lucene 问题。确保引用(反斜杠)空格。
  • 你能分享导致这个错误的 lucene 查询字符串吗?
  • @Michael Hunger 查询字符串只是纯文本:teamRepository.findByTeamName("The Los Angeles Will be Playing in a state of Golden");
  • 很遗憾,您必须在那里转义空格。

标签: neo4j lucene cypher spring-data-neo4j spring-data-neo4j-4


【解决方案1】:

经过反复试验,我能够解决这个问题。正如@Michael Hunger 指出的那样,这是查询中嵌入空格字符的问题。适当的查询是: @Query("START team=node:teamName('teamName:(*The Los Angeles Will be Playing in a state of Golden*)') RETURN team")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 2020-03-13
    • 2015-01-19
    • 1970-01-01
    相关资源
    最近更新 更多