0

I'm attempting to use a lucene index in a neo4j 2.0.1 database to do a fuzzy query for particular terms in the name property of nodes. When executing these queries, although the lucene syntax looks OK, it fails with a mysterious NullPointerException. It could be that I've made some straightforward mistake in the lucene syntax, but how can I discover what that is?

        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);

When this method is run with an argument of "track", the output is this:

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)
0

1 Answer 1

2

Your Lucene syntax is correct. If you provide the query as a parameter, you'll have to do it without the "'" characters though.

So use

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

instead of

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

You could also provide a fuzziness factor as follows:

expr = "name:" + expr + "~0.8"; 
Sign up to request clarification or add additional context in comments.

2 Comments

So what would explain the NullPointerException if the Lucene query syntax is correct?
I think there's definitely room for improvement regarding the exception message, but the point is that the lucene query cannot be processed. As you pass the query as a param, i guess Cypher already places the quotes around the query, so you end up with double quotes, which is wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.