From 44c324ec9ae5ec999b8e3bdc840851603efa09dd Mon Sep 17 00:00:00 2001 From: DonRenando Date: Sun, 11 Dec 2016 11:34:31 +0100 Subject: [PATCH] modif neo Variante V2 --- .../movierecommender/controller/MainController.java | 4 ++-- .../movierecommender/controller/Neo4JController.java | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/camillepradel/movierecommender/controller/MainController.java b/src/main/java/com/camillepradel/movierecommender/controller/MainController.java index 96bd0c1..47b4c7f 100644 --- a/src/main/java/com/camillepradel/movierecommender/controller/MainController.java +++ b/src/main/java/com/camillepradel/movierecommender/controller/MainController.java @@ -18,8 +18,8 @@ public class MainController { String message = "Welcome to Spring MVC!"; //Commenter et Decommenter en fonction de BD que l'on veut utiliser - DBControllerInterface db = new MongoDBController(); - //DBControllerInterface db = new Neo4jConnector(); + //DBControllerInterface db = new MongoDBController(); + DBControllerInterface db = new Neo4JController(); @RequestMapping("/hello") public ModelAndView showMessage( diff --git a/src/main/java/com/camillepradel/movierecommender/controller/Neo4JController.java b/src/main/java/com/camillepradel/movierecommender/controller/Neo4JController.java index 8e1b245..b7a1028 100644 --- a/src/main/java/com/camillepradel/movierecommender/controller/Neo4JController.java +++ b/src/main/java/com/camillepradel/movierecommender/controller/Neo4JController.java @@ -170,8 +170,8 @@ public class Neo4JController implements DBControllerInterface { + "LIMIT 5\n" + "MATCH (other_user)-[rat_other_user:RATED]->(m2:Movie)\n" + "WHERE NOT ((target_user)-[:RATED]->(m2))\n" - + "RETURN m2.id AS mov_id, m2.title AS rec_movie_title, rat_other_user.note AS rating, other_user.id AS watched_by\n" - + "ORDER BY rat_other_user.note DESC"); + + "RETURN m2.id AS mov_id, m2.title AS rec_movie_title, AVG(rat_other_user.note) AS rating, COUNT(other_user.id) AS watched_by\n" + + "ORDER BY AVG(rat_other_user.note) DESC, COUNT(other_user.id) DESC"); } catch (ConnectException ex) { Logger.getLogger(Neo4JController.class.getName()).log(Level.SEVERE, null, ex); @@ -181,14 +181,16 @@ public class Neo4JController implements DBControllerInterface { Record record = null; int idMovie = 0; String titre = ""; - int note = 0; + Double noteMoyenneDouble = 0.0; + Integer noteMoyenneInt = 0; while (result.hasNext()) { record = result.next(); idMovie = record.get("mov_id").asInt(); titre = record.get("rec_movie_title").asString(); - note = record.get("rating").asInt(); + noteMoyenneDouble = record.get("rating").asDouble(); + noteMoyenneInt = noteMoyenneDouble.intValue(); - ratings.add(new Rating(new Movie(idMovie, titre,null), userId, note)); + ratings.add(new Rating(new Movie(idMovie, titre,null), userId, noteMoyenneInt)); } return ratings;