예제 #1
0
파일: queries.py 프로젝트: correctiv/aleph
 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}
예제 #2
0
 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}
예제 #3
0
파일: queries.py 프로젝트: tomjie/aleph
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)
예제 #4
0
def upgrade():
    graph = get_graph()
    if graph is None:
        return
    # graph.delete_all()
    for node_type in NodeType.all():
        node_type.ensure_indices(graph)
예제 #5
0
파일: queries.py 프로젝트: rlugojr/aleph
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)
예제 #6
0
파일: queries.py 프로젝트: correctiv/aleph
 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}
예제 #7
0
파일: queries.py 프로젝트: nivertech/aleph
 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
예제 #8
0
파일: __init__.py 프로젝트: nivertech/aleph
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)
예제 #9
0
파일: __init__.py 프로젝트: correctiv/aleph
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)