arangodb / arangodb

🥑 ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions.
https://www.arangodb.com
Other
13.48k stars 834 forks source link

IMDB query question #8854

Open undeadindustries opened 5 years ago

undeadindustries commented 5 years ago

Not an issue but a question. I'm hoping this isn't the wrong place for this...

In the IMDB example used in the youtube arangodb search video: https://www.youtube.com/watch?v=iDznGhelajY&t=2137s

What would a query look like that would show all the connections between to individual people. ie: 6 degrees of Kevin Bacon. So if you picked: Matt Damon and Tim Burton one of the results would be Matt Damon->The Departed->Alec Baldwin->BeatleJuice->Tim Burton

Thanks!

maxkernbach commented 5 years ago

Hi @undeadindustries,

your requested query seems to be a better fit for Graph Traversals than ArangoSearch.

The query below is an example for the mps_graph with start vertex mps_verts/A and end vertex mps_verts/C. mps_edges is the edge collection in use. This query returns only paths with length of 2. In case you want to return paths of different lengths, please specify a different range (e.g. 2..5 for all paths from length 2 to 5.

Query:

  FOR v, e, p IN 2..2 OUTBOUND "mps_verts/A" mps_edges
     FILTER v._id == "mps_verts/C"
       RETURN CONCAT_SEPARATOR(" -> ", p.vertices[*]._key)

Query result:

[
  "A -> B -> C",
  "A -> D -> C"
]

Please find more details in the links below:

https://docs.arangodb.com/3.4/AQL/Graphs/Traversals.html https://docs.arangodb.com/3.4/AQL/Graphs/ShortestPath.html https://docs.arangodb.com/3.4/AQL/Examples/MultiplePaths.html

undeadindustries commented 5 years ago

The reason I asked about arangosearch for this, was because of how you could add a weight criteria to it. Meaning, You could make acting in the movie more relevant than directing in a movie, and it would choose actor->movie->actor traversals over actor->movie->director. Is that possible with a simple traversal? Or would search be better fit for that?

Thanks!

maxkernbach commented 5 years ago

One way to achieve this using Traversals would be adding IS_SAME_COLLECTION FILTER's on the path's vertices. However this way no weight is added but the path pattern is strictly specified.

E.g. the first vertex of the traversal has to be out of the collection "actor", 2nd out of collection "movie", 3rd "actor" etc.

  FOR v, e, p IN 2..4 OUTBOUND "mps_verts/A" mps_edges
     FILTER IS_SAME_COLLECTION('actor', p.vertices[0])
     FILTER IS_SAME_COLLECTION('movie', p.vertices[1])
     FILTER IS_SAME_COLLECTION('actor', p.vertices[2])
     FILTER v._id == "mps_verts/C"
       RETURN CONCAT_SEPARATOR(" -> ", p.vertices[*]._key)
undeadindustries commented 5 years ago

Thanks again. But, in theory, is adding a weight to certain criteria what search would be good for? I don't mean specifically with the IMDB example. I mean ... generally.

dothebart commented 4 years ago

https://github.com/arangodb/arangodb/issues/8016 related.