0
votes

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

1
have you tried with this : @Query("start movie=node:search_content(name={name} AND year={year}) return movie.name, movie.year) ? I mean without any \"agpt
I have. This is the exception it throws: java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Unclosed parenthesis "start movie=node:search_content(name={name} AND year={year}) return movie;" ^ at SyntaxExceptionCarmel Baumel-Ezra
I actually have doubt on query structure. Why don't you 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'. I am not sure about this, but just give it a try.agpt
basically () is applied in more broader way over the index given. in above comment, I have mentioned it explicitly name='Matrix' but it could have other value like className='org.abc.Movie' or something like that.agpt
The last one works. Thanks (though I still don't realize why a cipher query that works on the admin doesn't work on the SpringData). Thanks again :)Carmel Baumel-Ezra

1 Answers

2
votes

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.