Forum Discussion

samudhraa's avatar
samudhraa
Expert
12 years ago

How to filter topics based on highest replies across community ?

I want to create a custom component of Popular Discussion based on the "replies" metric . The topic with highest reply is considered most popular. Is there a REST api or combination of REST calls and filter to implement this?

  • AdamN's avatar
    AdamN
    Khoros Oracle

    When you perform a search, you can sort by the number of replies, so search might be a good fit for this. You can use:

    • q=is_root:true to give you only topic messages, and
    • sort_by=-replies to sort the messages by the number of replies, in descending order

    So your REST API call might look like:

    /restapi/vc/search/messages?q=is_root:true&sort_by=-replies

     For example:

    http://lithosphere.lithium.com/restapi/vc/search/messages?q=is_root:true&sort_by=-replies

     

    I hope this helps!

    • samudhraa's avatar
      samudhraa
      Expert

      Hi AdamN,

       

      Thanks alot , I tried it out and it give me what I was looking for

      However it took me awhile to verify that it works. I was expecting a xml node like <replies> (similar to the one that is present for <views> ) .But since I couldn't find that , I had to check with the board manually.

      I was wondering if there is a list of all the options available for the query parameter like sort_by etc.

       

       

      Thanks

      Sam

       

       

      • AdamN's avatar
        AdamN
        Khoros Oracle

        These are the "official" ones from the JavaDoc:

        f (optional) : string - Search field.
        q (optional) : string - Search text.
        phrase (optional) : string - A phrase.
        one_or_more (optional) : string - One or more term.
        without (optional) : string - Without term.
        sort_by (optional) : string - Sort order.
        collapse_discussion (optional) : boolean -

         If you haven't checked out the CommunitySearchContext and NodeSearchContext classes in the JavaDocs, I'd highly recommend it.

         

        Generally, you can also use the same parameters that work in the search page in the UI. So you may want to test out the search page and see the different parameters that are used when you enable/disable various filters, change the sort options, etc.