Skip to content

Neo4j

Install

Commands

  • delete all

    MATCH (n)
    DETACH DELETE n;
    

  • check index

    ALL db.indexes() YIELD tokenNames, properties WHERE \
                        '{label}' IN tokenNames AND '{property_name}' IN properties \
                        RETURN tokenNames, properties
    

  • create index

    CREATE INDEX ON :{label}({property_name})
    

  • create node

    tx.run("""
        UNWIND keys($data) AS brand_name
        MERGE (:Brand {name: brand_name})
        """, data=data)
    

  • create relation

    tx.run("""
        UNWIND $data AS record
        UNWIND keys(record.brand_json) AS brand_name
        MATCH (b:Brand {name: brand_name})
        MERGE (b)-[r:MENTIONED_IN {year_month: record.year_month, country: record.country}]->(b)
            ON CREATE SET r.mentionCount = record.brand_json[brand_name]
            ON MATCH SET r.mentionCount = r.mentionCount + record.brand_json[brand_name]
        """, data=data)
    

  • 匹配

    MATCH (n:Brand)-[r:COMPETES_WITH|MENTIONED_IN]->(m)
    WHERE r.year_month >= '2024-08' 
      AND r.year_month <= '2024-10'
      AND r.country IN ['中国']
      AND n.name <> m.name  // 添加这一行来移除相同的品牌
    WITH n.name AS brandName, m.name AS mentionedBrandName,
         SUM(coalesce(r.coMentionCount, 0)) AS totalCoMentionCount,
         SUM(coalesce(r.mentionCount, 0)) AS totalMentionCount
    RETURN brandName, mentionedBrandName, totalCoMentionCount, totalMentionCount