[Developers] Merge two queries

Alec Flett alecf at metaweb.com
Wed Dec 5 17:14:34 UTC 2007


Christopher R. Maden wrote:
>
> But since we are primarily interested in the types, turn the query inside-out (here the limits aren’t for testing, they are because we only need at least one instance at each level, and help the query run faster):
>
>   

And just for argument's sake, here's the query not turned inside out.. 
note that each instance can have multiple types, and each type can be in 
multiple categories.... so this fans out quite a bit. I left limits out 
of this query, but they could be similarly inserted Also note in the 
results that most things are of type /common/topic, which is in the 
"metaweb system types" category.

{
  "someids" : {
    "query" : [
      {
        "id" : null,
        "name" : null,
        "name~=" : "Martin",
        "type" : [
          {
            "domain" : [
              {
                "/freebase/domain_profile/category" : []
              }
            ],
            "id" : null
          }
        ]
      }
    ]
  }
}
> {
>   "someids" : {
>     "query" : [
>       {
>         "id" : null,
>         "instance" : [
>           {
>             "limit" : 1,
>             "name" : null,
>             "name~=" : "keyword"
>           }
>         ],
>         "type" : "/type/type"
>       }
>     ]
>   }
> }
>
> Now let’s find the domains of those types — but while we’re at it, let’s turn that inside-out, too:
>
> {
>   "someids" : {
>     "query" : [
>       {
>         "id" : null,
>         "type" : "/type/domain",
>         "types" : [
>           {
>             "instance" : [
>               {
>                 "limit" : 1,
>                 "name" : null,
>                 "name~=" : "keyword"
>               }
>             ],
>             "limit" : 1
>           }
>         ]
>       }
>     ]
>   }
> }
>
> Now, what categories hold those domains?
>
> {
>   "someids" : {
>     "query" : [
>       {
>         "domains" : [
>           {
>             "limit" : 1,
>             "type" : "/type/domain",
>             "types" : [
>               {
>                 "instance" : [
>                   {
>                     "limit" : 1,
>                     "name" : null,
>                     "name~=" : "keyword"
>                   }
>                 ],
>                 "limit" : 1
>               }
>             ]
>           }
>         ],
>         "id" : null,
>         "name" : null,
>         "type" : "/freebase/domain_category"
>       }
>     ]
>   }
> }
>
> The answer is “System” and “Arts & Entertainment.”
>
> ~Chris
>   



More information about the Developers mailing list