0

I am trying to filter feeds which contains user actvitity. I am using @QueryResult object to retrieve the result. I need both the feeds and the relationship information of user Liked Feeds. But while retrieving the feeds getting error: org.neo4j.rest.graphdb.entity.RestNode cannot be cast to java.lang.Iterable. (I am using SDN 3.3.0.RELEASE and neo4j 2.1.7)

@QueryResult
public interface FeedsIterableResult {
        @ResultColumn("f")
        Collection<Feed> getFeeds();

        @ResultColumn("r")
        Collection<UserInspiredByFeed> getPaths();
    }

@Query("match (feed:Feed)-[:FEED_CONTAINS_TAG]->(t:Tag)<-[:USER_FAVORITED_TAG]-(u:User{username:{1}}) "
            + "where feed.feedType in {0} "
            + "with u, feed "
            + "optional match (u)-[rel:USER_LIKED_FEED]->(feed) "
            + "return feed as f, rel as r "
            + "union match (u:User{username:{1}})-[:USER_FAVORITED_USER]->(u2:User)-[:USER_LIKED_FEED|:USER_CREATED_FEED]->(feed:Feed) "
            + "where feed.feedType in {0} "
            + "with u2, feed "
            + "optional match (u2)-[rel:USER_LIKED_FEED]->(feed) "
            + "return feed as f, rel as r "         
            + "order by f.timeAdded desc "
            + "skip {2} limit {3}")
FeedsIterableResult getAllFavoriteFeeds(String[] typeFilter, String userName, int skip, int limit);

If I convert the query as suggested by Luanne, I am getting following error: Type mismatch: expected Map, Node or Relationship but was Collection.

New Query:

    @QueryResult
    public interface FeedsIterableResult {
        @ResultColumn("f")
        List<Feed> getFeeds();

        @ResultColumn("r")
        List<UserInspiredByFeed> getPaths();
    }

@Query("match (feed:Feed)-[:FEED_CONTAINS_TAG]->(t:Tag)<-[:USER_FAVORITED_TAG]-(u:User{username:{1}}) "
            + "where feed.feedType in {0} "
            + "with u, feed "
            + "optional match (u)-[rel:USER_INSPIREDBY_FEED]->(feed) "
            + "return collect(feed) as f, collect(rel) as r "
            + "union match (u:User{username:{1}})-[:USER_FAVORITED_USER]->(u2:User)-[:USER_INSPIREDBY_FEED|:USER_CREATED_FEED]->(feed:Feed) "
            + "where feed.feedType in {0} "
            + "with u2, feed "
            + "optional match (u2)-[rel:USER_INSPIREDBY_FEED]->(feed) "
            + "return collect(feed) as f, collect(rel) as r "           
            + "order by f.timeAdded desc "
            + "skip {2} limit {3}")
FeedsIterableResult getAllFavoriteFeeds(String[] typeFilter, String userName, int skip, int limit );

1 Answer 1

2

Your query returns feed as f, a node, and rel as r, a relationship. But the FeedsIterableResult expects them to be collections. Each "row" returned by that query will contain a feed node and a rel relationship.

To match your QueryResult, you would have to change your Cypher query to return collections of feeds and rels. Or change FeedsIterableResult to expect single nodes and relationships and have getAllFavoriteFeeds return a Collection of FeedsIterableResult.

Sign up to request clarification or add additional context in comments.

6 Comments

But can i send collect(feed) and collect(rel) in union? I tried this too, but it was not working.
It should return two columns for feeds and relation respectively but right now giving exception.
I am not sure if this is the cause of your new exception, but the union will return two rows, one row from each union. But you're mapping onto a single FeedsIterableResult.
Its ok Luanne I have got the result using your other suggestion, by returning single nodes. But there is one minor problem in that too. The skip and limit I have applied is just working for the second union but I want it to work on whole result.
That's not possible currently. You can apply it to each part of the union but not the entire resultset.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.