org.weborganic.flint.query
Class SearchPaging

java.lang.Object
  extended by org.weborganic.flint.query.SearchPaging

public final class SearchPaging
extends Object

This class allows for a better control of search results by specifying paging information for the index tools to use.

Pages start at 1.

Note: This has nothing to do with memory management.


Field Summary
static int DEFAULT_HITS_PER_PAGE
          The default maximum number of hits per page.
static int DEFAULT_PAGE
          The default maximum number of hits per page.
 
Constructor Summary
SearchPaging()
          Creates a new paging configuration using the default values.
SearchPaging(int page, int hitsPerPage)
          Creates a new paging configuration using the specified values.
 
Method Summary
 int getFirstHit()
          Returns the first hit based on the total number of hits.
 int getHitsPerPage()
          Returns the number of hits per page for the searches.
 int getLastHit(int totalHits)
          Returns the last hit for the current page in the results based on the total number hits.
 int getPage()
          Returns the requested page number.
 int getPageCount(int totalHits)
          Returns the number of pages in the results based on the total number hits.
 void setHitsPerPage(int hitsPerPage)
          Sets the number of hits per page for the searches.
 void setPage(int page)
          Sets the page number.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE

public static final int DEFAULT_PAGE
The default maximum number of hits per page.

See Also:
Constant Field Values

DEFAULT_HITS_PER_PAGE

public static final int DEFAULT_HITS_PER_PAGE
The default maximum number of hits per page.

See Also:
Constant Field Values
Constructor Detail

SearchPaging

public SearchPaging()
Creates a new paging configuration using the default values.


SearchPaging

public SearchPaging(int page,
                    int hitsPerPage)
Creates a new paging configuration using the specified values.

Parameters:
page - The page requested.
hitsPerPage - The maximum number of results per page.
Method Detail

getHitsPerPage

public int getHitsPerPage()
Returns the number of hits per page for the searches.

Returns:
The number of hits per page for the searches.

setHitsPerPage

public void setHitsPerPage(int hitsPerPage)
Sets the number of hits per page for the searches.

A negative value in indicates no limit.

Parameters:
hitsPerPage - The number of hits per page for the searches.

getPage

public int getPage()
Returns the requested page number.

Returns:
The requested page number.

setPage

public void setPage(int page)
Sets the page number.

Parameters:
page - The page number.
Throws:
IllegalArgumentException - if the page is less than 1.

getFirstHit

public int getFirstHit()
Returns the first hit based on the total number of hits.

If hits per page is positive, it is the result of :

   HITS_PER_PAGE x (PAGE - 1) + 1
 

Otherwise, this method always returns 1;

Returns:
the first hit based on the total number of hits (inclusive)

getLastHit

public int getLastHit(int totalHits)
Returns the last hit for the current page in the results based on the total number hits.

If hits per page is positive, it is the result of :

   MIN( HITS_PER_PAGE x PAGE - 1, TOTAL_HITS)
 

Otherwise, this method always returns 1;

Parameters:
totalHits - The total number of hits.
Returns:
the last hit based on the total number of hits (inclusive).

getPageCount

public int getPageCount(int totalHits)
Returns the number of pages in the results based on the total number hits.

If hits per page is positive, it is the result of :

   ((TOTAL_HITS - 1) / HITS_PER_PAGE) + 1
 

Otherwise, this method always returns 1;

Parameters:
totalHits - The total number of hits.
Returns:
the last hit based on the total number of hits (inclusive).