org.gcube.opensearch.opensearchoperator
Class Pager

java.lang.Object
  extended by org.gcube.opensearch.opensearchoperator.Pager

public class Pager
extends java.lang.Object

A pager class that will be used to handle search query paging

Author:
gerasimos.farantatos

Constructor Summary
Pager(int numOfResults, int itemsPerPage, java.lang.String resourceName, int clientStartPage, int clientStartIndex, int clientCount)
          Creates a new Pages
 
Method Summary
 int getCurrentPageResultCount()
          Returns the number of results in the current page
 int getCurrPage()
          Returns the current page number
 java.net.URL getPageQuery()
          Returns a query for the current page of search results using a query builder among the ones available
 QueryBuilder getQueryBuilder()
          Returns the query builder used to construct queries
 int getTotalResultCount()
          Returns the number of results obtained so far
 boolean hasNext()
          Determines whether there exist more results available in a next page
 void next(OpenSearchResponse response, int resultsRetrieved)
          Advances the current page by one
 void setContext(java.util.List<QueryBuilder> queryBuilders, java.lang.String MIMEType)
          Provides the pager with a list of query builders to be used and the type of the search results that the provider returns
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pager

public Pager(int numOfResults,
             int itemsPerPage,
             java.lang.String resourceName,
             int clientStartPage,
             int clientStartIndex,
             int clientCount)
Creates a new Pages

Parameters:
numOfResults - The total number of results that should be obtained
itemsPerPage - The items to request per page
resourceName - The name of the OpenSearch provider that is being queried
clientStartPage - The start page requested by the client which invoked the OpenSearchOp, as present in its query
clientStartIndex - The start index requested by the client which invoked the OpenSearchOp, as present in its query
clientCount - The result count requested by the client which invoked the OpenSearchOp, as present in its query
Method Detail

setContext

public void setContext(java.util.List<QueryBuilder> queryBuilders,
                       java.lang.String MIMEType)
Provides the pager with a list of query builders to be used and the type of the search results that the provider returns

Parameters:
queryBuilders - The query builders to use
MIMEType - The MIME type of the search results that the provider returns

getPageQuery

public java.net.URL getPageQuery()
                          throws java.lang.Exception
Returns a query for the current page of search results using a query builder among the ones available

Returns:
The search query in URL form
Throws:
java.lang.Exception - If an error occurred while formulating a query, if the context is not set or in case of other error

next

public void next(OpenSearchResponse response,
                 int resultsRetrieved)
Advances the current page by one

Parameters:
response - The search response for the current page, potentially including OpenSearch response attributes
resultsRetrieved - The number of results retrieved in the current page

hasNext

public boolean hasNext()
Determines whether there exist more results available in a next page

Returns:
true if more results are available for retrieval, false otherwise

getTotalResultCount

public int getTotalResultCount()
Returns the number of results obtained so far

Returns:
The number of results obtained

getCurrentPageResultCount

public int getCurrentPageResultCount()
Returns the number of results in the current page

Returns:
The number of results in the current page

getQueryBuilder

public QueryBuilder getQueryBuilder()
Returns the query builder used to construct queries

Returns:
The query builder

getCurrPage

public int getCurrPage()
Returns the current page number

Returns:
The current page number