Complex Queries
Discussion
Simple usage of the API focuses around getting large sets of data about sites quickly. It's fairly obvious how to grab all of a user's answers, even all of a large set of users' via vectorized requests, all recent comments, and so on. What's less obvious is how to cull our datasets to smaller chunks of data.
The API provides the sort
, min
, max
, fromdate
, and todate
parameters
on many methods to allow for more complicated queries. min
and max
specify the range of a field must fall in (that field being
specified by sort
) to be returned, while fromdate
and todate
always define the range of creation_date
.
Think these parameters as defining two "windows" in which data must fit to be returned.
min
, max
, fromdate
, and todate
are inclusive.
Examples
- All Stack Overflow Users Created on Feb. 27th of 2011
- Comments with at least a score of 10 on Ask Ubuntu
- Of these three posts on Server Fault, the one with the most recent activity
- Any bookmarks added in the month of December 2011 by Darin Dimitrov
- Questions created during the Modern Warfare 3 VS Skyrim Contest with the
skryim
tag and a score greater than 10 on Gaming Stack Exchange
Another handy trick is to only request the total
field when all you care about is the quantity of items meeting some criteria, such as when calculating
statistics. The ?filter=total
built-in filter is provided for just this purpose.