def execute(self): query, args = self.query() edges = [] for row in self.graph.run(query, **args): data = EdgeType.dict(row.get('rel')) data['$source'] = NodeType.dict(row.get('source')) data['$target'] = NodeType.dict(row.get('target')) edges.append(data) return {'results': edges}
def suggest_nodes(graph, collection_id, prefix, limit, offset): """Suggest nodes whose names match the given prefix. Returns the result sorted by the visible degree count of each node. """ collections = authz.collections(authz.READ) collection_id = collection_id if len(collection_id) else collections q = "MATCH (n)-[:PART_OF]->(c1:Collection) " \ "MATCH (n)-[r]-(p) " \ "MATCH (p)-[:PART_OF]->(c2:Collection) " \ "WHERE c1.alephCollection IN {collection_id} " \ "AND c2.alephCollection IN {acl} " \ "AND n.name =~ {regex} " \ "WITH n, count(r) AS deg " \ "ORDER BY deg DESC " \ "SKIP {offset} LIMIT {limit} " \ "RETURN n, deg " regex = '(?i).*%s.*' % prefix cursor = graph.run(q, regex=regex, acl=collections, collection_id=collection_id, limit=limit, offset=offset) nodes = [] for row in cursor: node = NodeType.dict(row.get('n')) node['$degree'] = row.get('deg') nodes.append(node) return _make_response(nodes, [], limit=limit, offset=offset)
def upgrade(): graph = get_graph() if graph is None: return # graph.delete_all() for node_type in NodeType.all(): node_type.ensure_indices(graph)
def suggest_nodes(graph, collection_id, prefix, limit, offset): """Suggest nodes whose names match the given prefix. Returns the result sorted by the visible degree count of each node. """ collections = authz.collections(authz.READ) collection_id = collection_id if len(collection_id) else collections q = ( "MATCH (n)-[:PART_OF]->(c1:Collection) " "MATCH (n)-[r]-(p) " "MATCH (p)-[:PART_OF]->(c2:Collection) " "WHERE c1.alephCollection IN {collection_id} " "AND c2.alephCollection IN {acl} " "AND n.name =~ {regex} " "WITH n, count(r) AS deg " "ORDER BY deg DESC " "SKIP {offset} LIMIT {limit} " "RETURN n, deg " ) regex = "(?i).*%s.*" % prefix cursor = graph.run(q, regex=regex, acl=collections, collection_id=collection_id, limit=limit, offset=offset) nodes = [] for row in cursor: node = NodeType.dict(row.get("n")) node["$degree"] = row.get("deg") nodes.append(node) return _make_response(nodes, [], limit=limit, offset=offset)
def execute(self): query, args = self.query() nodes = [] for row in self.graph.run(query, **args): node = NodeType.dict(row.get('node')) # node['$degree'] = row.get('degree') nodes.append(node) return {'results': nodes}
def execute(self): query, args = self.query() nodes = [] for row in self.graph.run(query, **args): node = NodeType.dict(row.get('node')) node['$degree'] = row.get('degree') nodes.append(node) return nodes
def upgrade_graph(): graph = get_graph() if graph is None: return # graph.delete_all() cur = graph.run("MATCH (n) WHERE NOT (n)--() DELETE n;") log.debug("Deleted %(nodes_deleted)s orphan nodes.", cur.stats()) for node_type in NodeType.all(): node_type.ensure_indices(graph)
def upgrade_graph(): graph = get_graph() if graph is None: return # graph.delete_all() cur = graph.run("MATCH (n) WHERE NOT (n)--() DELETE n;") log.debug("Deleted %(nodes_deleted)s orphan nodes.", cur.stats()) # Common base type indexes if 'fingerprint' not in graph.schema.get_indexes(BASE_NODE): graph.schema.create_index(BASE_NODE, 'fingerprint') # if 'id' not in graph.schema.get_uniqueness_constraints(BASE_NODE): # graph.schema.create_uniqueness_constraint(BASE_NODE, 'id') if 'id' not in graph.schema.get_indexes(BASE_NODE): graph.schema.create_index(BASE_NODE, 'id') for node_type in NodeType.all(): node_type.ensure_indices(graph)