1

I have a graph containing nodes of two types: Attractions and Hotels.

What I want to do is that query for Hotels that are surrounded by three Attractions. The query I have now (below) gives Hotels that are connected to at least one Attraction.

FOR document IN Attraction
FOR vertex, edge, path IN 1..2 OUTBOUND document GRAPH "LondonAttractionDB" 
FILTER path.vertices[0].entityTypes[0] == "Attraction" OR path.vertices[0].entityTypes[0] == "Attraction" OR path.vertices[0].entityTypes[0] == "Attraction"
FILTER path.vertices[1].entityTypes[0] == "Hotel"
FOR prop4 IN path.edges[0].properties  
FILTER prop4.name == "name" AND prop4.value == "Food_and_beverage_location" 
OR prop4.name == "name" AND prop4.value == "Food_and_beverage_location" 
OR prop4.name == "name" AND prop4.value == "Accommodation_location" 
RETURN DISTINCT path

This gives the following result. (Orange - Hotel, Green - Attraction)

enter image description here

How do I get the result shown within circles? (Hotels connected to exactly three attractions)

Any help is much appreciated.

1 Answer 1

2

It's difficult to answer without details about the dataset (document structure and collections), but based on your example query and description, I would use a different approach:

  • Go over all documents (attractions and hotels seem to reside in the same collection)
  • Filter by type Hotel
  • For every hotel node, get neighbors with incoming edges
  • Filter these nodes by type Attraction
  • Count how many nodes there are for the hotel
  • Return hotels with exactly three connected attractions
FOR hotel IN Attraction
  FILTER doc.entityTypes[0] == "Hotel"
  LET attractions = (
      FOR vertex IN 1..1 INBOUND hotel GRAPH "LondonAttractionDB"
      FILTER vertex.entityTypes[0] == "Attraction"
      RETURN 1
  )
  FILTER LENGTH(attractions) == 3
  RETURN hotel
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.