用户登录网站并创建不同的活动。此事件作为节点保存到neo4j数据库中,然后生成" EVENT_CREATOR"用户和事件节点之间的关系。
我正在尝试为我网站上的所有用户事件(使用Play2框架)实现分页,例如,如果用户访问第一页,我需要加载前十个事件;加载第10至第20个事件的第2页,依此类推......
这是我的疑问:
apache
目前,我正在获取用户创建的所有事件,并将它们添加到数组列表中。
match(n);
...
skip k;
limit 10;
return n;
我想更新代码以运行Cypher查询,并添加以下代码行(使用示例https://www.tutorialspoint.com/neo4j/neo4j_cypher_api_example.htm)
private static List<PublicEvent> getEvents(int page, int pageSize) {
List<PublicEvent> events = new ArrayList<PublicEvent>();
GraphDatabaseService db = Neo4JHelper.getDatabase();
try (Transaction tx = db.beginTx()) {
Index<Node> userIndex = db.index().forNodes(ModelIndex.Users);
IndexHits<Node> userNodes = userIndex.get(ModelGraphProperty.UserProfile.UserName, SessionUtilities.getCurrentUser());
Node me = userNodes.next(); //current logged in user
PagingIterator paginator = new PagingIterator(me.getRelationships(GraphRelation.RelTypes.EVENT_CREATOR).iterator(), pageSize); // get all the events that were created by this user
paginator.page(page);
// adding all the created events by this user to an array
if (paginator.hasNext()) {
Relationship eventCreator = (Relationship)paginator.next();
Node event = eventCreator.getOtherNode(me);
events.add(new PublicEvent(event));
}
tx.success();
}
db.shutdown();
return events;
}
期待第二个参数:记录器。什么是错误或者我做错了什么?
答案 0 :(得分:1)
RestGraphDatabase db= (RestGraphDatabase)Neo4JHelper.getDatabase();
RestCypherQueryEngine engine=new RestCypherQueryEngine(db.getRestAPI());
Map<String, Object> params = new HashMap<String, Object>();
params.put( "id", eventId );
String query="match (s) where id(s) = {id} return s;";
QueryResult result=engine.query(query,params);
if(result.iterator().hasNext()) {
//HERE PUT WHATEVER YOU NEED
}
看一下文档: