Combine queries

I query for ID's belonging to a , after that (extracting IDs with PHP), I query foreach ID what CATEGORY, it is in and whats its name: Now the question is, if it is possible to merge both:

"Query for CATEGORIES (and name of given IDs) of a given "

[1] ID an DOMAIN of ,

{
"domid":{
"query":[{
"name":null,
"name~=":"",
"type":[{
"domain":null,
"id":null,
"name":null,
"type":"/type/type"
}]
}]
}
}

[2] myIdForKeyword) to ask for CATEGORY of it,

{
"category":{
"query":[{
"/type/type/domain":{
"/type/reflect/any_reverse":[{
"name":null,
"type":"/freebase/domain_category"
}],
"name":null
},
"id":"myIdForKeyword",
"name":null
}]
}
}

Here’s how I built it up.

Query for instances of (literally) “keyword” and their types (with a limit, just for testing):

{
"someids" : {
"query" : [
{
"limit" : 5,
"name" : null,
"name~=" : "keyword",
"type" : [
{
"id" : null
}
]
}
]
}
}

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):

{
"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.”

Search Help Center

Discussions

There are no conversations on this topic. Would you like to start one?

Start the Discussion »