0

I realise this may not be ideal usage, but apart from all the graphy goodness of Neo4j, I'd like to show a collection of nodes, say, People, in a tabular format that has indexed properties for sorting and filtering

I'm guessing the Type of a node can be stored as a Link, say Bob -> type -> Person, which would allow us to retrieve all People

Are the following possible to do efficiently (indexed?) and in a scalable manner?

  • Retrieve all People nodes and display all of their names, ages, cities of birth, etc (NOTE: some of this data will be properties, some Links to other nodes (which could be denormalised as properties for table display's and simplicity's sake)
  • Show me all People sorted by Age
  • Show me all People with Age < 30

Also a quick how to do the above (or a link to some place in the docs describing how) would be lovely

Thanks very much!

Oh and if the above isn't a good idea, please suggest a storage solution which allows both graph-like retrieval and relational-like retrieval

whalabi
  • 1,675
  • 3
  • 12
  • 16

2 Answers2

1

if you want to operate on these person nodes, you can put them into an index (default is Lucene) and then retrieve and sort the nodes using Lucene (see for instance How do I sort Lucene results by field value using a HitCollector? on how to do a custom sort in java). This will get you for instance People sorted by Age etc. The code in Neo4j could look like

Transaction tx = neo4j.beginTx();
idxManager = neo4j.index()
personIndex = idxManager.forNodes('persons')
personIndex.add(meNode,'name',meNode.getProperty('name'))
personIndex.add(youNode,'name',youNode.getProperty('name'))
tx.success()
tx.finish()


'*** Prepare a custom Lucene query context with Neo4j API ***'
query = new QueryContext( 'name:*' ).sort( new Sort(new SortField(     'name',SortField.STRING, true ) ) )
results = personIndex.query( query )

For combining index lookups and graph traversals, Cypher is a good choice, e.g.

START people = node:people_index(name="E*") MATCH people-[r]->() return people.name, r.age order by r.age asc

in order to return data on both the node and the relationships.

Community
  • 1
  • 1
Peter Neubauer
  • 6,311
  • 1
  • 21
  • 24
  • can neo4j make use of an index when sorting by a relationship property (r.age in this case)? – milan Aug 08 '13 at 13:09
1

Sure, that's easily possible with the Neo4j query language Cypher.

For example:

start cat=node:Types(name='Person') 
match cat<-[:IS_A]-person-[born:BORN]->city
where person.age > 30
return person.name, person.age, born.date, city.name
order by person.age asc
limit 10

You can experiment with it in our cypher console.

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80