[Developers] Kevin Bacon game via Freebase

Barak Michener barak at metaweb.com
Mon Apr 27 23:47:54 UTC 2009


Philip Kendall wrote:
> On Mon, Apr 27, 2009 at 06:54:48PM +0300, Alexios Zavras wrote:
>   
>> Philip Kendall wrote [edited]:
>>     
>>> http://kevinbacon.freebaseapps.com/
>>>       
>> Error "Query timeout" for ply 3
>>     
>
> Yeah, it happens. Not much I can do about it really; I can't see any way
> to break the query up... sometimes you can get a result out by reversing
> id1 and id2. Obviously, what works and what doesn't is going to be very
> sensitive to the underlying graph database performance. I'm impressed it
> works as well as it does :-)
>
> Cheers,
>
> Phil
>
>   
So you can actually break the query up like so (for 3-ply):

[{
  "name":  null,
  "id" : null,
  "type":  "/film/actor",
  "limit": 1,
  "a:film": {
    "limit": 1,
    "film": {
      "name": null,
      "starring": {
        "limit": 1,
        "actor": {
          "id": $ID1
        }
      }
    }
  },
  "b:film": {
    "limit": 1,
    "film": {
      "name": null,
      "starring": {
        "limit": 1,
        "actor": {
          "name": null,
          "film": {
            "limit": 1,
            "film": {
              "name": null,
              "starring": {
                "actor": {
                  "id": $ID2
                }
              }
            }
          }
        }
      }
    }
  }
}]

In general, for $PLY >= 2, you build two queries the same way you 
currently do, each of depth $PLY/2, with one taller if the number is 
odd, with the two endpoint ids at the deepest points. You'll always have 
an intermediate actor at the top.  You can then read from the inside-out 
of "a:film" and then run outside-in down "b:film" to form the page.

Query redangling is always fun and interesting. "Flatter" queries tend 
to work better. With this you should be able to fare a bit deeper.

--Barak Michener


More information about the Developers mailing list