当预期的属性名称未知时,如何查询图形? [英] How to query the graph when the intended property name is unknown?

查看:84
本文介绍了当预期的属性名称未知时,如何查询图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个相关的问题在这里: 如何在属性名称为参数?

A related question is here: How to query property value when property name is a parameter?

假设我要询问向我推荐500美元的手机".在我的图中,我有:

Let's say if I want to ask "Recommend me 500-dollar phones". And in my graph, I have:

create (p:Product {name:"iPhone 1", price:"500", color:"white"})
create (p:Product {name:"iPhone 2", price:"400", color:"white"})
create (p:Product {name:"iPhone 3", price:"800", color:"black"})

基于向我推荐500美元的手机推荐"的语言,我知道我应该在产品"节点上进行查询,但是我不知道价格"属性.我只想匹配具有某些属性值="500"的任何产品节点.在这种情况下,如何在查询中实现呢?

Based on the language "Recommend me 500-dollar phones", I know I should query on the Product node, but I don't know the 'price' property. I just want to match any product node with some property value = "500". In this case, how to achieve this in the query?

Match(p:Product) where p.x = 500

在这里,我不知道"x"是什么,并且我没有供x接受的属性名称.这可能吗?

Here I don't know what "x" is and I don't have a property name for x to accept. Is this possible?

match (p:Product)
where any(key in keys(node) where key contains 'TEST')
RETURN p.key

如何返回"p.key"值?

How to return the 'p.key' value?

推荐答案

目前尚不清楚您的问题在问什么,因此以下是对两种可能解释的答案:

It is not clear what your question is asking, so here are answers to 2 possible interpretations:

  1. 如果您知道所需的属性键包含字符串"TEST",并且想要获取其不同的属性值:

  1. If you know that the property key(s) of interest contain the string "TEST", and you want to get their distinct property values:

MATCH (p:Product)
WITH p, [k in KEYS(p) WHERE k CONTAINS 'TEST' | p[k]] AS values
UNWIND values AS value
RETURN DISTINCT value;

  • 如果您知道感兴趣的属性值包含字符串"TEST",并且想要获取不同的值:

  • If you know that the property value(s) of interest contain the string "TEST", and you want to get the distinct values:

    MATCH (p:Product)
    WITH p, [k in KEYS(p) WHERE p[k] CONTAINS 'TEST' | p[k]] AS values
    UNWIND values AS value
    RETURN DISTINCT value;
    

  • 如果要展开的列表为空,则UNWIND操作不会产生任何行.

    The UNWIND operation produces no rows if the list being unwound is empty.

    请注意,这些查询非常昂贵,因为它们必须扫描每个Product节点的每个属性.

    Please note that these queries are expensive, since they have to scan every property of every Product node.

    这篇关于当预期的属性名称未知时,如何查询图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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