0

在我们的数据模型中,我们将一些域实体值外部化到外部节点中。服务对象的模型如下所示:

ref=node(0), 
ref<-[:SERVICE]-subRefNode<-[:SERVICE]-aService-[:HAS_PROPERTY_VALUE]->propValueNode-[:IS_OF_TYPE]->propDefType,
ref<-[:SERVICE]-subRefNode-[:HAS_PROPERTY]->propDefType

节点 subRefNode 持有与所有服务的关系。服务的所有可能属性都通过 ref<-[:SERVICE]-subRefNode-[:HAS_PROPERTY]->propDefType 定义。因此,可能某个节点还没有某个属性(例如评论)的 propValueNode,而其他节点可能有一个但它是空的(用户可能已经输入了评论然后将其清除)。

所以我的问题是如何获取带有空 propValueNode.value 的节点以及那些还没有 propertyValueNode 的节点?我想到了类似...

START ref=node(0) MATCH ref<-[:SERVICE]-subRef, aService-[pvRel?:HAS_PROPERTY_VALUE]->propValueNode-[pdRel:IS_OF_TYPE]->propDef<-[:HAS_PROPERTY]-subRef<-[:SERVICE]-aService WHERE (pvRel IS NOT NULL AND propDef.name = 'comment' AND propValueNode.value=~"^$") OR (pvRel IS NULL AND pdRel IS NULL AND propDef.name="comment") RETURN DISTINCT aService.debug

http://console.neo4j.org/r/7zeoay

...但这错过了没有 propValueNode 的那些。任何提示表示赞赏!

问候, 安迪

如果http://console.neo4j.org/r/7zeoay不再有效,这里是初始图形设置:

start _0 = node(0) with _0 
create
(_1  {type:"SubReferenceNode", name:"SubRef"}),

(_2  {type:"Service", debug:"S0 empty value"}),
(_3  {type:"Service", debug:"S1 missing value node"}),
(_4  {type:"Service", debug:"S2 with value"}),

(_5  {type:"PropertyDefintion", name:"comment"}),
(_6  {type:"PropertyDefintion", name:"name"}),

(_7  {type:"PropertyValue", value:"S0 empty value"}),
(_8  {type:"PropertyValue", value:"S1 missing value node"}),
(_9 {type:"PropertyValue", value:"S2 with value"}),

(_10  {type:"PropertyValue", value:""}),
(_11 {type:"PropertyValue", value:"This is a comment"}),

_0<-[:SERVICE]-_1,
_1<-[:SERVICE]-_2,
_1<-[:SERVICE]-_3,
_1<-[:SERVICE]-_4,

_1-[:HAS_PROPERTY]->_5,
_1-[:HAS_PROPERTY]->_6,

_2-[:HAS_PROPERTY_VALUE]->_7,
_7-[:IS_OF_TYPE]->_6,
_3-[:HAS_PROPERTY_VALUE]->_8,
_8-[:IS_OF_TYPE]->_6,
_4-[:HAS_PROPERTY_VALUE]->_9,
_9-[:IS_OF_TYPE]->_6,

_2-[:HAS_PROPERTY_VALUE]->_10,
_10-[:IS_OF_TYPE]->_5,
_4-[:HAS_PROPERTY_VALUE]->_11,
_11-[:IS_OF_TYPE]->_5    
4

1 回答 1

0

您可以组合两个查询,一个是返回属性“comment”为空值的服务,另一个返回没有属性值为“comment”类型的服务,换句话说,无的服务属性值属于“注释”类型。

START ref=node(0) 
MATCH ref<-[:SERVICE]-subRef, aService-[pvRel?:HAS_PROPERTY_VALUE]->propValueNode-[pdRel:IS_OF_TYPE]->propDef<-[:HAS_PROPERTY]-subRef<-[:SERVICE]-aService 
WHERE (pvRel IS NOT NULL AND propDef.name = 'comment' AND propValueNode.value=~"^$") 
RETURN DISTINCT aService.debug
UNION
START ref=node(0)
MATCH ref<-[:SERVICE]-subRef, aService-[pvRel:HAS_PROPERTY_VALUE]->propValueNode-[pdRel:IS_OF_TYPE]->propDef<-[:HAS_PROPERTY]-subRef<-[:SERVICE]-aService
with aService, collect(propDef.name) as propNames
WHERE NONE( propName in propNames where propName = 'comment')
RETURN DISTINCT aService.debug

不使用“UNION”子句的另一种解决方案是获取每个服务的所有值节点,并仅返回那些其值都不是“comment”类型或只有一个“comment”类型值和值的服务为空,如下面的“Where”子句所示,

START ref=node(0) 
MATCH ref<-[:SERVICE]-subRef, aService-[pvRel:HAS_PROPERTY_VALUE]->propValueNode-[pdRel?:IS_OF_TYPE]->propDef<-[:HAS_PROPERTY]-subRef<-[:SERVICE]-aService 
WHERE propDef.name = 'comment' 
WITH aService, collect(propValueNode) AS valueNodes, propDef 
WHERE NONE (v IN valueNodes 
            WHERE v-[:IS_OF_TYPE]->propDef) OR SINGLE (v IN valueNodes 
                                                       WHERE v.value=~"^$" AND v-[:IS_OF_TYPE]->propDef) 
RETURN aService.debug 
于 2013-09-06T15:44:28.893 回答