Question

I would like to get all related topics of one topic. To make it clearer here is my example:

[{
  "id": "/en/united_states",
  "name": null,
  "/government/governmental_jurisdiction/governing_officials": [{
    "/government/government_position_held/office_holder": [{
      "id": null,
      "name": null
    }]
  }]
}]

The MQL query should give me all office holders which are basically the governing officials. In my example all governings officials for the United States should be returned which are about 3.2k in sum. So the problem is the above query returns only 100 results per default. So I can add the limit parameter to get for example 1000 results:

[{
  "id": "/en/united_states",
  "name": null,
  "/government/governmental_jurisdiction/governing_officials": [{
    "/government/government_position_held/office_holder": [{
      "id": null,
      "name": null
    }],
    "limit": 1000
  }]
}]

But setting the limit to a higher value does not work because the query result is getting too large.

So does anyone have an idea how to solve this problem? I tried to use the cursor to iterate through the results but cursor seem not to work for this nested type of query.

Was it helpful?

Solution

Your query only returns a single object (/en/united_states), which is why a cursor won't help you here. What you need to do is turn the query inside out so that the piece that is currently a subquery (office_holder) is at the outer level so you can iterate through it.

You can invert the query easily in the online query editor by pasting in your original query (click here), placing the cursor on the innermost subquery and clicking invert query which will give you something like this:

[{
  "id": null,
  "name": null,
  "type": "/government/politician",
  "!/government/government_position_held/office_holder": [{
    "!/government/governmental_jurisdiction/governing_officials": [{
      "id": "/en/united_states",
      "name": null
    }]
  }]
}]

which works, but is a little ugly and can be simplified to this:

[{
  "id": null,
  "name": null,
  "type": "/government/politician",
  "government_positions_held": [{
    "jurisdiction_of_office": [{
      "id": "/en/united_states"
    }],
    "basic_title": null
  }]
}]

which is a query that you can iterate through using a cursor.

One thing you should check, though, is the coverage of the jurisdiction property for offices to make sure it's well enough populated to provide you with useful data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top