Neo4j Label与Node Property技术咨询:魔兽世界公会数据建模疑问
Hey there, let's work through your WoW Neo4j project questions—this stuff is right up my alley!
First, let's lock in those missing labels to make your graph structure intuitive and query-friendly:
- Character: You’ve already got this covered—use it for every WoW player character, with attributes like
name,server,level, etc. - Guild: Also set—perfect for representing player guilds, with attributes like
name,server,faction. - Class: Definitely make this a standalone Label! Each character is tied to exactly one class, and classes have their own identity (think: Warrior, Druid) plus relationships to specializations. Add attributes like
name,armor_typeif you want extra context. - Specialization: Another key Label—each class has 2-4 specs, and each spec maps to a role. Include attributes like
nameandrole(whereroleis one of "Tank", "Healer", "Damage").
Recommended Relationships
To tie these together properly:
(Character)-[:MEMBER_OF]->(Guild): Links characters to their guild(Character)-[:PLAYS_CLASS]->(Class): Connects a character to their chosen class(Class)-[:HAS_SPEC]->(Specialization): Maps each class to its available specializations
Here are the Cypher queries you need, with quick explanations:
1. Find all tanks in guild "ABC"
MATCH (guild:Guild {name: "ABC"})<-[:MEMBER_OF]-(char:Character)-[:PLAYS_CLASS]->(class:Class)-[:HAS_SPEC]->(spec:Specialization {role: "Tank"}) RETURN char.name AS Character_Name, class.name AS Class, spec.name AS Tank_Spec ORDER BY Class, Character_Name
This query starts at the "ABC" guild, pulls all its members, traces their class and specialization, then filters only for specs marked as tanks. It returns clean, organized results grouped by class.
2. Find all Druids on server "DEF"
MATCH (char:Character {server: "DEF"})-[:PLAYS_CLASS]->(class:Class {name: "Druid"}) RETURN char.name AS Druid_Character, char.server AS Server ORDER BY Druid_Character
Straightforward: targets all characters on the "DEF" server who are playing the Druid class, then returns their names and server.
3. Find all characters grouped by their guild
MATCH (guild:Guild)<-[:MEMBER_OF]-(char:Character) RETURN guild.name AS Guild_Name, COLLECT(char.name) AS Guild_Members ORDER BY Guild_Name
This groups every character by their guild, returning each guild's name alongside a list of all its members. If you want to target a specific guild, just add WHERE guild.name = "Your_Guild_Name" right after the MATCH clause.
内容的提问来源于stack exchange,提问作者charles082986

