Forum Discussion

tripp-bishop's avatar
11 years ago

sorting REST call

Hi guys,
 
I'm trying to find out if/how I can sort the following REST call:

/blogs/id/myblog/topics?page=1&page_size=50&restapi.response_style=view
 
I've tried adding the following query params but with no luck:
 
&sort_by=topicpostdate
&sort_by=date
&sort.field=topicpostdate
&sort.field=date
 
I'm trying to get the oldest blogs in the blog for a report I'm building. I need to be able to sort to get at them. Looks like by default it's sorting in reverse chronological order, so I need the opposite of that. Does this call take a sorting param or am I out of luck?
 
Cheers
  • Hi tripp-bishop ,

     

    I think the below REST call might help you.

     

    /blogs/id/myblog/search/messages?q=is_root:true&sort_by=date

     

    It searches for messages that are topics(root messages) within your blog and sorts them by date. I believe the date is in chronological order. 

    As a side note , If you need it in reverse chronological order , change the sort_by parameter to "sort_by=-date" . 

    PS : I have found sort_by parameter to work , usually with search calls .

     

    Hope that helps.

     

    Thanks,

    Sam

5 Replies

  • NicoB's avatar
    NicoB
    Lithium Alumni (Retired)
    11 years ago

    Hi tripp-bishop 

    did you try with:

    <#assign count = rest("blogs/id/myblog/topics/count")/>
    <#assign last = rest("/blogs/id/myblog/topics?page=${count}&page_size=1&restapi.response_style=view").node_message_context.message />

     This will get you the vary first blog article but obviously if you want to get the first N articles you need to do the appropriate calculations and play with the page_size and page parameters.

    Thanks,

    Nico

  • well, I could do something like that. I the first 500 so I'd need to store a sequence in memory and do a ?reverse on it, which I can certainly do, but before I waste time on a solution like that I wanted to make sure that there wasn't something far simpler like a sort param that would save time and be far more efficient than a Free Marker sort. So is there no way to sort that REST call then?
  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    Hi NicoB 

     

    your answer sounds great, :), just for &restapi.response_style=view, it may not be necessary to be included in the call, as it will be automatically added by rest() and restadmin().

  • Hi tripp-bishop ,

     

    I think the below REST call might help you.

     

    /blogs/id/myblog/search/messages?q=is_root:true&sort_by=date

     

    It searches for messages that are topics(root messages) within your blog and sorts them by date. I believe the date is in chronological order. 

    As a side note , If you need it in reverse chronological order , change the sort_by parameter to "sort_by=-date" . 

    PS : I have found sort_by parameter to work , usually with search calls .

     

    Hope that helps.

     

    Thanks,

    Sam

  • tripp-bishop's avatar
    tripp-bishop
    Mentor
    11 years ago
    samudhraa of course, a lucene query instead. That's the ticket. I got so fixated on the bloody OOB REST call I didn't think of that, but that's exactly the low effort, efficient solution that I was looking for and was certain existed. Thanks!