Search code examples
javasearch-engine

How to develop server side pagination in java?


I have developed a search engine in java. Used java Servlet in server side. The problem is for each query lots of results appears.Each result is represented as a string. How to achieve server side pagination?


Solution

  • The general idea of the pagination is to using skip/limit parameters. You should set skip/limit parameters into the query in client-side and on the server-side by checking this parameters you should return the expected results.

    Explanation of the parameters are :

    skip : skips the number of results and return the others
    limit : return the given number of results.
    

    Ex : Say your query returns a 25 result and you want to paginate it. Then for your first page you should set skip=0, limit=10 on the client-side and on the server-side by checking this parameters you should skip 0 result and return the 10 of them. Then it will return the results between 0-9 for first page.

    For second page, you should send query with skip=10, limit=10 and result will be between 10-19.

    For last page your query will be skip=20, limit=10 and it will return you the results between 20-25.

    This is the general idea how pagination work. To use pagination you should implement it by yourself.