【问题标题】:Neo4j-Multiple match statement in cypher query with if else conditonNeo4j-使用 if else 条件的密码查询中的多重匹配语句
【发布时间】:2016-10-26 18:00:56
【问题描述】:

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

 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

此查询出错。可能是语法问题。但我只想像这样搜索页面。

【问题讨论】:

    标签: java neo4j cypher


    【解决方案1】:

    终于如愿以偿。谢谢大家。可选匹配对我来说效果很好。

    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
    

    【讨论】:

      【解决方案2】:

      这不只是基本条件吗?

      MATCH (n:page)<-[r:pagetag]-(tag)
      WITH n,r,tag
      WHERE r IS NULL AND (n.title CONTAINS 'java' or tag.name IN ["java"])
      OR NOT r is NULL AND (n.title CONTAINS 'java')
      return distinct n.name 
      

      【讨论】:

      • 先生,它还没有为我工作。好像页面节点和标签节点没有关系,则此查询不会搜索特定的页面节点。很抱歉,但需要您的指导。直到我正在努力。谢谢
      • 实际上,先生,我正在使用 neo4j ver 2.3.2,其中 null 检查和 where not 子句不起作用。可选匹配救了我。非常感谢你。我已经发布了正确的查询
      【解决方案3】:

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

      【讨论】:

      • Do case可以有像我想为if-else做条件的查询
      • 请再次阅读我的问题。可能是我无法让你理解,但这个问题对我没有帮助。
      猜你喜欢
      • 1970-01-01
      • 2013-11-11
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多