YUI3 YQL using limit and sort together
I have a YQL query that combines a bunch of RSS feeds and then sorts them by date. It's working great, but I would like to be able to paginate the results.
Here is my query:
select channel.item.title, channel.item.link, channel.item.pubDat开发者_开发问答e, channel.item.description(0) from xml where url in(... urls go here ...) | unique(field='channel.item.link') | sort(field='channel.item.pubDate', descending='true')
The problem is that yql executes LIMIT and OFFSET before the sort filter. So if I have a LIMIT 5 I end up with only the first 5 items from the first RSS feed in the list ... not the first 5 items of all my combined feeds.
Is there a way to chain queries, so I can get all my query that sorts all the results and the call a query that limits my results.
Thanks for the help.
Use the truncate(count=5) to get the first 5 items of the filtered feed.
select channel.item.title, channel.item.link, channel.item.pubDate, channel.item.description(0) from xml where url in(... urls go here ...) | unique(field='channel.item.link') | sort(field='channel.item.pubDate', descending='true') | truncate(count=5)
Or the tail() method with a reversed sort (posted above) would work as well.
See http://developer.yahoo.com/yql/guide/sorting.html
What about using tail()
and additionally sort()
in the other direction?
Something like this:
select channel.item.title, channel.item.link, channel.item.pubDate, channel.item.description(0) from xml where url in(... urls go here ...) | unique(field='channel.item.link') | sort(field='channel.item.pubDate', descending='false') | tail(count=5)
I have not tried this and I am not sure which sort order you need but you can for sure use tail()
. There is no equivalent head()
function apparently, so make sure the newest items are are the end after your sorting.
For further information see http://developer.yahoo.com/yql/guide/sorting.html
精彩评论