Tiago
Tiago

Reputation: 2966

Neo4j - Searching from an array of nodes

In my situation I've a bunch of nodes that represent the users and they have relation to books they read.

This user have a property that says where they are from, and I added them to an index, based on their country.

So I would like to search in the index for users from one country, and list the books that people from there read more, some sorting by grouping.

could any one give me a help how to do this? I'm having some trouble getting users from the index, and doing the query

Upvotes: 0

Views: 156

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39915

Couple of assumptions based on your descriptions:

  • users have a country property, it contains e.g. France as value
  • you have a index called users and you store the user node's country property there
  • relationship type to connect users and books is READ
  • book nodes have a title property

Based on these assumptions the cypher query would look like:

start user=node:users(country='France')
match user-[:READ]->book
return book.title, count(*) as rank
order by rank desc
limit 20    

side note: best approach to ask this kind of questions is to create a sample graph on http://console.neo4j.org and share your setup on SO.

Upvotes: 1

Related Questions