Facebook Graph Search with Cypher and Neo4j

3,704 views
3,486 views

Published on

How to build your own Facebook Graph Search with Cypher and Neo4j.

Demo:
neographsearch.herokuapp.com

Blog post:
http://maxdemarzi.com/2013/01/28/facebook-graph-search-with-cypher-and-neo4j/

Github:
https://github.com/maxdemarzi/neo_graph_search

Published in: Business, Technology, Sports

Facebook Graph Search with Cypher and Neo4j

  1. 1. Facebook GraphSearch with Neo4jMax De MarziMonday, April 29, 13
  2. 2. Can I Haz?Monday, April 29, 13
  3. 3. NopeMonday, April 29, 13
  4. 4. #9,998,383,750,000Monday, April 29, 13
  5. 5. Can I makemy own?Monday, April 29, 13
  6. 6. MaybeMonday, April 29, 13
  7. 7. What do Iknow aboutNLP?Monday, April 29, 13
  8. 8. NothingMonday, April 29, 13
  9. 9. What do Iknow?Monday, April 29, 13
  10. 10. Monday, April 29, 13
  11. 11. andMonday, April 29, 13
  12. 12. CypherMonday, April 29, 13
  13. 13. I can querya graphMonday, April 29, 13
  14. 14. How?Monday, April 29, 13
  15. 15. Matching PatternsMonday, April 29, 13
  16. 16. ASCII ArtMonday, April 29, 13
  17. 17. () --> ()ASCII ArtMonday, April 29, 13
  18. 18. Named NodesMonday, April 29, 13
  19. 19. (A) --> (B)Named NodesMonday, April 29, 13
  20. 20. LOVESTyped RelationshipsMonday, April 29, 13
  21. 21. A -[:LOVES]-> BLOVESTyped RelationshipsMonday, April 29, 13
  22. 22. Describing a PathMonday, April 29, 13
  23. 23. A --> B --> CDescribing a PathMonday, April 29, 13
  24. 24. AB CMultiple PathsMonday, April 29, 13
  25. 25. A --> B --> C, A --> CAB CMultiple PathsMonday, April 29, 13
  26. 26. A --> B --> C, A --> CAB CA --> B --> C <-- AMultiple PathsMonday, April 29, 13
  27. 27. The START ClauseMonday, April 29, 13
  28. 28. The START ClauseSTART me=node(1)RETURN meMonday, April 29, 13
  29. 29. with an IndexMonday, April 29, 13
  30. 30. with an IndexSTART me=node:Users(name=‘Max’)RETURN meMonday, April 29, 13
  31. 31. The MATCH ClauseMonday, April 29, 13
  32. 32. The MATCH ClauseSTART me=node:Users(name=‘Max’)MATCH me -[:friends]-> peopleRETURN peopleMonday, April 29, 13
  33. 33. My friends who like cheeseMonday, April 29, 13
  34. 34. My friends who like cheeseSTART me=node:Users(name=‘Max’)thing=node:Things(name=‘Cheese’)MATCH me -[:friends]-> people -[:like]-> thingRETURN peopleMonday, April 29, 13
  35. 35. My friends who like cheeseMonday, April 29, 13
  36. 36. My friends who like cheeseSTART me=node:Users(name=‘Max’)thing=node:Things(name=‘Cheese’)MATCH me -[:friends]-> people,people -[:like]-> thingRETURN peopleMonday, April 29, 13
  37. 37. My friends who like ?Monday, April 29, 13
  38. 38. My friends who like ?START me=node({me}),thing=node:Things({thing})MATCH me -[:friends]-> people,people -[:like]-> thingRETURN peopleParams :{“me”: 1, “thing”: “name: cheese”}Monday, April 29, 13
  39. 39. My friends who like ? and ?Monday, April 29, 13
  40. 40. My friends who like ? and ?START me=node({me}),thing1=node:Things({thing1}),thing2=node:Things({thing2})MATCH me -[:friends]-> people,people -[:like]-> thing1,people -[:like]-> thing2RETURN peopleParams :{“me”: 1, “thing1”: “name: cheese”,“thing2”: “name: wine”}Monday, April 29, 13
  41. 41. I need to build aCypher QueryMonday, April 29, 13
  42. 42. SEMR✦ Gateway drug to NLP✦ 4 years old✦ Didn’t work on my Mac✦ Pointed me to TreetopMonday, April 29, 13
  43. 43. Treetop✦ Create a Grammar bymaking some Rules✦ Turn expression intoSyntax Tree✦ Build custom Syntax Nodes✦ Prune the tree✦ to_cypherMonday, April 29, 13
  44. 44. Friends RuleMonday, April 29, 13
  45. 45. Friends Rulerule friends“friends” <Friends>endMonday, April 29, 13
  46. 46. friends to_cypherMonday, April 29, 13
  47. 47. friends to_cypherclass Friends < Treetop::Runtime::SyntaxNodedef to_cypherreturn {:start => "me = node({me})",:match => "me -[:friends]-> people",:return => "people",:params => {"me" => nil }}endendMonday, April 29, 13
  48. 48. Likes RuleMonday, April 29, 13
  49. 49. Likes Rulerule likes"who like" <Likes>endMonday, April 29, 13
  50. 50. likes to_cypherMonday, April 29, 13
  51. 51. likes to_cypherclass Likes < Treetop::Runtime::SyntaxNodedef to_cypherreturn {:match => "people -[:likes]-> thing"}endendMonday, April 29, 13
  52. 52. Thing RuleMonday, April 29, 13
  53. 53. Thing Rulerule thing[a-zA-Z0-9]+ <Thing>endMonday, April 29, 13
  54. 54. thing to_cypherMonday, April 29, 13
  55. 55. thing to_cypherclass Thing < Treetop::Runtime::SyntaxNodedef to_cypherreturn {:start => "thing = node:things({thing})",:params => {"thing" => "name: " + self.text_value } }endendMonday, April 29, 13
  56. 56. Show and Tellhttps://github.com/maxdemarzi/neo_graph_searchhttp://maxdemarzi.com/2013/01/28/facebook-graph-search-with-cypher-and-neo4j/Monday, April 29, 13

×