Open undeadindustries opened 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
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!
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)
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.
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!