Skip to content

Instantly share code, notes, and snippets.

@yanatan16
Last active December 25, 2015 00:38
Show Gist options
  • Save yanatan16/6888749 to your computer and use it in GitHub Desktop.
Save yanatan16/6888749 to your computer and use it in GitHub Desktop.
A simple neo4j based recommendations engine

Recommendations Engine in neo4j

Node Types

  • Project: { type: "project", id: <id>, featured: <bool> }
  • User: { type: "user", id: <id> }
  • Tag: { type: "tag", name: <name> }

Relationships

  • (project)-[:TAG]->(tag)
  • (user)-[:FOLLOW]->(project|user)
  • (user)-[:INTEREST]-(tag)
  • (user)-[:INTERACT {action: 'view|fund|create'}]->(project)

Queries

  • Featured projects in a tag
START tag=node(*)
MATCH (tag)<-[:TAG]-(cat)
WHERE tag.type = "tag"
AND tag.name = <tagname>
AND cat.featured! = true
RETURN cat;
  • Recommend projects to a user based on users who view projects like him
START user=node(*)
MATCH (user)-[:INTERACT]->(iproj)<-[:INTERACT]-(user2)-[:INTERACT]->(proj)
WHERE user.type = "user"
AND user.id = <id>
RETURN proj, COUNT(proj);
  • Recommend projects to a user based on categories interested in
START user=node(*)
MATCH (user)-[:INTEREST]->(cat)<-[:TAG]-(proj)
WHERE user.type = "user"
AND user.id = <id>
RETURN proj, COUNT(proj);
  • Recommend categories to a user based on projects viewed
START user=node(*)
MATCH (user)-[:INTERACT]->(proj)-[:TAG]->(cat)
WHERE user.type = "user"
AND user.id = <id>
RETURN cat, COUNT(cat);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment