[Developers] counts

Kurt Bollacker kurt at metaweb.com
Wed May 30 22:28:15 UTC 2007


On Wed, May 30, 2007 at 04:20:14PM -0400, Steve Sak wrote:
> 
> Is there some way to get a count of the number of objects matching some
> criteria without the actual objects themselves?  E.g., something to get
> the number of tracks recorded by "The Beatles"?

Not directly.  You could use the query:
 
 {
   "qname": {
     "query":[{
       "type" : "/music/album",
       "artist" : "The Beatles",
       "track" : []
     }]
   }
 }

and then simply count the number of items in the "track" array in the
result. This will work for all except very large numbers of items.  For
example, if the result:

{
  "qname":{
    "result":[{
      "artist":"The Beatles",
      "track":["I Saw Her Standing There","Misery","Anna (Go to Him)","Chains","Boys","Ask Me Why","Please Please Me","Love Me Do","P.S. I Love You","Baby It's You","Do You Want to Know a Secret","A Taste of Honey","There's a Place","Twist and Shout"],
      "type":"/music/album"
    },{
      "artist":"The Beatles",
      "track":["From Me to You","Thank You Girl"],
      "type":"/music/album"
    },{
............

was interpreted using a JSON library in python,
len(result['qname']['result'][0]['track']) would give you the number
of tracks in the first album of the result.

								Kurt :-)



More information about the Developers mailing list