일부 관계가 다른 관계보다 훨씬 중요하고이를 나타 내기 위해 가중치가 부여 된 데이터가 있습니다. 예를 들어 다음과 같은 그래프가 있습니다.
(city_a:City)-[:has{weight:10}]->(casino:Event)
(city_a:City)-[:has{weight:1}]->(restaurant:Event)
(city_a:City)-[:has{weight:30}]->(university:Event)
(city_a:City)-[:has{weight:25}]->(library:Event)
......
(city_b:City)-[:has{weight:2}]->(casino:Event)
(city_b:City)-[:has{weight:2}]->(restaurant:Event)
(city_b:City)-[:has{weight:5}]->(university:Event)
(city_b:City)-[:has{weight:10}]->(library:Event)
......
다음과 같은 입력이 있습니다.
Input: {casino, restaurant, university}
그리고 나는 출력해야
Output: city_a
대부분의 관계가 다른 도시보다 가중치가 높기 때문입니다.
(아마도 내 그래프 모델이 옳지 않을 수도 있지만, 뭔가 생각할 수 없었습니다. 조언은 매우 환영합니다).
그렇다면이 경우에 대한 암호 쿼리를 작성하는 방법은 무엇입니까?
미리 감사드립니다!
다음은 원하는 입력 이벤트보다 적은 도시의 경우를 다루기 위해 'city_c'가 던져진 설명을 기반으로 한 예제 그래프입니다.
merge (city_a:City{name:'city_a'})
merge (city_b:City{name:'city_b'})
merge (city_c:City{name:'city_c'})
merge (casino:Event{name:'casino'})
merge (restaurant:Event{name:'restaurant'})
merge (university:Event{name:'university'})
merge (library:Event{name:'library'})
merge (city_a)-[:has{weight:10}]->(casino)
merge (city_a)-[:has{weight:1}]->(restaurant)
merge (city_a)-[:has{weight:30}]->(university)
merge (city_a)-[:has{weight:25}]->(library)
merge (city_b)-[:has{weight:2}]->(casino)
merge (city_b)-[:has{weight:2}]->(restaurant)
merge (city_b)-[:has{weight:5}]->(university)
merge (city_b)-[:has{weight:10}]->(library)
merge (city_c)-[:has{weight:100}]->(university)
또한 입력 문자열에 의한 빠른 조회를 위해 : Event (name)에 대한 색인이 필요합니다 (이 특정 쿼리에 필요하거나 사용되지는 않지만 : City (name)에 대한 색인도 원할 것입니다)
create index on :Event(name)
여기에서 입력 이벤트에서 해당 이벤트가있는 도시로 일치하는 쿼리를 생성하고 도시 당 일치하는 이벤트 수와 등급 합계를 기준으로 정렬 할 수 있습니다.
대신 with ... as input
쿼리를 매개 변수화하고 싶습니다.
with ['casino', 'restaurant', 'university'] as input
match (e:Event)<-[r:has]-(city:City)
where e.name in input
with city, count(r) as eventCount, sum(r.weight) as weightSum
return city, eventCount, weightSum
order by eventCount desc, weightSum desc
limit 1
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다