neo4j提高密码查询性能 [英] neo4j improving cypher query performance
问题描述
我有items
个图数据库.每个item
连接到多个properties
,可以由多个items
共享.
我添加了一个由几个properties
定义的search
节点.
I have items
graph db. each item
is connected to multiple properties
, which can be shared by multiple items
.
I add a search
node which is defined by few properties
.
所以我将(search_node)连接到多个(properties_nodes),连接到多个(items_nodes)
So I have (search_node) connected to multiple (properties_nodes) connected to multiple (items_nodes)
现在,我想获得由{x}个或更多个属性来回答此搜索的项目列表.按匹配属性的数量排序.
Now I would like to get a list of items who answer this search by {x} properties or more. Ordered by number of matching properties.
start se=node:node_auto_index(name = {name}), pr = node:node_auto_index(type="item_property")
MATCH p=(se) -[rt:SEARCH]- > (pr)<-[r]-(item)
WHERE Has(item.type) and (item.type = "item")
WITH item, collect(distinct pr.name) as rs
where length(rs) > {x}
RETURN item.name as item_name, length(rs) as matching_properties
ORDER BY matching_properties desc
对我来说,性能问题是它将搜索所有匹配项,甚至那些仅匹配一个属性的项,然后删除所有匹配项少于{x}的项. 如果{x}大于1,那就是一大浪费.
The performance issue for me, is that it will search for all matching items, even those who match for only one property, and then remove all the items who are matching less than {x}. If {x} is higher than 1, it's a big waste.
如何仅通过{x}个匹配属性来匹配"?
How can I "MATCH" only by {x} matching properties?
创建了一个匹配示例: http://console.neo4j.org/?id=adrgsh
Created a matching sample : http://console.neo4j.org/?id=adrgsh
(neo4j 1.9.2版)
(neo4j version 1.9.2)
推荐答案
IMHO只能匹配具有> x个属性的项目,您仍然需要查找所有与搜索节点具有相同属性的项目.发布后,您可以使用<过滤出匹配项x个属性相同.你得到什么样的数字?在最坏的情况下,匹配了多少个项目,丢弃了多少个项目?
IMHO to be able to match only items with > x properties, you still need to find all those items that have properties in common with the search node. Post that, you can filter out the matches with < x properties in common. What kind of numbers are you getting? In your worst case, how many items were matched and how many were discarded?
您可以简化查询(控制台上匹配的结果,但是可能缺少此问题中未指定的一些详细信息)
You can simplify your query (matched results on the console but it could be missing some details that are not specified in this question)
START se=node(11)
MATCH (se)-[:SEARCH]- >(pr)<-[:HAS]-(item)
WHERE HAS (item.type) AND (item.type = "item")
WITH count(pr) AS matching_properties, item
WHERE matching_properties>1
RETURN item.name AS item_name, matching_properties
ORDER BY matching_properties DESC
这篇关于neo4j提高密码查询性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!