Sorry to flog a dead horse but getting cypher to work in the repository is often frustrating.
This code works exactly as expected:
Code:
Set<Note> query = repo.search(id, "(?i).*"+search+".*");
....
@Query(
"START user=node({0}) "
"MATCH user-[:FRIEND*0..3]-friends, "+
"friends-[:NOTE*1]->notes "+
"WHERE notes.note=~ {1} "+
"RETURN notes")
Set<Note> search(long id, String search);
But once I add more complexity, things start going tits up. This works in webadmin:
Code:
START user=node(548)
MATCH user-[:FRIEND*0..3]-friends
WITH distinct(friends) AS group, user
MATCH group-[:NOTE*1]->notes
WHERE notes.note=~ /(?i).*steve.*/
OR notes.tags=~ /(?i).*steve.*/
WITH notes, group, user
MATCH path=shortestPath(user-[:FRIEND*]-group)
RETURN notes, group, length(path)
ORDER BY length(path) ASC
If I hard code the regular expressions, this works in my repository:
Code:
Iterable<HashMap<String, Object>> query = repo.search2(id, "(?i).*"+search+".*");
....
@Query(
"START user=node({0}) "+
"MATCH user-[:FRIEND*0..3]-friends "+
"WITH distinct(friends) AS group, user "+
"MATCH group-[:NOTE*1]->notes "+
"WHERE notes.note=~ /(?i).*steve.*/ "+
"OR notes.tags=~ /(?i).*steve.*/ "+
"WITH notes, group, user "+
"MATCH path=shortestPath(user-[:FRIEND*]-group) "+
"RETURN notes, group, length(path) "+
"ORDER BY length(path) ASC " )
Iterable<HashMap<String, Object>> search2(long id, String search);
But the moment I pass in the search variable...
Code:
@Query(
"START user=node({0}) "+
"MATCH user-[:FRIEND*0..3]-friends "+
"WITH distinct(friends) AS group, user "+
"MATCH group-[:NOTE*1]->notes "+
"WHERE notes.note=~ {1} "+
"OR notes.tags=~ {1} "+
"WITH notes, group, user "+
"MATCH path=shortestPath(user-[:FRIEND*]-group) "+
"RETURN notes, group, length(path) "+
"ORDER BY length(path) ASC " )
Iterable<HashMap<String, Object>> search2(long id, String search);
The query fails and I get a BadInputException, which makes no sense since the query works in webadmin, it works in java with a fixed regex, and works in java with a parameter, albeit for a smaller query.
Again, any help would be much appreciated. Here is the stack trace if it's of any use
Code:
Expected a parameter named 1 at
BadInputException
org.neo4j.server.rest.repr.RepresentationExceptionHandlingIterable.exceptionOnHasNext(RepresentationExceptionHandlingIterable.java:51)
org.neo4j.helpers.collection.ExceptionHandlingIterable$1.hasNext(ExceptionHandlingIterable.java:61)
org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)
org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:58)
org.neo4j.server.rest.repr.Serializer.serialize(Serializer.java:75)
org.neo4j.server.rest.repr.MappingSerializer.putList(MappingSerializer.java:61)
org.neo4j.server.rest.repr.CypherResultRepresentation.serialize(CypherResultRepresentation.java:50)
org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:42)
org.neo4j.server.rest.repr.OutputFormat.format(OutputFormat.java:170)
org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:120)
org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:107)
org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:55)
org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:68)
java.lang.reflect.Method.invoke(Method.java:601)
org.neo4j.server.statistic.StatisticFilter.doFilter(StatisticFilter.java:62)
Caused by:
org.neo4j.rest.graphdb.RestResultException: Expected a parameter named 1 at
BadInputException