0
votes

I'm querying neo4j's auto index several times trying to retrieve nodes by the property ID. It works well most of the time, but if my query contains a lucene special character (+ - && || ! ( ) { } [ ] ^ " ~ * ? : ) I get a ParseException.

I tried to parse the query string with the following code (as suggested here):

String escapeChars ="[\\\\+\\-\\!\\(\\)\\:\\^\\]\\{\\}\\~\\*\\?]";

String escaped = userInput.replaceAll(escapeChars, "\\\\$0");

As a result, the index query returns null.

Am I doing something wrong? Is there better way of escaping those characters?

Edit:

I also tried using Lucene's QueryParser.escape(query) method with no luck.

1
Can you provide the query that is giving you trouble? And also, if the exception provides any further information, that could be helpful.femtoRgon
Use parameters instead of literal values for your query, and put double quotes around your value in the lucene query string.Michael Hunger

1 Answers

2
votes

Probably easier to put it in quotes if you can (and double quotes need a \\ in front of them, in Cypher, anyway).

id:"my_id_with*123y47123&"

http://console.neo4j.org/r/bpxvzv