where_1

(二)WHERE
//where不单独使用,与match,optional match,start,with搭配
where 与match,optional match 一起用,表示约束
where 与start,with一起用,表示过滤
create(andres:Swedish{name:"Andres",age:36,belt:"white"}),
(peter:Person{name:"Peter",email:"peter_n@example.com",age:34}),
(tobias:Person{name:"Tobias",address:"Sweden/Maimo",age:25}),
(andres)-[:KNOWS{since:1999}]->(peter),
(andres)-[:KNOWS{since:2012}]->(tobias)
1.布尔运算 xor结果不同为true
match(n) where n.name="Peter" XOR
(n.age<30 and n.name="Tobias") OR
NOT(n.name="Tobias" OR n.name="Peter")
return n
2.节点标签过滤
match(n) where n:Swedish return n
3.节点的属性过滤
match(n) where n.age<30 return n
4.关系属性的过滤
match(n)-[k:KNOWS]->(f) where k.since<2000 return f
5.动态节点属性的过滤
//以方括号语法的形式可使用动态计算的值来过滤属性
:param prop:"AGE"
match(n) where n[toLower($prop)]<30 return n
6.属性存在性检查exists
match(n) where exists(n.belt) return n
(二)字符串匹配
//匹配区分大小写
STARTS WITH ,ENDS WITH来匹配字符串的开始或者结尾,如果不关心位置,可以用CONTAINS
1.匹配字符串的开始
match(n) where n.name STARTS WITH "Pet" return n
2.匹配字符串的结尾
match(n) where n.name ENDS WITH "ter" return n
3. 字符串包含
match(n) where n.name CONTAINS "ete" return n
4. 字符串反向匹配
match (n) where NOT n.name STARTS WITH "s" return n
(三)正则表达式
1.正则表达式=~'regexp'
//不区分大小写(?i)多行(?m)单行(?s)
match(n) where n.name=~"(?i)Tob.*" return n
2.正则表达式中的转义字符(包括字符串)
match(n) where n.address=~"Sweden\\/Maimo" return n
(四)在where中使用路径模式
1.模式过滤
//模式返回的是一个路径列表的表达式,列表表达式也是断言,空列表代表false,非空列表代表false
//模式的局限性只能在单条路径中表达,不能像match那样使用逗号分隔多条路径,但可以通过and组合多个模式
match(tobias{name:"Tobias"}),(others)
where others.name in ["Andres","Peter"] AND (tobias)<--(others) return others
2. NOT 过滤
match (persons),(peter{name:"Peter"}) WHERE NOT (persons)-->(peter) return persons
3.模式中的属性过滤
match(n) where (n)-[:KNOWS]-({name:"Tobias"}) return n
4.关系类型的过滤
match(n)-[r]-() where n.name="Andres" AND type(r)=~"K.*" return r
(四)列表 IN
match(a) where a.name in ["Peter","Tobias"] RETURN a
(五)不存在的属性和值
1.属性不存在默认为true
match(n) where n.belt="white" or n.belt is null return n
2.空值过滤
match(person) where person.name="Peter" and person.belt is null return person
(六)属性范围
1.简单范围
match(a) where a.name>="Peter" RETURN a
2.范围组合
match (a) where a.name>"Andres" AND a.name<"Tobias" RETURN a

posted on 2019-01-06 11:35  happygril3  阅读(106)  评论(0编辑  收藏  举报

导航