Chapter 16. Movies! Friends! Bargains! - Recommendations

In the last part of this exercise we wanted to add recommendations to the app. One obvious recommendation is movies that our friends liked (and their friends too, but with less importance). The second was recommendations for new friends that also liked the movies that we liked most.

Doing this kind of ranking algorithms is really fun with graph databases. They are applied to the graph by traversing it in a certain order, collecting information on the go and deciding which paths to follow and what to include in the results.

Lets say I'm only interested in the top 10 recommendations each.

        // TODO Work In Progress 1/path.length()*stars
        user.breathFirst().relationship(FRIEND, OUTGOING).relationship(RATED, OUTGOING).evaluate(new Evaluator(Path path) {
            if (path.length > 5) return EXCLUDE_AND_STOP;
            Relationship rating = path.lastRelationship();
            if (rating.getType().equals(RATED)) {
                rating.getProperty()
                return INCLUDE_AND_STOP;
            }
            return INCLUDE_AND_CONTINUE;
        })