Forum Discussion

sylvain_mouquet's avatar
13 years ago

Search in multiple forums with pagination

Hi,

 

I with to search in multiple forums i use this request :

 /restapi/vc/categories/id/forum1/search/messages/?q=test&page_size=10&page=1

/restapi/vc/categories/id/forum2/search/messages/?q=test&page_size=10&page=1

 

the problem is i need to do the pagination on the result only.

there is a solution for solving it ?

 

In the NodeSearchContext.html file in the javadoc documentation, there is a list of queries arguments :

1) f (optional) : string - Search field.

2) q (optional) : string - Search text. 3) phrase (optional) : string - A phrase. 4) one_or_more (optional) : string- One or more term. What is the difference between each argument ? Cordially, Sylvain

 

6 Replies

  • Salut Sylvain,

    Can you explain a bit more what you are trying to do?

    1) Do you want to combine the result of both searches and then show those combined results using pagination?

    or

    2) Do you want to paginate in both search results seperately?

     

    Generally with the "page_size" parameter of the API call you are specifying how many result items you want to have (per page of the pagination) while the "page" parameter tells the API which page to return.

     

    Example:

    If you want to get the results from result item 30 onwards your could do either of these:

    ...page_size=30&page=2
    
    ...page_size=10&page=4

     

    The second part of your question I don't know the answer for either. Would be interesting to know what difference between the f, q and phrase parameters actually is and how the one_or_more parameter influences the result? @Lithium_devs

  • Hi Claudius,

     

    1) Do you want to combine the result of both searches and then show those combined results using pagination?

    yes, i wish to search in 2 forums and paginate the result.

    by example,

    nbResultByPage = 10

     /restapi/vc/categories/id/forum1/search/messages/?q=test > return 12 results

     /restapi/vc/categories/id/forum2/search/messages/?q=test > return 20 results

     

    i with to get this result

    PAGE 1 : 0-10 of forum1

    PAGE 2 : 11-12 of forum1 + 0-8 of forum2

    PAGE 3 : 9-19 of forum2

    PAGE 4 : 20 of forum2

     

    i have tried to use :

     /restapi/vc/categories/id/forum1/id/forum2/search/messages/?q=test

    but this does not work.

     

    "The second part of your question I don't know the answer for either. Would be interesting to know what difference between the f, q and phrase parameters actually is and how the one_or_more parameter influences the result? @Lithium_devs"

    yes what is the difference between this parameters and what is the influence of one_or_more parameter ?

  • Claudius's avatar
    Claudius
    Boss
    13 years ago

    What sometimes helps in answering API questions is taking a look at the page URL when using the community search page and applying some filters.
    I couldn't find a way both there or VIA API to filter by multiple locations. So probably you need to work around a bit like that (Pseudocode):

    if (number_resultsperpage_from_firstboard => results_per_page) {
    // If the results from the first board already fill a page only show those
    } else {
    //on the page first show the results from the first board and then have another API call to pull results from second board to fill up the page with parameter page_size = results_per_page - number_resultsperpage_from_firstboard
    }

     i know that's very rough because it does not include all of the pagination checking, but I hope you get the general idea.

     


    At least I can reply the second part of the question:
    On the "Search" page of your community click on "Advanced Search" and you will see the three parameters as input fields together with small (i) icons with a more detailed explanation.

  • " i know that's very rough because it does not include all of the pagination checking, but I hope you get the general idea."

     

    lol i have coming to the forum for eviting to develop that... After reflexion, this not solve my problem because there is also the sort (by date by example).

     

    "On the "Search" page of your community click on "Advanced Search" and you will see the three parameters as input fields together with small (i) icons with a more detailed explanation."

    thanks

  • KirillY's avatar
    KirillY
    Lithium Alumni (Retired)
    13 years ago

    Hi Sylvain,

     

    have you checked out an article on TKB here - http://lithosphere.lithium.com/t5/Support-Knowledge-Base/Working-with-Rest-API-search/ta-p/39942 . There are some nice pointers there.

     

    In terms of pulling data from two sources - it really depends on what you're trying to achieve. If you are after sequencial displaying of the results, then the above approach by  might work for you, i.e. call first board and paginate results until they run out, then start the second one.

     

    However, if you're after something a bit more flexible in terms of allowing for sorting by date for example, I think your best bet is to pull all the available search results into a single list and then do the pagination yourself.

     

    In terms of the query parameters - here's some info:

     

    1) f (optional) : string - Search field. - you can specify which specific fields you would like to be searched, e.g. subject, body, teaser, attach, tags - this depends on the type of search you're doing

     

    2) q (optional) : string - Search text. - search query

     

    3) phrase (optional) : string - A phrase.You can search for an exact phrase rather than just keyword

     

    4) one_or_more (optional) : string- One or more term. Not 100% sure, but I think its one or more terms present in the message, an equivalent to logical AND / OR. So for example, ?one_or_more=apple%20orange should return posts which include either apple or orange, or both.

     


    Hope this helps,

     

    p.s. would be curious to hear about your final solution algorithm!

     

    Best regards

    Kirill

  • Hi kyershov,

     

    "However, if you're after something a bit more flexible in terms of allowing for sorting by date for example, I think your best bet is to pull all the available search results into a single list and then do the pagination yourself."

    I think it's not a valid solution.

    Take a look to my table :

     

    5 messages   
    2.5 ko   
        
    nb messageskomogo
    52,50,00250,0000025
    300015001,50,0015
    10000500050,005
    10000050000500,05
        
    nb users   
    3004500004500,45
    300150000015001,5
    300150000001500015

     

    (tell me if i have done a mistake)

    if a search returns 100.000 messages. 300 users will download 15 go of data. (based on 5 messages returns 2.5ko)

     

    I think the only solution is to create an improvement on your API.

     

    "p.s. would be curious to hear about your final solution algorithm!"

    we have chosen to limit the filter to one category...