Skip to content

Commit 50113e3

Browse files
committed
Improved OTU.mergedDescription that includes stateDeepOrder
1 parent 860f43a commit 50113e3

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

schema.graphql

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ type PseudoCharacterInstance {
193193
characterName: String
194194
characterID: String
195195
characterDeepOrder: String
196+
stateDeepOrder: String
196197
stateName: String
197198
stateID: String
198199
stateOrder: String
@@ -240,33 +241,44 @@ type OTU {
240241
(ci)-[hs:HAS_STATE]->(s:State),
241242
(d)-[:APPLICATION_OF]->(schema:Schema)
242243
WITH
243-
DISTINCT c, schema, s{.*, value: hs.value, order:avg(toInteger(hs.order))} AS s //Tuck the order and value relationship properties in temp object with state for use later. For order, we want to save the average value for this state.
244+
DISTINCT c, schema, s, hs.value AS stateValue, hs.order AS stateOrder
244245
245-
// Calculate Character deepOrder using a subquery that doesn't affect row count
246+
// Combined subquery for both Character and State deepOrder
246247
CALL {
247-
WITH c
248-
MATCH path = (c)-[:CHARACTER_OF*0..]->(root:Character)
249-
WITH c, path
250-
ORDER BY length(path) DESC
248+
WITH c, s
249+
// Calculate Character deepOrder
250+
MATCH path1 = (c)-[:CHARACTER_OF*0..]->(rootChar:Character)
251+
WITH c, s, path1
252+
ORDER BY length(path1) DESC
251253
LIMIT 1
254+
255+
// Calculate State deepOrder
256+
MATCH path2 = (s)-[:STATE_OF*0..]->(rootState:State)
257+
WITH c, s, path1, path2
258+
ORDER BY length(path2) DESC
259+
LIMIT 1
260+
252261
RETURN
253-
c.pbotID AS charID,
254-
apoc.text.join([n IN reverse(nodes(path)) | n.order], ".") AS deepOrder
262+
c.pbotID AS charID,
263+
s.pbotID AS stateID,
264+
apoc.text.join([n IN reverse(nodes(path1)) | n.order], ".") AS charDeepOrder,
265+
apoc.text.join([n IN reverse(nodes(path2)) | n.order], ".") AS stateDeepOrder
255266
}
256267
257268
RETURN
258269
{
259270
schema: schema.title,
260271
characterName: c.name,
261272
characterID: c.pbotID,
262-
characterDeepOrder: deepOrder,
273+
characterDeepOrder: charDeepOrder,
263274
stateName: s.name,
264275
stateID: s.pbotID,
265-
stateOrder: s.order,
266-
stateValue: s.value
276+
stateOrder: stateOrder,
277+
stateDeepOrder: stateDeepOrder,
278+
stateValue: stateValue
267279
} AS md
268280
"""
269-
)
281+
)
270282
elementOf: [Group!]! @relation(name: "ELEMENT_OF", direction: OUT)
271283
enteredBy: [OTUEnteredBy]
272284
}

0 commit comments

Comments
 (0)