0
votes

I'm having troubles with part of my project which uses spring-data-neo4j. I've got node entity class:

@NodeEntity
@TypeAlias("Ad")
public class Ad{
@GraphId
private Long nodeId;

@Indexed(indexName = "adId", unique = true)
private Long id;

@Fetch
@RelatedTo(type="CONTAINS", direction = Direction.OUTGOING)
private Collection<Keyword> keywords;
 ...

And repository for it with such methods:

@Query(value = "START ad1=node({adv}) MATCH ad1-[r1:CONTAINS]->Keyword<-[r2:CONTAINS]-similar RETURN similar SKIP {param_offset} LIMIT {param_limit}")
Iterable<Ad> findSimilarAds(@Param("adv") Ad advertising, @Param("param_limit") int limit, @Param("param_offset") int offset);

@Query(value = "START ad1=node:adId(id={p_id}) MATCH ad1-[r1:CONTAINS]->Keyword<-[r2:CONTAINS]-similar RETURN similar SKIP {param_offset} LIMIT {param_limit}")
Iterable<Ad> findSimilarAdsById(@Param("p_id") Long id, @Param("param_limit") int limit, @Param("param_offset") int offset);

And then test, which do just something like this:

  1. create Keyword 1, create Keyword 2 - ok

  2. create Ad node with id 123456 containing Keyword 1 and Keyword 2 - ok

  3. create Ad node with id 654321 containing Keyword 1 - ok

  4. get Ad with id 654321 - works ok, generated query is:

    START ad=node:adId(id={0}) RETURN ad params {0=654321}

  5. get similar ads with findSimilarAds() and argument is the Ad from previous step - works good, it returns Ad with id 123456, generated query:

    START ad1=node({adv}) MATCH ad1-[r1:CONTAINS]->Keyword<-[r2:CONTAINS]-similar RETURN similar SKIP {param_offset} LIMIT {param_limit} params {param_offset=0, param_limit=10, adv=48}

  6. after that, get similar ads with findSimilarAdsById() method - the id argument is 654321L. The result query looks like this:

    START ad1=node:adId(id={p_id}) MATCH ad1-[r1:CONTAINS]->Keyword<-[r2:CONTAINS]-similar RETURN similar SKIP {param_offset} LIMIT {param_limit} params {param_offset=0, p_id=654321, param_limit=10}

But It is returning empty org.springframework.data.neo4j.conversion.QueryResultBuilder instance (i'm trying trying to get elements with iterator) instead of Iterable collection with Ad 123456. I've tried almost everything i could think of, withou any success, am I missing something important?

Versions:

  • spring-data-neo4j 2.3.3.RELEASE
  • neo4j-cypher-dsl 1.8
  • spring stuff 3.1.4.RELEASE
  • spring-data-neo4j-aspects 2.3.2.RELEASE
1

1 Answers

0
votes

I think you run in the numeric indexing issue, that is not usable with cypher. Due to issues with the lucene parser.

If you use

@Indexed(indexName = "adId", unique = true, numeric=false)
private Long id;

it should work.

Or you have to pass in ValueContext.numeric(id) instead of Long id as the parameter of the method.

For derived finders we handle that automatically, but for user defined queries we cannot know what you actually pass in.