如何在Cypher中无序查询多个属性值 [英] How to query multiple property values out of order in Cypher

查看:278
本文介绍了如何在Cypher中无序查询多个属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个产品名称列表[衬衫,鞋子,裤子,帽子,眼镜] 我正在尝试执行一个查询,该查询将使用不区分大小写的正则表达式并以任意顺序返回产品,只要该值存在即可.

I have a list of product names [shirt,shoes,pants,hat,glasses] I'm trying to perform a query that will return the products using regular expression that's case insensitive and in any order as long as the value exists.

我只能按顺序查询它们 MATCH(产品:产品)在哪里product.name =〜(?i).*衬衫.鞋子."返回产品

I'm only able to query them in order MATCH (product:Product) WHERE product.name =~"(?i).*shirt.shoes." RETURN product

我如何乱序查询它们,即 MATCH(产品:产品)在哪里product.name =〜(?i).* hat. shirt."?

How can I query them out of order ie MATCH (product:Product) WHERE product.name=~"(?i).*hat.shirt."?

谢谢

推荐答案

您要使用正则表达式精确搜索什么?您是否正在寻找仅包含列表中关键字之一的产品名称?还是多个关键字?

What exactly do you want to search for with the regular expression? Are you looking for product names that contain just one of the keywords in your list? Or multiple keywords?

如果只想查找列表中至少包含一个关键字的产品名称,则可以使用字符串比较运算符CONTAINStoLower()函数使比较大小写不敏感:

If you just want to find product names that contain at least one of the keywords in your list you could use the string comparison operator CONTAINS along with the toLower() function to make the comparison case insensitive:

WITH {products} AS products
MATCH (p:Product) WHERE any(x IN products WHERE toLower(p.name) CONTAINS toLower(x))
RETURN p

其中{products}是您的产品名称数组:['shirt', 'shoes', 'pants', 'hats', 'glasses']

Where {products} is your array of product names: ['shirt', 'shoes', 'pants', 'hats', 'glasses']

修改

要查找包含所有关键字的产品"节点,请使用all()列表谓词.

To find Product nodes that contain all keywords, use the all() list predicate.

例如,假设您要查找名称中包含"shirt"和"shoes"的所有Product节点:

For example, let's say you want to find all Product nodes where the name contains "shirt" and "shoes":

WITH ["shirt", "shoes"] AS keywords
MATCH (p:Product) WHERE all(x IN keywords WHERE toLower(p.name) CONTAINS toLower(x))
RETURN p

这篇关于如何在Cypher中无序查询多个属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆