Forum Discussion

bdelaune's avatar
bdelaune
Contributor
12 years ago

Rest API search to Discussion Style

Hi. I'm working on a project where the client would like to be able to search the community (this is very easy with the REST API.  From there, within their current application, they would like to view and navigate the thread as if they were on the website (without leaving the current tool).

 

I'm running into a problem when searching and then rendering the appropriate thread.  For example, let's say the user clicks on once of the results in the search.  I want to be able to display the page of the thread that message resides on.  From what I can tell the /restapi/thread/[id]/messages/linear will not allow me to say which message's page I'd like.  Is there a better way to approach this?  Let me know if I'm not making any sense.

5 Replies

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    Hi bdelaune,

     

    I'm not sure I fully understand what you're looking for. Are you just wanting to page through the results of the "/restapi/thread/[id]/messages/linear" call? If so, that call should accept the "page" and "page_size" parameters. So for example if you wanted to get 50 messages at a time:

    /restapi/thread/[id]/messages/linear?page_size=50&page=1

    /restapi/thread/[id]/messages/linear?page_size=50&page=2

    /restapi/thread/[id]/messages/linear?page_size=50&page=3

    ...

     

    If you were looking for something different, could you please try to explain more?

  • bdelaune_hp's avatar
    bdelaune_hp
    Contributor
    11 years ago

    Thanks for your help, but let me clarify what I am asking.

     

    We are utilizing the Community/Search/Messages api to get back a list of search results.  When someone searches on the website and click on a link, it not only takes them to a linear version of the thread, but it also directs them to the correct page of the thread in order to view the message that matched their search results.

     

    We are attempting to replicate this functionality within a tool on an internal system.  Ideally, when a user clicks on one of the search results, they are directed to a page that renders a linear view of the thread and brings them directly to the page they need to be on to view the message that matched their search.  As far as I can tell, there is no programmatic way to determine which number a message is in the linear view of a thread.  That is what we need.

  • nathan's avatar
    nathan
    Executive
    11 years ago

    If you include the parameter restapi.response_style=view in the REST API URL, the results will include the URL for each message returned in the results.

     

    For example, if you search Lithosphere:

    http://lithosphere.lithium.com/restapi/vc/search/messages?q=test&restapi.response_style=view

     

    The first message tag looks like this:

    <message type="message" href="/messages/id/129079" view_href="http://lithosphere.lithium.com/t5/developers-discussion/Test-messages/m-p/129079#M4947">

     

    The view_href URL should take you straight to the message, whichever page it is on.

     

  • bdelaune_hp's avatar
    bdelaune_hp
    Contributor
    11 years ago

    Thanks, Nathan, and we are aware of this functionality, but we need the ability to show the thread within our tool without linking out to the website.  The case we are using it in will not allow the users to actually go to the website (it is blocked on their machines).  We need to replicate the same functionality as that view_href link within our own tool.

     

    Does that make sense?

  • YuriK's avatar
    YuriK
    Khoros Expert
    11 years ago

    Hey Bdelaune,

     

    If I'm not mistaken, you're trying to do is figure out the index of the message in a thread, so that you can figure out what page to pass into the /threads/linear call. Unfortunately, there is nothing out of the box that will do that at the moment. One of the reasons for this is that the index of the message would depend on how you're sorting the messages in a thread. 

     

    One way that you could get this information is to create an endpoint that will take in a message id and a thread id, and will page through the thread's results using AdamN's method and return the index of the message in the thread with your sorting algorithm, you can then use the index of the message to decide what page to retrieve from the /thread/linear call. However, this approach may not be performant enough for your needs, but since you're doing this for one message at a time only when the user clicks on a search result, it may be ok.

     

    I would also suggest that you add a suggestion to the Lithium Ideas board to create an API that returns the index of a message within a thread that is sorted with a specific algorithm.

     

    Hope this helps,

     

    Yuri