Jose Villaveces
Jose Villaveces

Reputation: 91

How to parse an index query in Neo4j?

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.

Upvotes: 0

Views: 208

Answers (1)

Eve Freeman
Eve Freeman

Reputation: 33155

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

Upvotes: 2

Related Questions