그래프에서 합계 연산을하고 있습니다. DB : 몇 개의 노드를 비교하고 그래프의 특정 영역이 얼마나 비슷한지를 나타내는 숫자를 계산합니다. 충분히 큰, 나는 노드 사이의 관계를 만들고 싶습니다.Neo4j/Cypher : 특정 조건이 충족되면 관계를 만듭니다.
그림이 충분히 큰지 확인하는 것 외에는 모든 것을 수행하는 쿼리가 있습니다. 그것은 현재 유사성 점수가 0 인 유사성 관계를 생성합니다. 그리고 나는 그것을 원하지 않습니다.
내 전체 사이퍼 쿼리는 약간 길기 때문에이 게시물에 대해 간략화했습니다. 따라서 neo4j 콘솔에는 샘플 그래프 db를 제공 할 수 없습니다. 내 그래프에는 Center
노드가 포함되어 있으며 노드는 Affinity
이고 노드 주위에는 Searched
노드가 있습니다. 2 개의 센터 노드가 유사한 선호도 또는 검색된 노드를 갖는 경우, 센터 노드는 관계를 가져야합니다. 내가 올바른 명백하게 결코 다양한 장소에서 CASE 문을 도입 시도,하지만 한
MATCH (a:Center), (x:Center)
WHERE id(a) <> id(x)
OPTIONAL MATCH a-->(aff1:Affinity), x-->(aff2:Affinity)
WHERE aff1.affinityReference=aff2.affinityReference // if the Affinity nodes have the same reference, then their Center nodes are similar
OPTIONAL MATCH a-->(search1:Search), x-->(search2:Search)
WHERE search1.searchTerm = search2.searchTerm // if the Search nodes have the same searchTerm, then their Center nodes are similar
WITH a, x,
SUM (CASE WHEN aff2.relative_weight IS NULL THEN 0 ELSE (aff2.relative_weight * 5) END) AS AffinityScore, // Affinity nodes have a relative weight, which shall be used in the similarity calculation.
(count(search2) * 5) AS SearchScore // matching Search nodes shall just be counted and multiplied with 5.
OPTIONAL MATCH x-[r1:IS_SIMILAR_TO]->() // Delete all similarity relationships for x
WITH a,x,r1,AffinityScore, SearchScore, (AffinityScore+SearchScore) AS TotalScore
DELETE r1 // delete relationship if it exists...
MERGE // ... and create it anew.
x-[:IS_SIMILAR_TO {
SimilarityScore:Total,
AffinityScore:AffinityScore,
SearchScore:SearchScore
}]->a
RETURN a, x, AffintyScore, SearchScore, TotalScore
ORDER BY TotalScore DESC
:
여기에 주석을 단순화 문입니다. 어디로 가야합니까?
도움 주셔서 감사합니다.
간지 트릭을 할 해당 배열을 반복합니다! – rene
정확히 내가 필요했던 것 –
왜 Cypher는 더 좋은 방법이 없습니까? – fiatjaf