来自neo4j和python匹配计数

63lcw9qa  于 2022-11-05  发布在  Python
关注(0)|答案(1)|浏览(153)

给定此代码块

parent_node_count = db.run(f"MATCH(parentNode) WHERE "
                              f"parentNode.LC = '{x[4]}' "
                              f"AND parentNode.U = '{x[5]}' "
                              f"AND parentNode.R = '{x[6]}' "
                              f"AND parentNode.Type = 'Parent' "
                              f"AND parentNode.Deck_Set = '{outline}' "
                              f" return parentNode")
            n = 0

            for record in parent_node_count:
                print(record["parent_node_count"]["id"])
                n = n + 1

            print("total number of records : " + str(n))
            total = int(n)

如何从MATCH查询中获取匹配项的数量?
在提供的代码中,它总是返回0,我已经在浏览器中检查过了,匹配的计数不等于零。

vawmfj5a

vawmfj5a1#

变量parent_node_count是一个neo4j.work.result.Result对象,它不包含对象ID。您需要将其添加到密码查询中,并通过record.data()对象访问它。请参见下面的示例:

parent_node_count = tx.run(f"MATCH(parentNode) WHERE "
                          f"parentNode.LC = '{x[4]}' "
                          f"AND parentNode.U = '{x[5]}' "
                          f"AND parentNode.R = '{x[6]}' "
                          f"AND parentNode.Type = 'Parent' "
                          f"AND parentNode.Deck_Set = '{outline}' "
                          f" return parentNode, ID(parentNode) AS id")
    print(parent_node_count)
    n = 0

    for record in parent_node_count:
        print(record.data()["parentNode"])
        print(record.data()["id"])
        n = n + 1

    print("total number of records : " + str(n))
    total = int(n)

Result:
<neo4j.work.result.Result object at 0x7ff6cd035f60>    <- parent_node_count
{'Latitude': 28.5553263, 'Longitude': 68.2132128, 'Name': 'Dayna'} <- record
321  <- id
{'Latitude': 54.1863169, 'Longitude': 19.7204087, 'Name': 'Dione'} <- record
333  <- id
total number of records : 2

相关问题