SpringData / Neo4j:查询全文索引导致RuntimeException,因为参数未被替换

时间:2014-10-20 07:17:53

标签: neo4j spring-data-neo4j

使用Spring Data for Neo4j在模型(NodeEntity)类中创建全文索引,如下所示:

@Indexed(indexName="descriptionSearchIdx", indexType=IndexType.FULLTEXT)
private String description;

存储库类:我按如下方式查询:

@Query("START n=node:descriptionSearchIdx('description:*{0}*') RETURN n;")
public List<MyModel> searchMyModelByText(String searchText);

但是,参数替换似乎因为给出RuntimeException而失败。

如果将{0}替换为硬编码的任何有效搜索词,则查询将正常运行,但不会启用替换{0}。

任何线索?

注意:我使用的是Play框架,因此堆栈跟踪也会包含这些内容。

堆栈追踪:

Execution exception[[RuntimeException: org.apache.lucene.queryParser.ParseException: Cannot parse 'description:*{0}*': Encountered " "}" "} "" at line 1, column 15.
Was expecting one of:
    "TO" ...
    <RANGEEX_QUOTED> ...
    <RANGEEX_GOOP> ...
    ]]
    at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10-2.2.3.jar:2.2.3]
    at play.api.DefaultApplication.handleError(Application.scala:399) ~[play_2.10-2.2.3.jar:2.2.3]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) ~[play_2.10-2.2.3.jar:2.2.3]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) ~[play_2.10-2.2.3.jar:2.2.3]
    at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) ~[play_2.10-2.2.3.jar:2.2.3]
Caused by: java.lang.RuntimeException: org.apache.lucene.queryParser.ParseException: Cannot parse 'description:*{0}*': Encountered " "}" "} "" at line 1, column 15.
Was expecting one of:
    "TO" ...
    <RANGEEX_QUOTED> ...
    <RANGEEX_GOOP> ...

    at org.neo4j.index.impl.lucene.IndexType.query(IndexType.java:307) ~[neo4j-lucene-index-2.0.3.jar:2.0.3]
    at org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:251) ~[neo4j-lucene-index-2.0.3.jar:2.0.3]
    at org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:263) ~[neo4j-lucene-index-2.0.3.jar:2.0.3]
    at org.neo4j.cypher.internal.spi.v2_0.TransactionBoundQueryContext$NodeOperations.indexQuery(TransactionBoundQueryContext.scala:169) ~[neo4j-cypher-2.0.3.jar:2.0.3]
    at org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:116) ~[neo4j-cypher-compiler-2.0-2.0.3.jar:2.0.3]
    at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$super$indexQuery(ExceptionTranslatingQueryContext.scala:142) ~[neo4j-cypher-compiler-2.0-2.0.3.jar:2.0.3]
Caused by: org.apache.lucene.queryParser.ParseException: Cannot parse 'description:*{0}*': Encountered " "}" "} "" at line 1, column 15.
Was expecting one of:
    "TO" ...
    <RANGEEX_QUOTED> ...
    <RANGEEX_GOOP> ...

    at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:211) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
    at org.neo4j.index.impl.lucene.IndexType.query(IndexType.java:303) ~[neo4j-lucene-index-2.0.3.jar:2.0.3]
    at org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:251) ~[neo4j-lucene-index-2.0.3.jar:2.0.3]
    at org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:263) ~[neo4j-lucene-index-2.0.3.jar:2.0.3]
    at org.neo4j.cypher.internal.spi.v2_0.TransactionBoundQueryContext$NodeOperations.indexQuery(TransactionBoundQueryContext.scala:169) ~[neo4j-cypher-2.0.3.jar:2.0.3]
    at org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:116) ~[neo4j-cypher-compiler-2.0-2.0.3.jar:2.0.3]
Caused by: org.apache.lucene.queryParser.ParseException: Encountered " "}" "} "" at line 1, column 15.
Was expecting one of:
    "TO" ...
    <RANGEEX_QUOTED> ...
    <RANGEEX_GOOP> ...

    at org.apache.lucene.queryParser.QueryParser.generateParseException(QueryParser.java:1849) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
    at org.apache.lucene.queryParser.QueryParser.jj_consume_token(QueryParser.java:1731) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
    at org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:1530) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
    at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1319) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
    at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1275) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]
    at org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1234) ~[lucene-core-3.6.2.jar:3.6.2 1423725 - rmuir - 2012-12-18 19:45:40]

1 个答案:

答案 0 :(得分:1)

你也应该能够使用:

interface MyModelRepository extends GraphRepository<MyModel> {

   List<MyModel> findByDescriptionContaining(String searchText);
}

如果字段已编入索引,则使用正确的索引和复合lucene查询自动创建查询。