mr.setMap(def); else if(REDUCE_JS.equals(fileName)) mr.setReduce(def);
private Message addConnectionView() { try { DesignDocument connectionDocument = prepareDocument("_design/connection"); Map<String, MapReduce> views = new HashMap<>(); MapReduce frequentFunction = new MapReduce(); frequentFunction.setMap("function(doc) { if(doc.from && doc.to) { emit([doc.from, doc.to] , 1 ); } }"); frequentFunction.setReduce("function (key, values) { return sum(values); }"); views.put("frequent", frequentFunction); connectionDocument.setViews(views); Response resp = Utils.getCouchDbConnectionClient().design().synchronizeWithDb(connectionDocument); if (resp.getError() != null) return Notifications.error("Preparing database 'connection'..."); else return Notifications.success("Preparing database 'connection'..."); } catch (Exception e) { return Notifications.error("Preparing database 'connection'..."); } }
private Message addConnectionView() { try { DesignDocument connectionDocument = prepareDocument("_design/connection"); Map<String, MapReduce> views = new HashMap<>(); MapReduce frequentFunction = new MapReduce(); frequentFunction.setMap("function(doc) { if(doc.from && doc.to) { emit([doc.from, doc.to] , 1 ); } }"); frequentFunction.setReduce("function (key, values) { return sum(values); }"); views.put("frequent", frequentFunction); connectionDocument.setViews(views); Response resp = Utils.getCouchDbConnectionClient().design().synchronizeWithDb(connectionDocument); if (resp.getError() != null) return Notifications.error("Preparing database 'connection'..."); else return Notifications.success("Preparing database 'connection'..."); } catch (Exception e) { return Notifications.error("Preparing database 'connection'..."); } }