1
votes

My entities have an attribute with the name "size". The value of this attribute is one of the followings: "huge", "normal", "small".

Is there a way to order my nodes where "huge">"normal">"small"?

1
luckily your attributes are in alphabetical order as well as in the correct size order. in this case you can still use the order by node.size asc syntax.ulkas

1 Answers

1
votes

If you are using Cypher 2.0, yes.

Try using the CASE expression http://docs.neo4j.org/chunked/milestone/cypher-expressions.html#query-syntax-case

Example:

MATCH n:MyNode
WITH n, CASE n.size
  WHEN 'small' THEN 0
  WHEN 'normal' THEN 1
  WHEN 'huge' THEN 2
  ELSE -1
END as sortOrder
RETURN n ORDER BY sortOrder