Neo4j-cypher查询中的多个匹配语句,带有if else conditon

时间:2016-06-24 07:30:44

标签: java neo4j cypher

我必须搜索某些节点,例如eq.page,无论它们是否与其他节点类似的标签有关系。

 If they are connected to tag nodes then search for the search string in page name and the tag names 

Else search for the search string in page name only
MATCH ...//nodes of certain type    
WHERE    
    if r is null'
      ...//Match query without relation for searching
    else 
      ...//Match query without relation for searching

Return ...

MATCH (n:page)<-[r:pagetag]-(tag)
if  r is null 
then n.title CONTAINS 'java'or tag.name IN ["java"] 
return distinct n.name
else  n.title CONTAINS 'java'return distinct n.name
  END

此查询出错。可能是语法问题。但我想只为这些页面搜索这样的内容。

3 个答案:

答案 0 :(得分:2)

终于实现了我想要的东西。谢谢大家。 OPTIONAL Match对我很有用。

MATCH (s:page)
WITH s
OPTIONAL MATCH (s)<-[r:pagetag]-(tag)
WITH s,r,tag
Where s.pagename contains 'juniors'or tag.name contains 'math'
return distinct s.pagename

答案 1 :(得分:1)

这不仅仅是基本条件吗?

Content-Disposition: form-data; name="f"; filename*=utf-8''pesta%C3%B1a2.png

答案 2 :(得分:0)

我认为你不能在Neo4j中使用if else,你必须使用case,或者foreach来模拟if。