ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • neo4j example - 레스토랑
    Intelligent Product/Neo4J 2022. 3. 3. 23:07

    - 데이터 확인

    MATCH (n) RETURN n

    전체 데이터 확인


    - Alice의 친구들을 조회

    MATCH (alice:Person {name:"Alice"})-[:IS_FRIEND_OF]-(person) RETURN person, alice

    Alice의 친구 조회 - 테이블
    Alice의 친구 조회 - 그래프


    - 레스토랑 조회

    MATCH (location)<-[:LOCATED_IN]-(restaurant)-[:SERVES]->(cuisine) 
    RETURN location, restaurant, cuisine

    레스토랑 조회


    - 마곡동에 위치한 레스토랑 조회

    MATCH (magok:Location {name:"마곡동"})<-[:LOCATED_IN]-(restaurant)-[:SERVES]->(cuisine) 
    RETURN magok, restaurant, cuisine

    마곡동에 위치한 레스토랑 조회


    - 중식당 조회

    MATCH (location)<-[:LOCATED_IN]-(restaurant)-[:SERVES]->(chinese:Cuisine {name: "중식당"}) 
    RETURN location, restaurant, chinese

    중식당 조회


    - Alice와 친구들이 좋아하는 음식점

    MATCH (restaurant:Restaurant)-[:LOCATED_IN]->(location),
          (restaurant)-[:SERVES]->(cuisine),
          (person:Person)-[:LIKES]->(restaurant)
    RETURN restaurant.name, collect(person.name) as likers, count(*) as occurence
    ORDER BY occurence DESC


    - Alice를 제외한 친구들이 좋아하는 음식점

    MATCH (restaurant:Restaurant)-[:LOCATED_IN]->(location),
          (restaurant)-[:SERVES]->(cuisine),
          (person:Person)-[:LIKES]->(restaurant)
    WHERE person.name <> "Alice"
    RETURN restaurant.name, collect(person.name) as likers, count(*) as occurence
    ORDER BY occurence DESC

    or

     

    MATCH (alice:Person {name:"Alice"}),
          (alice)-[:IS_FRIEND_OF]-(friend),
          (restaurant:Restaurant)-[:LOCATED_IN]->(location),
          (restaurant)-[:SERVES]->(cuisine),
          (friend)-[:LIKES]->(restaurant)
    RETURN restaurant.name, collect(friend.name) as likers, count(*) as occurence
    ORDER BY occurence DESC


    - Alice의 친구들이 좋아하는 중식당

    MATCH (alice:Person {name:"Alice"}),
          (alice)-[:IS_FRIEND_OF]-(friend),
          (restaurant:Restaurant)-[:LOCATED_IN]->(location),
          (restaurant)-[:SERVES]->(:Cuisine {name:"중식당"}),
          (friend)-[:LIKES]->(restaurant)
    RETURN restaurant.name, location.name, collect(friend.name) as likers, count(*) as occurence
    ORDER BY occurence DESC


    - Alice의 친구들이 좋아하는 마곡동에 있는 식당

    MATCH (alice:Person {name:"Alice"}),
          (alice)-[:IS_FRIEND_OF]-(friend),
          (restaurant:Restaurant)-[:LOCATED_IN]->(location:Location {name:"마곡동"}),
          (restaurant)-[:SERVES]->(cuisine),
          (friend)-[:LIKES]->(restaurant)
    RETURN restaurant.name, collect(friend.name) as likers, count(*) as occurence
    ORDER BY occurence DESC


    - Alice의 친구인 Jasper와 Jay가 좋아하는 식당

    MATCH (restaurant:Restaurant)-[:LOCATED_IN]->(location),
          (restaurant)-[:SERVES]->(cuisine),
          (person:Person)-[:LIKES]->(restaurant)
    WHERE person.name = "Jasper" OR person.name = "Jay"
    RETURN restaurant.name, collect(person.name) as likers, count(*) as occurence
    ORDER BY occurence DESC

     

     

    참고

    https://ichi.pro/ko/neo4jleul-sayonghayeo-leseutolang-chucheon-enjin-guchug-172708887086902

     

    'Intelligent Product > Neo4J' 카테고리의 다른 글

    Neo4j Rest API 서버 구성하기 #3  (0) 2022.05.11
    Neo4j RestAPI 서버 구성하기 #2  (0) 2022.05.10
    Neo4j RestAPI 서버 구성하기 #1  (0) 2022.05.09
    Neo4J 데이터 셋 구성  (0) 2022.03.03
    Neo4J 세팅  (0) 2022.03.03
Designed by Tistory.