[英]Get information from a cypher query inside python implementation when using py2neo?
I am implementing a search engine in python that will be connected to neo4j graph database. 我正在用python实现一个搜索引擎,它将连接到neo4j图形数据库。 I have some data in the database and I want to get some information from the database using python code.
我的数据库中有一些数据,我想使用python代码从数据库中获取一些信息。 I am connected with the database and I want to make a cypher query that will give me the prices that are lower than the average.
我已与数据库连接,我想进行一次密码查询,该查询将给我提供低于平均价格的价格。
The first thing, I think it is good do to is to make a cypher query for the average price and then to use if(else) statements in python in order to differentiate between cheap and expensive. 首先,我认为这样做的好处是对平均价格进行密码查询,然后在python中使用if(else)语句来区分便宜还是昂贵。
def cheap(self):
query = '''
MATCH (p:Price)-[:COSTS]-(s:Service)
WITH avg(toFloat(p.monthly)) as {Average}, p.currency as {Currency}, s.service_name as {Service}
Return Average,Currency, Service
'''
return cheap = graph.run(query, average= self.Average, currency= self.Currency, service_name=self.Service )
This python code is showing nothing. 此python代码未显示任何内容。 Does anyone have any idea on how to proceed??
有人对如何进行有任何想法吗?
One issue is that assignment in python doesn't return anything, so 一个问题是python中的赋值不返回任何内容,因此
return cheap = ...
will always return None
. 将始终返回
None
。 Try return graph.run(...)
instead. 尝试
return graph.run(...)
。
Also, the WITH
statement in cypher is used to alias variables, not to filter them. 此外,cypher中的
WITH
语句用于别名变量,而不是对其进行过滤。 Your cipher query should filter in a WHERE
clause instead: 您的密码查询应改为在
WHERE
子句中进行过滤:
MATCH (p:Price)-[:COSTS]-(s:Service)
WITH avg(toFloat(p.monthly)) AS Average, p.currency AS Currency, s.service_name AS Service
WHERE Average = {Average}, Currency = {Currency}, Service = {Service}
RETURN Average,Currency, Service
Hopefully this helps! 希望这会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.