gpt4 book ai didi

java - 克服 Cypher Lucene 查询上的 NullPointerException

转载 作者:行者123 更新时间:2023-12-02 06:01:27 26 4
gpt4 key购买 nike

我正在尝试使用 neo4j 2.0.1 数据库中的 lucene 索引对节点名称属性中的特定术语进行模糊查询。执行这些查询时,虽然 lucene 语法看起来不错,但它会失败并出现神秘的 NullPointerException。我可能在 lucene 语法中犯了一些简单的错误,但我怎样才能发现那是什么?

        String query = "start n=node:node_auto_index({searchCriteria}) "+                "match (n:Provenance) " +                 "return n " +                     "order by n.created desc " +                     "limit 10";        String expr = term;        if(term.contains(" ") || term.contains("\t"))            expr = "\"" + term + "\"";        expr = "'name:" + expr + "~'";        log.info("search expression=" + expr);        Map<String,Object>params = new HashMap();        params.put("searchCriteria", expr);

当使用“track”参数运行此方法时,输出如下:

INFO: search expression='name:track~'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.(Term.java:38)    at org.apache.lucene.queryParser.QueryParser.getFieldQuery(QueryParser.java:643)    at org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:1436)    at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1319)    at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1275)    at org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1234)    at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:206)    at org.neo4j.index.impl.lucene.IndexType.query(IndexType.java:303)    at org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:251)    at org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:263)    at org.neo4j.kernel.impl.coreapi.AbstractAutoIndexerImpl$ReadOnlyIndexToIndexAdapter.query(AbstractAutoIndexerImpl.java:249)    at org.neo4j.cypher.internal.spi.v2_0.TransactionBoundExecutionContext$NodeOperations.indexQuery(TransactionBoundExecutionContext.scala:166)    at org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113)    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)    at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142)    at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142)    at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$$translateException(ExceptionTranslatingQueryContext.scala:149)    at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.indexQuery(ExceptionTranslatingQueryContext.scala:142)    at org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:66)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:64)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:35)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:34)    at org.neo4j.cypher.internal.compiler.v2_0.pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:34)    at org.neo4j.cypher.internal.compiler.v2_0.pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:33)    at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)    at scala.collection.Iterator$$anon$14.hasNext(Iterator.scala:388)    at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)    at scala.collection.Iterator$class.isEmpty(Iterator.scala:256)    at scala.collection.AbstractIterator.isEmpty(Iterator.scala:1157)    at org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe.internalCreateResults(TopPipe.scala:42)    at org.neo4j.cypher.internal.compiler.v2_0.pipes.PipeWithSource.createResults(Pipe.scala:71)    at org.neo4j.cypher.internal.compiler.v2_0.pipes.PipeWithSource.createResults(Pipe.scala:68)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder.org$neo4j$cypher$internal$compiler$v2_0$executionplan$ExecutionPlanBuilder$$prepareStateAndResult(ExecutionPlanBuilder.scala:149)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder$$anonfun$2.apply(ExecutionPlanBuilder.scala:126)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder$$anonfun$2.apply(ExecutionPlanBuilder.scala:125)    at org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder$$anon$6.execute(ExecutionPlanBuilder.scala:50)    at org.neo4j.cypher.internal.ExecutionPlanWrapperForV2_0.execute(CypherCompiler.scala:93)    at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:61)    at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:65)    at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:78)    at org.mitre.provenance.db.neo4j.Neo4JStorage.execute(Neo4JStorage.java:1216)

最佳答案

您的 Lucene 语法是正确的。如果您提供查询作为参数,则必须不使用“'”字符。

所以使用

expr = "name:" + expr + "~"; 

而不是

expr = "'name:" + expr + "~'";

您还可以提供模糊因子,如下所示:

expr = "name:" + expr + "~0.8"; 

关于java - 克服 Cypher Lucene 查询上的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22637914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com