atg.search.formhandlers
Class CollectionFilterFetchingProxy

java.lang.Object
  extended by atg.search.formhandlers.CollectionFilterFetchingProxy
All Implemented Interfaces:
ResultsFetchingProxy

public class CollectionFilterFetchingProxy
extends java.lang.Object
implements ResultsFetchingProxy

A results fetcher that uses a collection filter to filter search results on the client side. Normally one should rely on the search server to filter results, however under certain circumstances it may be desirable or necessary to filter this way in order to consider some criteria in a nearer-to-realtime context, such as inventory status.

Collection filters configured for use in this class will be passed collections (ArrayList objects) of Result objects. Note that these are not repository items. Collection filters written to filter repository items will not work.

This class only works for QueryRequest.Responses from a QueryRequest.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
CollectionFilterFetchingProxy()
           
 
Method Summary
 SearchResponse fetch(BaseSearchFormHandler pFormHandler, SearchRequest pSearchRequest, atg.search.client.SearchSession pSearchSession)
          Fetch results
protected  boolean filterItems(BaseSearchFormHandler pFormHandler, QueryRequest.Response pResults, java.util.List pUnfilteredItems, int pPageSize, boolean pUsingPaging)
          Apply filter to specified unfiltered items.
 java.lang.String getCacheKey()
          Get the cache key
protected  java.lang.String getCacheKey(BaseSearchFormHandler pFormHandler, QueryRequest.Response pResults, java.util.List pUnfilteredItems)
          Return a string that uniquely identifies the unfiltered collection.
 double getFetchFactor()
          When using paging, the page size is is multiplied by this value in order to request more results than are required by the page size, since it is expected that some items will be filtered out.
protected  int getFetchSize(int pPageSize)
          Return the page size adjusted by the fetch factor.
 CachedCollectionFilter getFilter()
           
 boolean getUpdateCache()
          Set the updateCache property
 boolean getUseCache()
          Get the useCache property
 void setCacheKey(java.lang.String pCacheKey)
          Set a key to use as the cache key
 void setFetchFactor(double pFetchFactor)
          When using paging, the page size is is multiplied by this value in order to request more results than are required by the page size, since it is expected that some items will be filtered out.
 void setFilter(CachedCollectionFilter pCachedCollectionFilter)
          Set the cached collection filter
 void setUpdateCache(boolean pUpdateCache)
          Set the updateCache property
 void setUseCache(boolean pUseCache)
          Set useCache property
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

CollectionFilterFetchingProxy

public CollectionFilterFetchingProxy()
Method Detail

setFilter

public void setFilter(CachedCollectionFilter pCachedCollectionFilter)
Set the cached collection filter

Parameters:
pCachedCollectionFilter - the collection filter

getFilter

public CachedCollectionFilter getFilter()
Returns:
the cached collection filter

setCacheKey

public void setCacheKey(java.lang.String pCacheKey)
Set a key to use as the cache key

Parameters:
pCacheKey - the cache key or null

getCacheKey

public java.lang.String getCacheKey()
Get the cache key

Returns:
the cache key

setUseCache

public void setUseCache(boolean pUseCache)
Set useCache property

Parameters:
pUseCache - true to pass useCache to filter, false otherwise

getUseCache

public boolean getUseCache()
Get the useCache property

Returns:
true to pass useCache to filter, false otherwise

setUpdateCache

public void setUpdateCache(boolean pUpdateCache)
Set the updateCache property

Parameters:
pUpadateCache - true to tell filter to update cache, false otherwise

getUpdateCache

public boolean getUpdateCache()
Set the updateCache property

Parameters:
pUpadateCache - true to tell filter to update cache, false otherwise

setFetchFactor

public void setFetchFactor(double pFetchFactor)
When using paging, the page size is is multiplied by this value in order to request more results than are required by the page size, since it is expected that some items will be filtered out. For example, with a real page size of 10 and a fetch factor of 1.2, requests will be issued with a pageSize of 12. This value should be >= 1.0

Parameters:
pFetchFactor - the fetch factor value

getFetchFactor

public double getFetchFactor()
When using paging, the page size is is multiplied by this value in order to request more results than are required by the page size, since it is expected that some items will be filtered out.

Returns:
the fetch factor.

fetch

public SearchResponse fetch(BaseSearchFormHandler pFormHandler,
                            SearchRequest pSearchRequest,
                            atg.search.client.SearchSession pSearchSession)
                     throws atg.search.client.SearchClientException
Fetch results

Specified by:
fetch in interface ResultsFetchingProxy
Parameters:
pFormHandler - the form handler issuing the request
pRequest - the client request
pSearchSession - the search session
Returns:
the search results
Throws:
atg.search.es.exception.SearchException
atg.search.client.SearchClientException

getCacheKey

protected java.lang.String getCacheKey(BaseSearchFormHandler pFormHandler,
                                       QueryRequest.Response pResults,
                                       java.util.List pUnfilteredItems)
Return a string that uniquely identifies the unfiltered collection. This string will be passed as the cache key parameter to the CachedCollectionFilter's filterCollection() method.

This implementation just returns the value of the cacheKey property, which may be null

Parameters:
pFormHandler - the form handler invoking this filter (use pFormHandler.getUserProfile() to get profile)
pResults - the unfiltered search results
pUnfilteredItems - the unfiltered search results

filterItems

protected boolean filterItems(BaseSearchFormHandler pFormHandler,
                              QueryRequest.Response pResults,
                              java.util.List pUnfilteredItems,
                              int pPageSize,
                              boolean pUsingPaging)
Apply filter to specified unfiltered items. Populate specified results object with items that pass filter upto the number of items specified in page size.

Parameters:
pFormHandler - the form hander invoking this proxy
pResults - the results object to populate with filtered items
pUnfilteredItems - the unfiltered search result items
pPageSize - the maximum number of items to show on the page
pUsingPaging - true if using paging
Returns:
true if done filtering items. This may be due to an error (logging through the form handler) or because the reults.resultsList is full (>= pageSize)

getFetchSize

protected int getFetchSize(int pPageSize)
Return the page size adjusted by the fetch factor.

Parameters:
pPageSize - the actual pageSize
Returns:
the number of results to request