Drupal and Neo4J

4,692 views
4,394 views

Published on

Graph databases and a use case with Drupal.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,692
On SlideShare
0
From Embeds
0
Number of Embeds
53
Actions
Shares
0
Downloads
10
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Drupal and Neo4J

  1. 1. Drupal & Graphs
  2. 2. • The “problem” • Graph databases • Neo4J • Examples • Drupal & graph • Future
  3. 3. The problem
  4. 4. too many joins
  5. 5. query is unknown
  6. 6. tricks only graphs can solve
  7. 7. 1M nodes, ~50 rel/node Depth RDBMS Neo4J Returned records 2 0.016 0.01 ~2’500 3 30.267 0.168 ~110’000 4 1543.505 1.359 ~600’000 5 unfinished 2.132 ~800’000
  8. 8. Such speed So wow Very graph
  9. 9. Examples
  10. 10. • Business Intelligence • Content Management • Fraud Detection • Geo • Graph Search • Identity & Access Management • Impact Analysis • Logistics • Master Data Management • Network and Data Center Management • Product Catalog • Recommendation Engine • Resource Authorization & Access Control • Social Network
  11. 11. http://gist.neo4j.org/
  12. 12. Graph databases
  13. 13. Node Node Relationship
  14. 14. Jim Lisa :COOK_FOR
  15. 15. Jim:PERSON Lisa:PERSON :COOK_FOR city: London gender: male city: San Francisco gender: female meal: Jalfrezi score: 9.8 user_index::uid::3 user_index::uid::8
  16. 16. Jim:PERSON Lisa:PERSON :COOK_FOR city: London gender: male city: San Francisco gender: female meal: Jalfrezi score: 9.8 :LOVE user_index::uid::3 user_index::uid::8
  17. 17. hop hop hop ? N hops
  18. 18. Start
  19. 19. designing graph db
  20. 20. John Visit Paris Eiffel Louvre VisitVisit
  21. 21. John Visit Paris Eiffel Louvre HasHas
  22. 22. John Attended ParisEiffel Louvre Include Travel Include City
  23. 23. 1973 Jan JuneMarch 12 245 1986 3 11
  24. 24. Node Term Italy Node! {t:Italy} vs :HAS_TERM :TERM_NAME
  25. 25. Neo4J
  26. 26. Server: embedded - server mode low latency network low level API REST API better control better scaling JVM only languages
  27. 27. Backend
  28. 28. db labels nodes propsrels
  29. 29. Node inUse nextRelId nextPropId
  30. 30. Relationship inUse firstNode secondNode relType firstPrevRelId firstNextRelId secondPrevRelId secondNextRelId nextPropId
  31. 31. Disks Record files File system cache Object cache Traversal API Cypher Transaction log Transaction management Core API
  32. 32. Core API
  33. 33. Traversal API
  34. 34. Cypher
  35. 35. MATCH (n)-[r]->(m)
  36. 36. • MATCH (n)-[r]->(m) • MATCH (n:USER)-[:EAT]->(m:FOOD) • MATCH p = (n)--(m) • MATCH (n{name:’Jim’})-[r]->(m) • MATCH (o)-->(n)<-[*1..3]-(m) • MATCH [:TRAVEL{by:”bus”}]->(n)
  37. 37. START n=node(*)
  38. 38. • START n=node(12) • START n=node({12, 3, 7}) • START n=node:user_index(uid=“12”) • START n=node(3), m=node(12)
  39. 39. • WHERE n.name = ‘Jim’ • WHERE n.has(“name”) • WITH count(n) AS all WHERE all > 10
  40. 40. • RETURN n • RETURN collect(n), o.name • RETURN length(p)
  41. 41. I want a good party this Friday. Show me my foaf who has at least 20 close friends - so I can avoid awkward parties. And they don’t know my ex.
  42. 42. START n=node(12) MATCH p = (n)-[:FRIEND*]->(m), (m)<-[:FRIEND*1..2]-(o) WHERE any(p IN collect(o) WHERE p.name != ‘Liz’) WITH count(o) AS total WHERE total >= 20 RETURN m.name, p, total, collect(o)
  43. 43. CREATE (jim:USER{hair:’green’}), (erica:USER{hair:’brown’}), jim-[:REPORTS_TO{type:’TPS’}]->erica; ! MATCH (n) SET n.name = ‘Walter’; ! MATCH (n) DELETE n;
  44. 44. Drupal <3 Neo4J
  45. 45. https://drupal.org/ project/neo4j_connector
  46. 46. Neo4JNeo4J-PHP Neo4J! Drupal! Connector REST API
  47. 47. • Pluggable indexes • Dynamic labels, properties and relationships • “smart” indexing
  48. 48. DEMO
  49. 49. Future? • Cypher builder • Views integration • More field support • Embedded graph display
  50. 50. Thank You Questions?

×