Reputation: 305
I'm kind of new to Neo4J: I've built an application that uses Neo4j using SpringData. I have a @NodeEntity that contains 'name' and 'year' properties and as a search by name and year is commonly used, I defined a compound index on these two fields:
@Getter
@Setter
@NoArgsConstructor
@ToString(of = { "name", "year" })
public abstract class BaseContent<D extends BaseContentDTO> extends BaseEntity {
@Indexed(indexName = "search_content")
protected String name;
@Indexed(indexName = "search_content")
protected Integer year;
}
I'm trying to query content by name and year, using this compound index. This query works from the Neo4j web-admin, but it doesn't when I try to run it with SpringData.
This is my query in SpringData:
@Query("start movie=node:search_content(\"name={name} AND year={year}\") return movie;")
public T findByNameAndYear(@Param("name") String name, @Param("year") Integer year);
The error I'm getting:
org.apache.cxf.interceptor.Fault: null at
BadInputException
I don't understand what I'm doing wrong. I've tried different variations, like using {0} and {1} instead of param names, but this doesn't help either.
By the way, this is the Cypher query, works well in the web-admin:
start movie=node:search_content('name:Salt AND year:2010') return movie.name, movie.year;
And if I use in the @query ':' instead of '=' like this:
@Query("start movie=node:search_content(\"name:{name} AND year:{year}\") return movie;")
I get this error:
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: org.apache.lucene.queryParser.ParseException: Cannot parse 'name:{name} AND year:{year}': Encountered " "}" "} "" at line 1, column 10.
Was expecting one of:
"TO" ...
<RANGEEX_QUOTED> ...
<RANGEEX_GOOP> ...
at
I really appreciate your assistance,
Carmel
Upvotes: 0
Views: 238
Reputation: 5734
Try to take out your actual query look up out side the (). I mean inside parenthesis you need to mention explicitly some value over which cypher will look out.
@Query("start movie=node:search_content(name='Matrix') WHERE movie.year={year} return movie)
This will search all the nodes based on index search_content and one property as name='Matrix'
, but it could have other value like className='org.abc.Movie'
or something like that.
Upvotes: 2