Today we have a new MQL feature to announce: sort: count
We already had the ability to return a count of results:
[{
"type" : "/astronomy/planet",
"return" : "count"
}]
(The above will tell you how many planets we have in Freebase’s Astronomy Commons.)
And you can even find counts within a sub-part of the query, like, how many moons each planet has:
[{
"type" : "/astronomy/planet",
"/astronomy/orbital_relationship/orbited_by" : {
"optional" : true,
"return" : "count"
}
}]
But what if you just wanted to know the planets with the most satellites? There’s no way to sort by that count that’s returned… until now!
[{
"type" : "/astronomy/planet",
"/astronomy/orbital_relationship/orbited_by" : {
"return" : "count"
},
"sort" : "-/astronomy/orbital_relationship/orbited_by.count",
"limit" : 3
}]
You can also use estimate-count for counts which are large and might otherwise time out.
