2

I have read the document, and i found that curly brackets are normally used to form a subquery or it can be used to describe the properties of a node or relationships.

But i notice that some times curly brackets are used separately, and i can't understand what exactly it was doing.

Here are some example of curly brackets used separately:

MATCH (p:Person)
RETURN
  p,
  p.name AS name,
  toUpper(p.name),
  coalesce(p.nickname, 'n/a') AS nickname,
  {name: p.name, label: head(labels(p))} AS person    // what is this sentence doing?
MATCH (e:Entity)-[r1:{}]-(t1:Entity)
WHERE e.lid IN {{qids}} AND e.name <> ""
WITH e, r1, t1
OPTIONAL MATCH  (t1)-[r2]-(t2:Entity)
WHERE t1.name = ""
   AND t2.name <> ""
   AND t2 <> e
WITH e, r1,  t1, r2, t2
WHERE t1.name <> "" OR (t2 IS NOT NULL AND  t2.name <> "")
RETURN e,
   { name : r1.name, labelId: r1.labelId, type: type(r1)  } as r1,  // this
   t1,
   { name : r2.name, labelId: r2.labelId, type: type(r2)  } as r2,  // and this
   t2
ORDER BY t2.score IS NOT NULL DESC, t1.score IS NOT NULL DESC,
   t2.score DESC, t1.score DESC
LIMIT 20

many thanks in advance!

Taja Jan
  • 942
  • 1
  • 1
  • 11
Frisia
  • 23
  • 4

2 Answers2

1

You are essentially creating a map of key value pairs. Along the lines of

{ name: "Some-name", labelId: "some-value" ... }
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
0

Kevin's answer is correct.

You are defining a node here Person. The Key-value pair is to define the properties of the node in question.

MATCH (p:Person)
RETURN
  p,
  p.name AS name,
  toUpper(p.name),
  coalesce(p.nickname, 'n/a') AS nickname,
  {name: p.name, label: head(labels(p))} AS person
  {name: p.name, label: head(labels(p))}

Here, you're defining {key1: value1, key2: value2}.

This is a representation of what would be considered defining an object from an interface in most programming languages.

RU-D
  • 224
  • 8
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 18 '23 at 10:07